erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.8k stars 743 forks source link

No `open` price for SPX #572

Closed 4everlove closed 1 year ago

4everlove commented 1 year ago

Hi,

I'm trying to get the open price for SPX, but get nan instead. Here is a snippet

from ib_insync import *

ib = IB()
ib.connect('127.0.0.1', 4001)
spx = Index('SPX', 'CBOE')
ticker = ib.reqMktData(spx, '')
ib.sleep()
print(f'open: {ticker.open}, close: {ticker.close}, last: {ticker.last}')

open: nan, close: 4105.02, last: 4100.21

I can also get high and low in the above example. I have the CBOE streaming index data subscription so the feed shouldn't be an issue. Is it something specific to how IBKR handles index products or a bug with ib_insync?

Thanks!

erdewit commented 1 year ago

Probably you'll need to sleep longer, like ib.sleep(4), for the data to come in.

4everlove commented 1 year ago

Thanks, Ewald. Sorry for the late response. Even if i do ib.sleep(100) it doesn't come alive for open. Has it worked for you?