roboquant icon indicating copy to clipboard operation
roboquant copied to clipboard

Errors while fetching Futures historical data in IBKR

Open apellicerep opened this issue 1 year ago • 5 comments

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.

apellicerep avatar Nov 25 '24 10:11 apellicerep

Hmm, this always had two spaces (at least for stocks). Which version of the IB API are you using?

jbaron avatar Dec 26 '24 16:12 jbaron

10.32.01

apellicerep avatar Jan 05 '25 21:01 apellicerep

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.

shubhamos-ai avatar Aug 29 '25 09:08 shubhamos-ai

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.

shubhamos-ai avatar Aug 29 '25 09:08 shubhamos-ai

Feel free to provide some input or a PR.

jbaron avatar Oct 03 '25 12:10 jbaron