Skip to content

Commit 4f4e6b8

Browse files
committed
remove PushClient auto_reconnect param
1 parent 67f73bf commit 4f4e6b8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.1.2 (2022-06-07)
2+
### Modify
3+
- 升级 stomp.py 版本, 将之前的 4.1.24 升级到 8.0.1
4+
### Breaking
5+
- PushClient 去除 `auto_reconnect` 参数,如需自动重连,可自定义 `disconnect_callback` 进行重连
6+
- 处理连接被踢的情况,如果有多台设备使用相同 tiger_id 连接, 新连接会将较早的连接踢掉,较早连接会抛出异常,停止接收消息
7+
18
## 2.1.1 (2022-05-25)
29
### New
310
- 新增批量分页获取k线接口

tigeropen/push/push_client.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import logging
99
import sys
10+
import os
1011
from collections import defaultdict
1112

1213
import stomp
@@ -22,6 +23,7 @@
2223
SUBSCRIPTION_TRADE_ORDER
2324
from tigeropen.common.consts.push_types import RequestType, ResponseType
2425
from tigeropen.common.consts.quote_keys import QuoteChangeKey, QuoteKeyType
26+
from tigeropen.common.exceptions import ApiException
2527
from tigeropen.common.util.string_utils import camel_to_underline
2628
from tigeropen.common.util.common_utils import get_enum_value
2729
from tigeropen.common.util.order_utils import get_order_status
@@ -68,14 +70,12 @@
6870

6971

7072
class 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

Comments
 (0)