Skip to content

Commit 4db758a

Browse files
committed
Merge branch 'feature_execution_push' into 'dev'
Feature execution push See merge request server/openapi/openapi-python-sdk!139
2 parents 4a46c64 + a6646f3 commit 4db758a

File tree

12 files changed

+70
-9
lines changed

12 files changed

+70
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.2.2 (2022-11-22)
2+
### New
3+
- 订单支持GTD类型, 下单时可通过指定 Order 属性 time_in_force = "GTD" 设置
4+
- 订单成交明细支持长链接订阅推送
5+
16
## 2.2.1 (2022-11-07)
27
### Fixed
38
- 修复 `TradeClient.get_trade_ticks` begin_index 参数传 0 不生效的问题

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.2.1'
7+
__VERSION__ = '2.2.2'

tigeropen/common/consts/push_destinations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
TRADE_ASSET = 'trade/asset'
1010
TRADE_POSITION = 'trade/position'
1111
TRADE_ORDER = 'trade/order'
12+
TRADE_TRANSACTION = 'trade/transaction'

tigeropen/common/consts/push_subscriptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
SUBSCRIPTION_TRADE_ASSET = 'Asset'
1010
SUBSCRIPTION_TRADE_POSITION = 'Position'
1111
SUBSCRIPTION_TRADE_ORDER = 'OrderStatus'
12+
SUBSCRIPTION_TRADE_TRANSACTION = 'TradeTransaction'

tigeropen/common/consts/push_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ResponseType(Enum):
4545
SUBSCRIBE_ORDER_STATUS = 9
4646
SUBSCRIBE_POSITION = 10
4747
SUBSCRIBE_ASSET = 11
48+
SUBSCRIBE_TRADE_EXECUTION = 12
4849

4950
# 行情
5051
GET_MARKET_STATE_END = 101

tigeropen/examples/push_client_demo.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ def on_order_changed(account, items):
123123
"""
124124
print(account, items)
125125

126+
def on_transaction_changed(account, items):
127+
"""
128+
129+
:param account:
130+
:param items:
131+
:return:
132+
account:11111,
133+
items: [('id', 28819544190616576), ('currency', 'USD'), ('sec_type', 'FUT'), ('market', 'SG'), ('symbol', 'CN'),
134+
('multiplier', 1.0), ('action', 'BUY'), ('filled_quantity', 1.0), ('filled_price', 12309.0),
135+
('order_id', 28819544031364096), ('transact_time', 1668774872538), ('create_time', 1668774872946),
136+
('update_time', 1668774872946), ('identifier', 'CN2212'), ('timestamp', 1668774873002), ('segment', 'C')]
137+
"""
138+
print(f'account:{account}, items: {items}')
126139

127140
def on_asset_changed(account, items):
128141
"""
@@ -210,6 +223,8 @@ def disconnect_callback():
210223
# push_client.subscribed_symbols = on_query_subscribed_quote
211224
# 订单变动回调
212225
push_client.order_changed = on_order_changed
226+
# 订单执行明细回调
227+
push_client.transaction_changed = on_transaction_changed
213228
# 资产变动回调
214229
push_client.asset_changed = on_asset_changed
215230
# 持仓变动回调
@@ -244,6 +259,8 @@ def disconnect_callback():
244259
push_client.subscribe_asset()
245260
# 订阅订单变动
246261
push_client.subscribe_order()
262+
# 订阅订单执行明细
263+
push_client.subscribe_transaction()
247264
# 订阅持仓变动
248265
push_client.subscribe_position()
249266
# 查询已订阅的 symbol

