Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors while fetching Futures historical data in IBKR #87

Open
apellicerep opened this issue Nov 25, 2024 · 1 comment
Open

Errors while fetching Futures historical data in IBKR #87

apellicerep opened this issue Nov 25, 2024 · 1 comment

Comments

@apellicerep
Copy link

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.

@jbaron
Copy link
Collaborator

jbaron commented Dec 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants