Skip to content

Commit b5e830d

Browse files
committed
Merge branch 'dev' into 'master'
contract api upgrade to v3; See merge request server/openapi/openapi-python-sdk!131
2 parents 65a13b9 + 682b4ee commit b5e830d

File tree

7 files changed

+51
-18
lines changed

7 files changed

+51
-18
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2.1.8 (2022-08-26)
2+
### Modify
3+
- `TradeClient.get_orders` 新增参数 `seg_type`, 可指定交易品种(证券SEC/期货FUT/全部ALL)
4+
- `PushClient` 修改自动重连重试次数
5+
- `TradeClient.get_contract` 接口版本升级到V3
6+
### Fixed
7+
- 修复 `TradeClient.get_contract` 获取港股期权合约时返回空的问题
8+
9+
110
## 2.1.7 (2022-08-19)
211
### New
312
- 新增获取期货某类型所有合约接口 `QuoteClient.get_all_future_contracts`

tigeropen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
@author: gaoan
66
"""
7-
__VERSION__ = '2.1.7'
7+
__VERSION__ = '2.1.8'

tigeropen/common/consts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SecurityType(Enum):
5151

5252
@unique
5353
class SegmentType(Enum):
54+
ALL = 'ALL'
5455
SEC = 'SEC'
5556
FUT = 'FUT'
5657

tigeropen/push/push_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _connect(self):
117117

118118
self._stomp_connection = stomp.Connection12(host_and_ports=[(self.host, self.port)],
119119
keepalive=KEEPALIVE, timeout=self._connection_timeout,
120-
heartbeats=self._heartbeats)
120+
heartbeats=self._heartbeats, reconnect_attempts_max=60)
121121
self._stomp_connection.set_listener('push', self)
122122
try:
123123
if self.use_ssl:
@@ -143,6 +143,8 @@ def on_connected(self, frame):
143143
def on_disconnected(self):
144144
if self.disconnect_callback:
145145
self.disconnect_callback()
146+
else:
147+
self._connect()
146148

147149
def on_message(self, frame):
148150
"""

tigeropen/trade/request/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ def __init__(self):
441441
self._secret_key = None
442442
self._market = None # 市场
443443
self._sec_type = None # 合约类型
444+
self._seg_type = None # segment type
444445
self._symbol = None # 合约代码
445446
self._is_brief = None
446447
self._start_date = None
@@ -482,6 +483,14 @@ def sec_type(self):
482483
def sec_type(self, value):
483484
self._sec_type = value
484485

486+
@property
487+
def seg_type(self):
488+
return self._seg_type
489+
490+
@seg_type.setter
491+
def seg_type(self, value):
492+
self._seg_type = value
493+
485494
@property
486495
def symbol(self):
487496
return self._symbol
@@ -560,6 +569,9 @@ def to_openapi_dict(self):
560569
if self.sec_type:
561570
params['sec_type'] = self.sec_type
562571

572+
if self.seg_type:
573+
params['seg_type'] = self.seg_type
574+
563575
if self.symbol:
564576
params['symbol'] = self.symbol
565577

tigeropen/trade/response/contracts_response.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ def parse_response_content(self, response_content):
2727
if self.data:
2828
data_json = self.data if isinstance(self.data, dict) else json.loads(self.data)
2929
if 'items' in data_json:
30-
for item in data_json['items']:
31-
contract_fields = {}
32-
for key, value in item.items():
33-
tag = CONTRACT_FIELD_MAPPINGS[key] if key in CONTRACT_FIELD_MAPPINGS else camel_to_underline(key)
34-
if isinstance(value, (list, dict)):
35-
value = camel_to_underline_obj(value)
36-
contract_fields[tag] = value
37-
contract = Contract()
38-
for k, v in contract_fields.items():
39-
setattr(contract, k, v)
40-
self.contracts.append(contract)
30+
items = data_json['items']
31+
else:
32+
items = [data_json]
33+
for item in items:
34+
contract_fields = {}
35+
for key, value in item.items():
36+
tag = CONTRACT_FIELD_MAPPINGS[key] if key in CONTRACT_FIELD_MAPPINGS else camel_to_underline(key)
37+
if isinstance(value, (list, dict)):
38+
value = camel_to_underline_obj(value)
39+
contract_fields[tag] = value
40+
contract = Contract()
41+
for k, v in contract_fields.items():
42+
setattr(contract, k, v)
43+
self.contracts.append(contract)

tigeropen/trade/trade_client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
import logging
88

