@@ -27,6 +27,7 @@ def __init__(self, username, password, server="openfeed.aws.barchart.com", debug
2727
2828 self .instrument_definitions = {}
2929 self .instruments_by_symbol = {}
30+ self .subscription_symbol_by_marketid = {}
3031 self .snapshots = {}
3132
3233 self .symbol_handlers = {}
@@ -275,6 +276,7 @@ def handleSubscriptionResponse(msg):
275276 raise Exception ("Subscription has failed: " , msg )
276277
277278 if len (msg .subscriptionResponse .symbol ) > 0 :
279+ self .subscription_symbol_by_marketid [msg .subscriptionResponse .marketId ] = msg .subscriptionResponse .symbol
278280 self .__notify_symbol_listeners (
279281 self .__create_instrument (msg .subscriptionResponse .symbol ), msg )
280282 else :
@@ -382,21 +384,26 @@ def on_open(ws):
382384
383385 def __notify_symbol_listeners (self , instrument , msg ):
384386
385- # TODO review symbology handling, subbing by one and keying off the other can create unexpected results
386- # for example subscribing to "ZCYAIA40.CM" will come back with OF symbol (less the suffix) in `instrument.symbol`
387- # given the below, if the instrument contains duplicate `instrument.symbols`, the listeners will get duplicate callbacks
387+ symbol_key = ""
388+
389+ if instrument .marketId in self .subscription_symbol_by_marketid :
390+ symbol_key = self .subscription_symbol_by_marketid [instrument .marketId ]
388391
389392 for s in instrument .symbols :
390393 if s .symbol not in self .symbol_handlers or s .vendor != "Barchart" :
391394 continue
395+ symbol_key = s .symbol
392396
393- for cb in self .symbol_handlers [s .symbol ]:
397+ if symbol_key != "" :
398+ for cb in self .symbol_handlers [symbol_key ]:
394399 try :
395400 cb .callback (msg )
396401 except Exception as e :
397402 if self .debug :
398- print ("Failed to notify `symbol` callback:" , s , e )
403+ print ("Failed to notify `symbol` callback:" , symbol_key , e )
399404 self .__callback (self .on_error , e )
405+ else :
406+ print ("got a message but have no handlers" , instrument , msg )
400407
401408 def __notify_exchange_listeners (self , exchange , msg ):
402409 if exchange not in self .exchange_handlers :
0 commit comments