@@ -120,25 +120,30 @@ def unsubscribe_callback(destination, content):
120120 print ('subscribe:{}, callback content:{}' .format (destination , content ))
121121
122122
123- # def connect_callback():
124- # """连接建立回调"""
125- # print('connected')
126- #
127- #
128- # def disconnect_callback():
129- # """连接断开回调. 此处利用回调进行重连"""
130- # for t in range(1, 200):
131- # try:
132- # print('disconnected, reconnecting')
133- # push_client.connect(client_config.tiger_id, client_config.private_key)
134- # except:
135- # print('connect failed, retry')
136- # time.sleep(t)
137- # else:
138- # print('reconnect success')
139- # return
140- # print('reconnect failed, please check your network')
141- #
123+ def error_callback (content ):
124+ """错误回调"""
125+ print (content )
126+
127+
128+ def connect_callback ():
129+ """连接建立回调"""
130+ print ('connected' )
131+
132+
133+ def disconnect_callback ():
134+ """连接断开回调. 此处利用回调进行重连"""
135+ for t in range (1 , 200 ):
136+ try :
137+ print ('disconnected, reconnecting' )
138+ push_client .connect (client_config .tiger_id , client_config .private_key )
139+ except :
140+ print ('connect failed, retry' )
141+ time .sleep (t )
142+ else :
143+ print ('reconnect success' )
144+ return
145+ print ('reconnect failed, please check your network' )
146+
142147
143148if __name__ == '__main__' :
144149 client_config = get_client_config ()
@@ -150,21 +155,24 @@ def unsubscribe_callback(destination, content):
150155 # 已订阅 symbol 查询回调
151156 push_client .subscribed_symbols = on_query_subscribed_quote
152157 # 订单变动回调
153- # push_client.order_changed = on_order_changed
158+ push_client .order_changed = on_order_changed
154159 # 资产变动回调
155- # push_client.asset_changed = on_asset_changed
160+ push_client .asset_changed = on_asset_changed
156161 # 持仓变动回调
157- # push_client.position_changed = on_position_changed
162+ push_client .position_changed = on_position_changed
158163
159164 # 订阅成功与否的回调
160165 push_client .subscribe_callback = subscribe_callback
161166 # 退订成功与否的回调
162167 push_client .unsubscribe_callback = unsubscribe_callback
163168
169+ # 错误信息回调
170+ push_client .error_callback = error_callback
171+
164172 # 建立推送连接
165173 push_client .connect (client_config .tiger_id , client_config .private_key )
166174 # 断线重连回调
167- # push_client.disconnect_callback = disconnect_callback
175+ push_client .disconnect_callback = disconnect_callback
168176
169177 # 订阅行情
170178 push_client .subscribe_quote (['AAPL' , 'GOOG' ])
0 commit comments