1212import stomp
1313from stomp .exception import ConnectFailedException
1414
15+ from tigeropen import __VERSION__
1516from tigeropen .common .consts import OrderStatus
17+ from tigeropen .common .consts .params import P_SDK_VERSION , P_SDK_VERSION_PREFIX
1618from tigeropen .common .consts .push_destinations import QUOTE , QUOTE_DEPTH , QUOTE_FUTURE , QUOTE_OPTION , TRADE_ASSET , \
1719 TRADE_ORDER , TRADE_POSITION
1820from tigeropen .common .consts .push_types import RequestType , ResponseType
@@ -107,7 +109,7 @@ def _connect(self):
107109 self ._stomp_connection .set_listener ('push' , self )
108110 self ._stomp_connection .start ()
109111 try :
110- self ._stomp_connection .connect (self ._tiger_id , self ._sign , wait = True )
112+ self ._stomp_connection .connect (self ._tiger_id , self ._sign , wait = True , headers = self . _generate_headers () )
111113 except ConnectFailedException as e :
112114 raise e
113115
@@ -241,6 +243,8 @@ def on_message(self, headers, body):
241243 def on_error (self , headers , body ):
242244 if self .error_callback :
243245 self .error_callback (body )
246+ else :
247+ logging .error (body )
244248
245249 def _update_subscribe_id (self , destination ):
246250 self ._destination_counter_map [destination ] += 1
@@ -341,7 +345,7 @@ def query_subscribed_quote(self):
341345 查询已订阅行情的合约
342346 :return:
343347 """
344- headers = dict ()
348+ headers = self . _generate_headers ()
345349 headers ['destination' ] = QUOTE
346350 headers ['req-type' ] = RequestType .REQ_SUB_SYMBOLS .value
347351 self ._stomp_connection .send (QUOTE , "{}" , headers = headers )
@@ -358,7 +362,7 @@ def unsubscribe_depth_quote(self, symbols=None, id=None):
358362 退订深度行情更新
359363 :return:
360364 """
361- self ._handle_quote_unsubscribe (destination = QUOTE_DEPTH , subscription = 'AskBid ' , sub_id = id , symbols = symbols )
365+ self ._handle_quote_unsubscribe (destination = QUOTE_DEPTH , subscription = 'QuoteDepth ' , sub_id = id , symbols = symbols )
362366
363367 def _handle_trade_subscribe (self , destination , subscription , account = None , extra_headers = None ):
364368 if extra_headers is None :
@@ -385,25 +389,28 @@ def _handle_quote_unsubscribe(self, destination, subscription, sub_id=None, symb
385389 extra_headers = extra_headers )
386390
387391 def _handle_subscribe (self , destination , subscription , extra_headers = None ):
388- headers = dict ( )
392+ headers = self . _generate_headers ( extra_headers )
389393 headers ['destination' ] = destination
390394 headers ['subscription' ] = subscription
391395 self ._update_subscribe_id (destination )
392396 sub_id = self ._get_subscribe_id (destination )
393397 headers ['id' ] = sub_id
394398
395- if extra_headers is not None :
396- headers .update (extra_headers )
397399 self ._stomp_connection .subscribe (destination , id = sub_id , headers = headers )
398400 return sub_id
399401
400402 def _handle_unsubscribe (self , destination , subscription , sub_id = None , extra_headers = None ):
401- headers = dict ( )
403+ headers = self . _generate_headers ( extra_headers )
402404 headers ['destination' ] = destination
403405 headers ['subscription' ] = subscription
404406 id_ = sub_id if sub_id is not None else self ._get_subscribe_id (destination )
405407 headers ['id' ] = id_
406- if extra_headers :
407- headers .update (extra_headers )
408408
409409 self ._stomp_connection .unsubscribe (id = id_ , headers = headers )
410+
411+ def _generate_headers (self , extra_headers = None ):
412+ headers = {P_SDK_VERSION : P_SDK_VERSION_PREFIX + __VERSION__ }
413+ if extra_headers is not None :
414+ headers .update (extra_headers )
415+ return headers
416+
0 commit comments