9-
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, Market, Currency, Language
9+
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, Market, Currency, Language, OPEN_API_SERVICE_VERSION_V3
1010
from tigeropen.common.consts.service_types import CONTRACTS, ACCOUNTS, POSITIONS, ASSETS, ORDERS, ORDER_NO, \
1111
CANCEL_ORDER, MODIFY_ORDER, PLACE_ORDER, ACTIVE_ORDERS, INACTIVE_ORDERS, FILLED_ORDERS, CONTRACT, PREVIEW_ORDER, \
1212
PRIME_ASSETS, ORDER_TRANSACTIONS, QUOTE_CONTRACT, ANALYTICS_ASSET
@@ -134,6 +134,7 @@ def get_contract(self, symbol, sec_type=SecurityType.STK, currency=None, exchang
134134
params.sec_type = get_enum_value(sec_type)
135135
params.currency = get_enum_value(currency)
136136
params.lang = get_enum_value(self._lang)
137+
params.version = OPEN_API_SERVICE_VERSION_V3
137138
if expiry:
138139
params.expiry = expiry
139140
if strike:
@@ -301,7 +302,7 @@ def get_prime_assets(self, account=None):
301302
return None
302303

303304
def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None, start_time=None, end_time=None,
304-
limit=100, is_brief=False, states=None, sort_by=None):
305+
limit=100, is_brief=False, states=None, sort_by=None, seg_type=None):
305306
"""
306307
获取订单列表
307308
:param account:
@@ -316,6 +317,7 @@ def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None
316317
:param states: 订单状态枚举对象列表, 可选, 若传递则按状态筛选
317318
:param sort_by: Field used to sort and filter start_time and end_time,available value can be imported from
318319
tigeropen.common.consts.OrderSortBY, like LATEST_CREATED or LATEST_STATUS_UPDATED
320+
:param seg_type: tigeropen.common.consts.SegmentType
319321
:return: Order 对象构成的列表. Order 对象信息参见 tigeropen.trade.domain.order
320322
"""
321323
params = OrdersParams()
@@ -331,6 +333,7 @@ def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None
331333
params.states = [get_enum_value(state) for state in states] if states else None
332334
params.sort_by = get_enum_value(sort_by)
333335
params.lang = get_enum_value(self._lang)
336+
params.seg_type = get_enum_value(seg_type)
334337
request = OpenApiRequest(ORDERS, biz_model=params)
335338
response_content = self.__fetch_data(request)
336339
if response_content:
@@ -343,7 +346,7 @@ def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None
343346
return None
344347

345348
def get_open_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None, start_time=None,
346-
end_time=None, parent_id=None, sort_by=None):
349+
end_time=None, parent_id=None, sort_by=None, seg_type=None):
347350
"""
348351
获取待成交订单列表. 参数同 get_orders
349352
:param parent_id: 主订单 order_id
@@ -359,6 +362,7 @@ def get_open_orders(self, account=None, sec_type=None, market=Market.ALL, symbol
359362
params.parent_id = parent_id
360363
params.sort_by = get_enum_value(sort_by)
361364
params.lang = get_enum_value(self._lang)
365+
params.seg_type = get_enum_value(seg_type)
362366
request = OpenApiRequest(ACTIVE_ORDERS, biz_model=params)
363367
response_content = self.__fetch_data(request)
364368
if response_content:
@@ -371,7 +375,7 @@ def get_open_orders(self, account=None, sec_type=None, market=Market.ALL, symbol
371375
return None
372376

373377
def get_cancelled_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None, start_time=None,
374-
end_time=None, sort_by=None):
378+
end_time=None, sort_by=None, seg_type=None):
375379
"""
376380
获取已撤销订单列表. 参数同 get_orders
377381
"""
@@ -385,6 +389,7 @@ def get_cancelled_orders(self, account=None, sec_type=None, market=Market.ALL, s
385389
params.end_date = date_str_to_timestamp(end_time, self._timezone)
386390
params.sort_by = get_enum_value(sort_by)
387391
params.lang = get_enum_value(self._lang)
392+
params.seg_type = get_enum_value(seg_type)
388393
request = OpenApiRequest(INACTIVE_ORDERS, biz_model=params)
389394
response_content = self.__fetch_data(request)
390395
if response_content:
@@ -397,7 +402,7 @@ def get_cancelled_orders(self, account=None, sec_type=None, market=Market.ALL, s
397402
return None
398403

399404
def get_filled_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None, start_time=None,
400-
end_time=None, sort_by=None):
405+
end_time=None, sort_by=None, seg_type=None):
401406
"""
402407
获取已成交订单列表. 参数同 get_orders
403408
"""
@@ -411,6 +416,7 @@ def get_filled_orders(self, account=None, sec_type=None, market=Market.ALL, symb
411416
params.end_date = date_str_to_timestamp(end_time, self._timezone)
412417
params.sort_by = get_enum_value(sort_by)
413418
params.lang = get_enum_value(self._lang)
419+
params.seg_type = get_enum_value(seg_type)
414420
request = OpenApiRequest(FILLED_ORDERS, biz_model=params)
415421
response_content = self.__fetch_data(request)
416422
if response_content:

0 commit comments

Comments
 (0)