tigeropen/push/push_client.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
from tigeropen.common.consts import OrderStatus
1818
from tigeropen.common.consts.params import P_SDK_VERSION, P_SDK_VERSION_PREFIX
1919
from tigeropen.common.consts.push_destinations import QUOTE, QUOTE_DEPTH, QUOTE_FUTURE, QUOTE_OPTION, TRADE_ASSET, \
20-
TRADE_ORDER, TRADE_POSITION, TRADE_TICK
20+
TRADE_ORDER, TRADE_POSITION, TRADE_TICK, TRADE_TRANSACTION
2121
from tigeropen.common.consts.push_subscriptions import SUBSCRIPTION_QUOTE, SUBSCRIPTION_QUOTE_DEPTH, \
2222
SUBSCRIPTION_QUOTE_OPTION, SUBSCRIPTION_QUOTE_FUTURE, SUBSCRIPTION_TRADE_ASSET, SUBSCRIPTION_TRADE_POSITION, \
23-
SUBSCRIPTION_TRADE_ORDER, SUBSCRIPTION_TRADE_TICK
23+
SUBSCRIPTION_TRADE_ORDER, SUBSCRIPTION_TRADE_TICK, SUBSCRIPTION_TRADE_TRANSACTION
2424
from tigeropen.common.consts.push_types import RequestType, ResponseType
2525
from tigeropen.common.consts.quote_keys import QuoteChangeKey, QuoteKeyType
2626
from tigeropen.common.exceptions import ApiException
@@ -97,6 +97,7 @@ def __init__(self, host, port, use_ssl=True, connection_timeout=120, heartbeats=
9797
self.asset_changed = None
9898
self.position_changed = None
9999
self.order_changed = None
100+
self.transaction_changed = None
100101
self.connect_callback = None
101102
self.disconnect_callback = None
102103
self.subscribe_callback = None
@@ -273,6 +274,16 @@ def on_message(self, frame):
273274
items.append((camel_to_underline(key), value))
274275
if items:
275276
self.order_changed(account, items)
277+
elif response_type == str(ResponseType.SUBSCRIBE_TRADE_EXECUTION.value):
278+
data = json.loads(body)
279+
if self.transaction_changed:
280+
if 'account' in data:
281+
account = data.pop('account', None)
282+
items = []
283+
for key, value in data.items():
284+
items.append((camel_to_underline(key), value))
285+
if items:
286+
self.transaction_changed(account, items)
276287
elif response_type == str(ResponseType.GET_SUBSCRIBE_END.value):
277288
if self.subscribe_callback:
278289
self.subscribe_callback(headers.get('destination'), json.loads(body))
@@ -345,6 +356,20 @@ def unsubscribe_order(self, id=None):
345356
"""
346357
self._handle_trade_unsubscribe(TRADE_ORDER, SUBSCRIPTION_TRADE_ORDER, sub_id=id)
347358

359+
def subscribe_transaction(self, account=None):
360+
"""
361+
订阅订单执行明细
362+
:return:
363+
"""
364+
return self._handle_trade_subscribe(TRADE_TRANSACTION, SUBSCRIPTION_TRADE_TRANSACTION, account)
365+
366+
def unsubscribe_transaction(self, id=None):
367+
"""
368+
退订订单执行明细
369+
:return:
370+
"""
371+
self._handle_trade_unsubscribe(TRADE_TRANSACTION, SUBSCRIPTION_TRADE_TRANSACTION, sub_id=id)
372+
348373
def subscribe_quote(self, symbols, quote_key_type=QuoteKeyType.TRADE, focus_keys=None):
349374
"""
350375
订阅行情更新

tigeropen/quote/quote_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ class QuoteClient(TigerOpenClient):
7272

7373
def __init__(self, client_config, logger=None, is_grab_permission=True):
7474
if not logger:
75-
self.logger = logging.getLogger('tiger_openapi')
76-
super(QuoteClient, self).__init__(client_config, logger=self.logger)
75+
logger = logging.getLogger('tiger_openapi')
76+
self.logger = logger
77+
super(QuoteClient, self).__init__(client_config, logger=logger)
7778
self._lang = LANGUAGE
7879
self._timezone = eastern
7980
self._url = None

tigeropen/trade/domain/order.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Order:
1717
"trail_stop_price", "limit_price", "aux_price", "trailing_percent", "percent_offset", "action",
1818
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params", "algo_strategy",
1919
"secret_key", "liquidation", "discount", "attr_desc", "source", 'adjust_limit', 'sub_ids', "user_mark",
20-
"update_time"]
20+
"update_time", "expire_time"]
2121

2222
def __init__(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
2323
trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
@@ -45,7 +45,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
4545
- trailing_percent: 跟踪止损单-百分比, 取值范围为0-100
4646
- percent_offset: None,
4747
- order_type: 订单类型, 'MKT' 市价单 / 'LMT' 限价单 / 'STP' 止损单 / 'STP_LMT' 止损限价单 / 'TRAIL' 跟踪止损单
48-
- time_in_force: 有效期,'DAY' 日内有效 / 'GTC' 撤销前有效
48+
- time_in_force: 有效期,'DAY' 日内有效 / 'GTC' good till cancel / 'GTD' good till date
4949
- outside_rth: 是否允许盘前盘后交易(outside of regular trading hours 美股专属). True 允许, False 不允许
5050
- contract: 合约对象
5151
- status: Order_Status 的枚举, 表示订单状态
@@ -60,6 +60,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
6060
例如:0.001 代表向上调整且幅度不超过 0.1%;-0.001 代表向下调整且幅度不超过 0.1%。默认 0 表示不调整
6161
- sub_ids id list of sub orders.
6262
- user_mark: user's remark
63+
- expire_time: GTD order's expire time
6364
"""
6465

6566
self.id = id
@@ -98,6 +99,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
9899
self.adjust_limit = kwargs.get('adjust_limit')
99100
self.sub_ids = kwargs.get('sub_ids')
100101
self.user_mark = kwargs.get('user_mark')
102+
self.expire_time = kwargs.get('expire_time')
101103

102104
def to_dict(self):
103105
dct = {name: getattr(self, name) for name in self.__slots__ if name not in ORDER_FIELDS_TO_IGNORE}

tigeropen/trade/request/model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ def __init__(self):
774774
self.algo_params = None
775775
self.adjust_limit = None
776776
self.user_mark = None
777+
self.expire_time = None
777778

778779
def to_openapi_dict(self):
779780
params = super().to_openapi_dict()
@@ -831,6 +832,8 @@ def to_openapi_dict(self):
831832
params['adjust_limit'] = self.adjust_limit
832833
if self.user_mark is not None:
833834
params['user_mark'] = self.user_mark
835+
if self.expire_time is not None:
836+
params['expire_time'] = self.expire_time
834837

835838
if self.order_legs:
836839
if len(self.order_legs) > 2:

0 commit comments

Comments
 (0)