开云体育

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Starting and stopping market data using ticker object


 

Hi all,
First thanks for resurrecting the forum following Ewald's sad passing. He was very kind and helpful to me when i was getting my head around Insync.
?
My problem now though is that I need to both start streaming a ticker, and also to stop it later.
?
I can start it no problem:
?
? ? stock_symbols = ['SPY', 'AAPL'],
? ? stocks = [Stock(symbol, 'SMART', 'USD') for symbol in stock_symbols]
? ? for stock in stocks:
? ? ? ? ib.qualifyContracts(*stocks)
? ? ? ? ticker = ib.reqMktData(stock, '', False, False)
?
..but have been unable to selectively cancel a ticker, ie cancel AAPL and keep SPY streaming. This seems to be because there is no reqID fround to identify the tickers.
?
Any help would be much appreciated.
Thanks
Dan


 

Dan, I use this. I don't know 100% if it works as I didn't bother to test since it was not mission critical for my use case:

def req_market_data_initial_contracts(previous_options_contracts=None):
? ? active_tickers_temp = {}
? ? for each_contract in previous_options_contracts:
? ? ? ? active_tickers_temp[each_contract.localSymbol] = ib.reqMktData(each_contract, "", False, False)
? ? ib.sleep(10)

And then when I need to cancel any of these:

? ? ? for contract_item in previous_options_contrs:
? ? ? ? ? ? if contract_item not in current_options_contracts:
? ? ? ? ? ? ? ? ib.cancelMktData(contract_item)
? ? ? ? ? ? ? ? ib.cancelRealTimeBars(opt_5_sec_bars_dict.get(contract_item.localSymbol))
? ? ? ? ? ? ? ? print_log(msg=f"Cancelled bars for {contract_item.localSymbol} during re-alignment of spx")
? ? ? ? ? ? ? ? active_tickers.pop(contract_item.localSymbol, None)
? ? ? ? ? ? ? ? opt_5_sec_bars_dict.pop(contract_item.localSymbol, None)


On Wed, Aug 21, 2024 at 12:30?PM Daniel Stewart via <danieljstewart=hotmail.com@groups.io> wrote:
Hi all,
First thanks for resurrecting the forum following Ewald's sad passing. He was very kind and helpful to me when i was getting my head around Insync.
?
My problem now though is that I need to both start streaming a ticker, and also to stop it later.
?
I can start it no problem:
?
? ? stock_symbols = ['SPY', 'AAPL'],
? ? stocks = [Stock(symbol, 'SMART', 'USD') for symbol in stock_symbols]
? ? for stock in stocks:
? ? ? ? ib.qualifyContracts(*stocks)
? ? ? ? ticker = ib.reqMktData(stock, '', False, False)
?
..but have been unable to selectively cancel a ticker, ie cancel AAPL and keep SPY streaming. This seems to be because there is no reqID fround to identify the tickers.
?
Any help would be much appreciated.
Thanks
Dan


 

Thanks!