Skip to content

Commit 762b412

Browse files
committed
Merge branch 'feat_contract_lotsize' into 'master'
Feat contract lotsize See merge request server/openapi/openapi-python-sdk!230
2 parents 12bcf77 + 1c52de3 commit 762b412

9 files changed

Lines changed: 57 additions & 9 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/quote/quote_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,18 +1047,18 @@ def get_future_contract(self, contract_code, lang=None):
10471047
raise ApiException(response.code, response.message)
10481048
return None
10491049

1050-
def get_future_continuous_contracts(self, type_=None, lang=None):
1050+
def get_future_continuous_contracts(self, future_type=None, lang=None):
10511051
"""
10521052
Get Future Continuous Contracts
1053-
:param type_: 'CL'
1053+
:param future_type: 'CL'
10541054
:param lang: zh_CN,zh_TW,en_US
10551055
:return: pandas.DataFrame
10561056
contract_code continuous contract_month currency display_multiplier exchange exchange_code first_notice_date last_bidding_close_time last_trading_date min_tick multiplier name symbol trade type
10571057
0 CLmain False USD 1 NYMEX NYMEX 0 0.01 1000.0 WTI原油主连 CL True CL
10581058
10591059
"""
10601060
params = FutureContractParams()
1061-
params.type = type_
1061+
params.type = future_type
10621062
params.lang = get_enum_value(lang) if lang else get_enum_value(self._lang)
10631063

10641064
request = OpenApiRequest(FUTURE_CONTINUOUS_CONTRACTS, biz_model=params)

tigeropen/tiger_open_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
DEFAULT_PROPS_FILE = 'tiger_openapi_config.properties'
5757
DEFAULT_TOKEN_FILE = 'tiger_openapi_token.properties'
58-
TOKEN_REFRESH_DURATION = 24 * 60 * 60 # seconds
58+
TOKEN_REFRESH_DURATION = 0 # seconds
5959
TOKEN_CHECK_INTERVAL = 5 * 60 # seconds
6060

6161
def fallback_get_mac_address():

tigeropen/trade/domain/contract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(self, symbol=None, currency=None, contract_id=None, sec_type=None,
8989
self.discounted_start_at = kwargs.get('discounted_start_at')
9090
self.discounted_end_at = kwargs.get('discounted_end_at')
9191
self.categories = kwargs.get('categories')
92+
self.lot_size = kwargs.get('lot_size')
9293

9394
@property
9495
def right(self):

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/response/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
'shortable', 'long_initial_margin', 'long_maintenance_margin', 'contract_month', 'identifier',
1111
'primary_exchange', 'min_tick', 'trading_class', 'continuous', 'trade', 'tradeable',
1212
'last_trading_date', 'first_notice_date', 'last_bidding_close_time', 'shortable_count',
13-
'categories'])
13+
'categories', 'is_etf', 'etf_leverage', 'lot_size'])
1414

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)