Errors while fetching Futures historical data in IBKR
Hi,
I've tried to fetch historical data from a NQ future contract in IBKR and I couldn't. First thing,
Example contract:
val asset = futureContract( symbol = "NQ", month = Month.DECEMBER, year = 2024, multiplier = 20.0, exchangeCode = "CME", )
When function "tofutureContract" builds an Asset creates a futureSymbol as NQZ24 when it should be NQZ4, this quick change fixes it:
old: val futureSymbol = "$symbol$monthEncoding${yearCode.takeLast(2)}"
new: val futureSymbol = "$symbol$monthEncoding${yearCode.last()}"
Second thing, when I want to retrieve the data like so:
val yesterday = now.minusDays(4)
feed.retrieve(asset, duration = "1 D", endDate = yesterday.toInstant(), barSize = "5 mins")
feed.retrieve(asset)
feed.waitTillRetrieved()
I get an error:
java.time.format.DateTimeParseException: Text '20241119 08:30:00 US/Central' could not be parsed at index 9
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2108)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:2010)
at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:494)
at org.roboquant.ibkr.IBKRHistoricFeed$Wrapper.historicalData(IBKRHistoricFeed.kt:134)
at com.ib.client.EDecoder.processHistoricalDataMsg(Unknown Source)
at com.ib.client.EDecoder.processMsg(Unknown Source)
at com.ib.client.EReader.processMsgs(Unknown Source)
at org.roboquant.ibkr.IBKR.connect$lambda$1(IBKR.kt:95)
Could it be this date formatter? seems that has two white spaces betwen date and time but the time string been parsed has only one white space.
private val dtf = DateTimeFormatter.ofPattern("yyyyMMdd HH:mm:ss")
Btw, great project.
Hmm, this always had two spaces (at least for stocks). Which version of the IB API are you using?
10.32.01
I'm interested in contributing to this project! The issue description is clear and I have some ideas for implementation. Would love to discuss the approach.
I'm interested in contributing to this project! The issue description is clear and I have some ideas for implementation. Would love to discuss the approach.
Feel free to provide some input or a PR.