I'm using the following code to try and pull the current price of SPX during regular trading hours, but it is giving me yesterday's close price. This is utilizing the TWS API.
I have market data subscriptions for:
CBOE One add-on bundle (NP, L1)
US Equity and Options add-on streaming bundle
US Securities Snapshot and Futures Value Bundle (NP, L1)
### SPX Variables ###
und_symbol = 'SPX'
und_exchange = 'CBOE'
### Establishing the specific contract to get options ###
idx_con = Index(und_symbol, und_exchange)
ib.qualifyContracts(idx_con)
### Select market data type: 1 = Live 2 = Frozen 3 = Delayed 4 = Delayed frozen
ib.reqMarketDataType(1)
### Then get the ticker. Requesting a ticker can take up to 11 seconds.
[ticker] = ib.reqTickers(idx_con)
### Take the current market value of the ticker:
current_price = ticker.marketPrice()
print(current_price)
I'm using the following code to try and pull the current price of SPX during regular trading hours, but it is giving me yesterday's close price. This is utilizing the TWS API.
I have market data subscriptions for:
CBOE One add-on bundle (NP, L1)
US Equity and Options add-on streaming bundle
US Securities Snapshot and Futures Value Bundle (NP, L1)
### SPX Variables ###
und_symbol = 'SPX'
und_exchange = 'CBOE'
### Establishing the specific contract to get options ###
idx_con = Index(und_symbol, und_exchange)
ib.qualifyContracts(idx_con)
### Select market data type: 1 = Live 2 = Frozen 3 = Delayed 4 = Delayed frozen
ib.reqMarketDataType(1)
### Then get the ticker. Requesting a ticker can take up to 11 seconds.
[ticker] = ib.reqTickers(idx_con)
### Take the current market value of the ticker:
current_price = ticker.marketPrice()
print(current_price)
Problem solved. Switched to IB Gateway API instead of using the TWS API.