erdewit / ib_insync

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

contract in tickers when using reqTickByTickData doesn't have conId #681

Closed drhboss closed 5 months ago

drhboss commented 5 months ago

when requesting tickbytick data, the tickers returned doen't have the conId in the contract field, only symbols are available, and it makes it hard to handle the streaming tickers when there is mutiple requests for tickbytick data of multiple symbols.

from ib_insync import *

ib = IB()
ib.connect('127.0.0.1', 6002, clientId=2)

contract = Future('ES', '202403', 'CME')                                                                                                          
tickers_BidAsk  = ib.reqTickByTickData(contract, 'BidAsk', numberOfTicks=0, ignoreSize=False)                                                       
tickers_Last = ib.reqTickByTickData(contract, 'Last', numberOfTicks=0, ignoreSize=False)                                                         

def onPendingTickers(tickers):                                                                                                                       
    for ticker in tickers:                                                                                                                                 
        print(ticker)                                                                                                                                      

ib.pendingTickersEvent   += onPendingTickers 

ib.run()
erdewit commented 5 months ago

If the contracts are qualified beforehand (with ib.qualifyContracts) then the conId will actually be filled.