1717from tigeropen .common .consts import OrderStatus
1818from tigeropen .common .consts .params import P_SDK_VERSION , P_SDK_VERSION_PREFIX
1919from tigeropen .common .consts .push_destinations import QUOTE , QUOTE_DEPTH , QUOTE_FUTURE , QUOTE_OPTION , TRADE_ASSET , \
20- TRADE_ORDER , TRADE_POSITION , QUOTE_TICK
20+ TRADE_ORDER , TRADE_POSITION , TRADE_TICK
2121from tigeropen .common .consts .push_subscriptions import SUBSCRIPTION_QUOTE , SUBSCRIPTION_QUOTE_DEPTH , \
2222 SUBSCRIPTION_QUOTE_OPTION , SUBSCRIPTION_QUOTE_FUTURE , SUBSCRIPTION_TRADE_ASSET , SUBSCRIPTION_TRADE_POSITION , \
23- SUBSCRIPTION_TRADE_ORDER , SUBSCRIPTION_QUOTE_TICK
23+ SUBSCRIPTION_TRADE_ORDER , SUBSCRIPTION_TRADE_TICK
2424from tigeropen .common .consts .push_types import RequestType , ResponseType
2525from tigeropen .common .consts .quote_keys import QuoteChangeKey , QuoteKeyType
2626from tigeropen .common .exceptions import ApiException
@@ -90,6 +90,7 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=120, heartbeats=
9090 self ._destination_counter_map = defaultdict (lambda : 0 )
9191
9292 self .subscribed_symbols = None
93+ self .query_subscribed_callback = None
9394 self .quote_changed = None
9495 self .tick_changed = None
9596 self .asset_changed = None
@@ -102,6 +103,7 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=120, heartbeats=
102103 self .error_callback = None
103104 self ._connection_timeout = connection_timeout
104105 self ._heartbeats = heartbeats
106+ self .logger = logging .getLogger ('tiger_openapi' )
105107 _patch_ssl ()
106108
107109 def _connect (self ):
@@ -156,17 +158,29 @@ def on_message(self, frame):
156158 try :
157159 response_type = headers .get ('ret-type' )
158160 if response_type == str (ResponseType .GET_SUB_SYMBOLS_END .value ):
159- if self .subscribed_symbols :
161+ if self .subscribed_symbols or self . query_subscribed_callback :
160162 data = json .loads (body )
161- limit = data .get ('limit' )
162- symbols = data .get ('subscribedSymbols' )
163- used = data .get ('used' )
164- symbol_focus_keys = data .get ('symbolFocusKeys' )
163+ formatted_data = camel_to_underline_obj (data )
164+
165+ limit = formatted_data .get ('limit' )
166+ subscribed_symbols = formatted_data .get ('subscribed_symbols' )
167+ used = formatted_data .get ('used' )
168+ symbol_focus_keys = formatted_data .get ('symbol_focus_keys' )
165169 focus_keys = dict ()
166170 for sym , keys in symbol_focus_keys .items ():
167171 keys = set (QUOTE_KEYS_MAPPINGS .get (key , camel_to_underline (key )) for key in keys )
168172 focus_keys [sym ] = list (keys )
169- self .subscribed_symbols (symbols , focus_keys , limit , used )
173+ formatted_data ['symbol_focus_keys' ] = focus_keys
174+ formatted_data ['subscribed_quote_depth_symbols' ] = formatted_data .pop ('subscribed_ask_bid_symbols' )
175+ formatted_data ['quote_depth_limit' ] = formatted_data .pop ('ask_bid_limit' )
176+ formatted_data ['quote_depth_used' ] = formatted_data .pop ('ask_bid_used' )
177+ if self .subscribed_symbols :
178+ self .logger .warning ('PushClient.subscribed_symbols is deprecated, '
179+ 'use PushClient.query_subscribed_callback instead.' )
180+ self .subscribed_symbols (subscribed_symbols , focus_keys , limit , used )
181+ if self .query_subscribed_callback :
182+ self .query_subscribed_callback (formatted_data )
183+
170184 elif response_type == str (ResponseType .GET_QUOTE_CHANGE_END .value ):
171185 if self .quote_changed :
172186 data = json .loads (body )
@@ -266,19 +280,19 @@ def on_message(self, frame):
266280 if self .error_callback :
267281 self .error_callback (body )
268282 except Exception as e :
269- logging .error (e , exc_info = True )
283+ self . logger .error (e , exc_info = True )
270284
271285 def on_error (self , frame ):
272286 body = json .loads (frame .body )
273287 if body .get ('code' ) == 4001 :
274- logging .error (body )
288+ self . logger .error (body )
275289 self .disconnect_callback = None
276290 raise ApiException (4001 , body .get ('message' ))
277291
278292 if self .error_callback :
279293 self .error_callback (frame )
280294 else :
281- logging .error (frame .body )
295+ self . logger .error (frame .body )
282296
283297 def _update_subscribe_id (self , destination ):
284298 self ._destination_counter_map [destination ] += 1
@@ -356,7 +370,7 @@ def subscribe_tick(self, symbols):
356370 :param symbols: symbol列表
357371 :return:
358372 """
359- return self ._handle_quote_subscribe (destination = QUOTE_TICK , subscription = SUBSCRIPTION_QUOTE_TICK ,
373+ return self ._handle_quote_subscribe (destination = TRADE_TICK , subscription = SUBSCRIPTION_TRADE_TICK ,
360374 symbols = symbols )
361375
362376 def subscribe_depth_quote (self , symbols ):
@@ -405,7 +419,7 @@ def unsubscribe_tick(self, symbols=None, id=None):
405419 退订行情更新
406420 :return:
407421 """
408- self ._handle_quote_unsubscribe (destination = QUOTE_TICK , subscription = SUBSCRIPTION_QUOTE_TICK , sub_id = id ,
422+ self ._handle_quote_unsubscribe (destination = TRADE_TICK , subscription = SUBSCRIPTION_TRADE_TICK , sub_id = id ,
409423 symbols = symbols )
410424
411425 def unsubscribe_depth_quote (self , symbols = None , id = None ):
0 commit comments