Skip to content

Commit 1c52de3

Browse files
committed
kick out callback
1 parent 29be339 commit 1c52de3

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

tigeropen/examples/trade_client_demo.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from tigeropen.trade.trade_client import TradeClient
1616
from tigeropen.common.response import TigerResponse
1717
from tigeropen.common.request import OpenApiRequest
18-
from tigeropen.common.consts import Currency, SecurityType
18+
from tigeropen.common.consts import Currency, SecurityType, OrderSortBy
1919
from tigeropen.common.util.contract_utils import stock_contract, option_contract_by_symbol, future_contract, \
2020
war_contract_by_symbol, iopt_contract_by_symbol
2121
from tigeropen.common.util.order_utils import limit_order, limit_order_with_legs, order_leg, algo_order_params, \
@@ -71,6 +71,30 @@ def get_account_apis():
7171
openapi_client.get_analytics_asset(start_date='2021-12-01', end_date='2021-12-07')
7272

7373

74+
def test_get_orders_by_page():
75+
"""分页获取订单"""
76+
trade_client = TradeClient(client_config)
77+
result = list()
78+
# 每次返回数量(需 <= 300)
79+
limit = 300
80+
conditions = {
81+
'limit': limit,
82+
'start_time': '2024-12-01',
83+
'end_time': '2025-02-12',
84+
# 返回数据是按照时间逆序,即最新的数据在前。此处按照下单时间 order_time 排序
85+
'sort_by': OrderSortBy.LATEST_CREATED,
86+
}
87+
orders_page = trade_client.get_orders(**conditions)
88+
result.extend(orders_page)
89+
while len(orders_page) == limit:
90+
next_order_time = orders_page[-1].order_time
91+
conditions.pop('end_time', None)
92+
orders_page = trade_client.get_orders(**conditions, end_time=next_order_time)
93+
result.extend(orders_page)
94+
print(f'total order size: {len(result)}')
95+
return result
96+
97+
7498
def trade_apis():
7599
account = client_config.account
76100
openapi_client = TradeClient(client_config, logger=logger)

tigeropen/push/protobuf_push_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=30, heartbeats=(
5858
self.unsubscribe_callback = None
5959
self.error_callback = None
6060
self.heartbeat_callback = None
61+
self.kickout_callback = None
6162
self._connection_timeout = connection_timeout
6263
self._heartbeats = heartbeats
6364
self._client_config = client_config
@@ -122,7 +123,9 @@ def on_heartbeat(self, frame):
122123
self.heartbeat_callback(frame)
123124

124125
def on_error(self, frame):
125-
if self.error_callback:
126+
if frame.code == 4001 and self.kickout_callback:
127+
self.kickout_callback(frame)
128+
elif self.error_callback:
126129
self.error_callback(frame)
127130
else:
128131
self.logger.error(frame)

tigeropen/push/push_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ def error_callback(self):
181181
def error_callback(self, value):
182182
self.client.error_callback = value
183183

184+
@property
185+
def kickout_callback(self):
186+
return self.client.kickout_callback
187+
188+
@kickout_callback.setter
189+
def kickout_callback(self, value):
190+
self.client.kickout_callback = value
191+
184192
@property
185193
def heartbeat_callback(self):
186194
return self.client.on_heartbeat

tigeropen/trade/request/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ def __init__(self):
488488
self._parent_id = None
489489
self._sort_by = None
490490
self._show_charges = None
491+
self._page_token = None
491492

492493
@property
493494
def account(self):
@@ -601,6 +602,14 @@ def show_charges(self):
601602
def show_charges(self, value):
602603
self._show_charges = value
603604

605+
@property
606+
def page_token(self):
607+
return self._page_token
608+
609+
@page_token.setter
610+
def page_token(self, value):
611+
self._page_token = value
612+
604613
def to_openapi_dict(self):
605614
params = super().to_openapi_dict()
606615
if self.account:
@@ -645,6 +654,9 @@ def to_openapi_dict(self):
645654
if self.show_charges is not None:
646655
params['show_charges'] = self.show_charges
647656

657+
if self.page_token:
658+
params['page_token'] = self.page_token
659+
648660
return params
649661

650662

tigeropen/trade/trade_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None
321321
:param sec_type:
322322
:param market:
323323
:param symbol:
324-
:param start_time: 开始时间. 若是时间戳需要精确到毫秒, 为13位整数;
324+
:param start_time: 开始时间(闭区间,包含). 若是时间戳需要精确到毫秒, 为13位整数;
325325
或是日期时间格式的字符串,如"2017-01-01"和 "2017-01-01 12:00:00"
326-
:param end_time: 截至时间. 格式同 start_time
326+
:param end_time: 截至时间(开区间,不包含). 格式同 start_time.
327327
:param limit: 每次获取订单的数量
328328
:param is_brief: 是否返回精简的订单数据
329329
:param states: 订单状态枚举对象列表, 可选, 若传递则按状态筛选

0 commit comments

Comments
 (0)