77import json
88import logging
99import sys
10+ import os
1011from collections import defaultdict
1112
1213import stomp
2223 SUBSCRIPTION_TRADE_ORDER
2324from tigeropen .common .consts .push_types import RequestType , ResponseType
2425from tigeropen .common .consts .quote_keys import QuoteChangeKey , QuoteKeyType
26+ from tigeropen .common .exceptions import ApiException
2527from tigeropen .common .util .string_utils import camel_to_underline
2628from tigeropen .common .util .common_utils import get_enum_value
2729from tigeropen .common .util .order_utils import get_order_status
6870
6971
7072class PushClient (stomp .ConnectionListener ):
71- def __init__ (self , host , port , use_ssl = True , connection_timeout = 120 , auto_reconnect = True ,
72- heartbeats = (30 * 1000 , 30 * 1000 )):
73+ def __init__ (self , host , port , use_ssl = True , connection_timeout = 120 , heartbeats = (30 * 1000 , 30 * 1000 )):
7374 """
7475 :param host:
7576 :param port:
7677 :param use_ssl:
77- param connection_timeout: unit: second. The timeout value should be greater the heartbeats interval
78- :param auto_reconnect:
78+ :param connection_timeout: unit: second. The timeout value should be greater the heartbeats interval
7979 :param heartbeats: tuple of millisecond
8080 """
8181 self .host = host
@@ -98,7 +98,6 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=120, auto_reconn
9898 self .unsubscribe_callback = None
9999 self .error_callback = None
100100 self ._connection_timeout = connection_timeout
101- self ._auto_reconnect = auto_reconnect
102101 self ._heartbeats = heartbeats
103102 _patch_ssl ()
104103
@@ -133,13 +132,11 @@ def disconnect(self):
133132
134133 def on_connected (self , frame ):
135134 if self .connect_callback :
136- self .connect_callback ()
135+ self .connect_callback (frame )
137136
138137 def on_disconnected (self ):
139138 if self .disconnect_callback :
140139 self .disconnect_callback ()
141- elif self ._auto_reconnect :
142- self ._connect ()
143140
144141 def on_message (self , frame ):
145142 """
@@ -264,6 +261,12 @@ def on_message(self, frame):
264261 logging .error (e , exc_info = True )
265262
266263 def on_error (self , frame ):
264+ body = json .loads (frame .body )
265+ if body .get ('code' ) == 4001 :
266+ logging .error (body )
267+ self .disconnect_callback = None
268+ raise ApiException (4001 , body .get ('message' ))
269+
267270 if self .error_callback :
268271 self .error_callback (frame )
269272 else :
0 commit comments