python - Cannot get SPX live data to pull from IBKR API - Stack Overflow

admin2025-05-01  2

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)
Share Improve this question asked Jan 2 at 22:09 PythonNewbPythonNewb 231 gold badge1 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Problem solved. Switched to IB Gateway API instead of using the TWS API.

转载请注明原文地址:http://anycun.com/QandA/1746094634a91589.html