2626from tigeropen .common .util .common_utils import get_enum_value
2727from tigeropen .common .util .order_utils import get_order_status
2828from tigeropen .common .util .signature_utils import sign_with_rsa
29+ from tigeropen .push import _patch_ssl
2930
3031HOUR_TRADING_QUOTE_KEYS_MAPPINGS = {'hourTradingLatestPrice' : 'latest_price' , 'hourTradingPreClose' : 'pre_close' ,
3132 'hourTradingLatestTime' : 'latest_time' , 'hourTradingVolume' : 'volume' ,
@@ -73,7 +74,7 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=120, auto_reconn
7374 :param host:
7475 :param port:
7576 :param use_ssl:
76- : param connection_timeout: second
77+ param connection_timeout: unit: second. The timeout value should be greater the heartbeats interval
7778 :param auto_reconnect:
7879 :param heartbeats: tuple of millisecond
7980 """
@@ -99,6 +100,7 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=120, auto_reconn
99100 self ._connection_timeout = connection_timeout
100101 self ._auto_reconnect = auto_reconnect
101102 self ._heartbeats = heartbeats
103+ _patch_ssl ()
102104
103105 def _connect (self ):
104106 try :
@@ -108,12 +110,13 @@ def _connect(self):
108110 except :
109111 pass
110112
111- self ._stomp_connection = stomp .Connection12 (host_and_ports = [(self .host , self .port ), ], use_ssl = self . use_ssl ,
113+ self ._stomp_connection = stomp .Connection12 (host_and_ports = [(self .host , self .port )] ,
112114 keepalive = KEEPALIVE , timeout = self ._connection_timeout ,
113115 heartbeats = self ._heartbeats )
114116 self ._stomp_connection .set_listener ('push' , self )
115- self ._stomp_connection .start ()
116117 try :
118+ if self .use_ssl :
119+ self ._stomp_connection .set_ssl ([(self .host , self .port )])
117120 self ._stomp_connection .connect (self ._tiger_id , self ._sign , wait = True , headers = self ._generate_headers ())
118121 except ConnectFailedException as e :
119122 raise e
@@ -128,7 +131,7 @@ def disconnect(self):
128131 if self ._stomp_connection :
129132 self ._stomp_connection .disconnect ()
130133
131- def on_connected (self , headers , body ):
134+ def on_connected (self , frame ):
132135 if self .connect_callback :
133136 self .connect_callback ()
134137
@@ -138,13 +141,18 @@ def on_disconnected(self):
138141 elif self ._auto_reconnect :
139142 self ._connect ()
140143
141- def on_message (self , headers , body ):
144+ def on_message (self , frame ):
142145 """
143146 Called by the STOMP connection when a MESSAGE frame is received.
144147
145- :param dict headers: a dictionary containing all headers sent by the server as key/value pairs.
146- :param body: the frame's payload - the message body.
148+ :param Frame frame: the stomp frame. stomp.utils.Frame
149+ A STOMP frame's attributes:
150+ cmd: the protocol command
151+ headers: a map of headers for the frame
152+ body: the content of the frame.
147153 """
154+ headers = frame .headers
155+ body = frame .body
148156 try :
149157 response_type = headers .get ('ret-type' )
150158 if response_type == str (ResponseType .GET_SUB_SYMBOLS_END .value ):
@@ -255,11 +263,11 @@ def on_message(self, headers, body):
255263 except Exception as e :
256264 logging .error (e , exc_info = True )
257265
258- def on_error (self , headers , body ):
266+ def on_error (self , frame ):
259267 if self .error_callback :
260- self .error_callback (body )
268+ self .error_callback (frame )
261269 else :
262- logging .error (body )
270+ logging .error (frame . body )
263271
264272 def _update_subscribe_id (self , destination ):
265273 self ._destination_counter_map [destination ] += 1
0 commit comments