@@ -112,25 +112,35 @@ def on_error(self, frame):
112112 self .logger .error (frame )
113113
114114 def on_message (self , frame ):
115- if frame .code == ResponseType .GET_SUB_SYMBOLS_END .value :
116- if self .query_subscribed_callback :
117- self .query_subscribed_callback (frame .msg )
118- elif frame .code == ResponseType .GET_SUBSCRIBE_END .value :
119- if self .subscribe_callback :
120- self .subscribe_callback (frame )
121- elif frame .code == ResponseType .GET_CANCEL_SUBSCRIBE_END .value :
122- if self .unsubscribe_callback :
123- self .unsubscribe_callback (frame )
124- elif frame .code == ResponseType .ERROR_END .value :
125- if self .error_callback :
126- self .error_callback (frame )
127- else :
128- if frame .body .dataType == SocketCommon .DataType .Quote :
129- if frame .body .quoteData .type == SocketCommon .QuoteType .BASIC and self .quote_changed :
130- self .quote_changed (frame .body .quoteData )
131- if frame .body .quoteData .type == SocketCommon .QuoteType .BBO and self .quote_bbo_changed :
132- self .quote_bbo_changed (frame .body .quoteData )
133- if frame .body .quoteData .type == SocketCommon .QuoteType .ALL :
115+ try :
116+ if frame .code == ResponseType .GET_SUB_SYMBOLS_END .value :
117+ if self .query_subscribed_callback :
118+ self .query_subscribed_callback (frame .msg )
119+ elif frame .code == ResponseType .GET_SUBSCRIBE_END .value :
120+ if self .subscribe_callback :
121+ self .subscribe_callback (frame )
122+ elif frame .code == ResponseType .GET_CANCEL_SUBSCRIBE_END .value :
123+ if self .unsubscribe_callback :
124+ self .unsubscribe_callback (frame )
125+ elif frame .code == ResponseType .ERROR_END .value :
126+ if self .error_callback :
127+ self .error_callback (frame )
128+ else :
129+ if frame .body .dataType == SocketCommon .DataType .Quote :
130+ if frame .body .quoteData .type == SocketCommon .QuoteType .BASIC and self .quote_changed :
131+ self .quote_changed (frame .body .quoteData )
132+ if frame .body .quoteData .type == SocketCommon .QuoteType .BBO and self .quote_bbo_changed :
133+ self .quote_bbo_changed (frame .body .quoteData )
134+ if frame .body .quoteData .type == SocketCommon .QuoteType .ALL :
135+ if self .quote_changed :
136+ basic_data = convert_to_basic_data (frame .body .quoteData )
137+ if basic_data :
138+ self .quote_changed (basic_data )
139+ if self .quote_bbo_changed :
140+ bbo_data = convert_to_bbo_data (frame .body .quoteData )
141+ if bbo_data :
142+ self .quote_bbo_changed (bbo_data )
143+ elif frame .body .dataType in {SocketCommon .DataType .Future , SocketCommon .DataType .Option }:
134144 if self .quote_changed :
135145 basic_data = convert_to_basic_data (frame .body .quoteData )
136146 if basic_data :
@@ -139,43 +149,36 @@ def on_message(self, frame):
139149 bbo_data = convert_to_bbo_data (frame .body .quoteData )
140150 if bbo_data :
141151 self .quote_bbo_changed (bbo_data )
142- elif frame .body .dataType in {SocketCommon .DataType .Future , SocketCommon .DataType .Option }:
143- if self .quote_changed :
144- basic_data = convert_to_basic_data (frame .body .quoteData )
145- if basic_data :
146- self .quote_changed (basic_data )
147- if self .quote_bbo_changed :
148- bbo_data = convert_to_bbo_data (frame .body .quoteData )
149- if bbo_data :
150- self .quote_bbo_changed (bbo_data )
151- elif frame .body .dataType == SocketCommon .DataType .QuoteDepth :
152- if self .quote_depth_changed :
153- self .quote_depth_changed (frame .body .quoteDepthData )
154- elif frame .body .dataType == SocketCommon .DataType .TradeTick :
155- if self .tick_changed :
156- self .tick_changed (self ._convert_tick (frame .body .tradeTickData ))
157- elif frame .body .dataType == SocketCommon .DataType .OrderStatus :
158- if self .order_changed :
159- frame .body .orderStatusData .status = get_order_status (frame .body .orderStatusData .status ,
160- frame .body .orderStatusData .filledQuantity ).name
161- self .order_changed (frame .body .orderStatusData )
162- elif frame .body .dataType == SocketCommon .DataType .OrderTransaction :
163- if self .transaction_changed :
164- self .transaction_changed (frame .body .orderTransactionData )
165- elif frame .body .dataType == SocketCommon .DataType .Asset :
166- if self .asset_changed :
167- self .asset_changed (frame .body .assetData )
168- elif frame .body .dataType == SocketCommon .DataType .Position :
169- if self .position_changed :
170- self .position_changed (frame .body .positionData )
171- elif frame .body .dataType == SocketCommon .DataType .StockTop :
172- if self .stock_top_changed :
173- self .stock_top_changed (frame .body .stockTopData )
174- elif frame .body .dataType == SocketCommon .DataType .OptionTop :
175- if self .option_top_changed :
176- self .option_top_changed (frame .body .optionTopData )
177- else :
178- self .logger .warning (f'unhandled frame: { frame } ' )
152+ elif frame .body .dataType == SocketCommon .DataType .QuoteDepth :
153+ if self .quote_depth_changed :
154+ self .quote_depth_changed (frame .body .quoteDepthData )
155+ elif frame .body .dataType == SocketCommon .DataType .TradeTick :
156+ if self .tick_changed :
157+ self .tick_changed (self ._convert_tick (frame .body .tradeTickData ))
158+ elif frame .body .dataType == SocketCommon .DataType .OrderStatus :
159+ if self .order_changed :
160+ frame .body .orderStatusData .status = get_order_status (frame .body .orderStatusData .status ,
161+ frame .body .orderStatusData .filledQuantity ).name
162+ self .order_changed (frame .body .orderStatusData )
163+ elif frame .body .dataType == SocketCommon .DataType .OrderTransaction :
164+ if self .transaction_changed :
165+ self .transaction_changed (frame .body .orderTransactionData )
166+ elif frame .body .dataType == SocketCommon .DataType .Asset :
167+ if self .asset_changed :
168+ self .asset_changed (frame .body .assetData )
169+ elif frame .body .dataType == SocketCommon .DataType .Position :
170+ if self .position_changed :
171+ self .position_changed (frame .body .positionData )
172+ elif frame .body .dataType == SocketCommon .DataType .StockTop :
173+ if self .stock_top_changed :
174+ self .stock_top_changed (frame .body .stockTopData )
175+ elif frame .body .dataType == SocketCommon .DataType .OptionTop :
176+ if self .option_top_changed :
177+ self .option_top_changed (frame .body .optionTopData )
178+ else :
179+ self .logger .warning (f'unhandled frame: { frame } ' )
180+ except Exception :
181+ self .logger .error (f'error in on_message ' , exc_info = True )
179182
180183 def subscribe_asset (self , account = None ):
181184 """
0 commit comments