Skip to content

Commit 48ad1c4

Browse files
committed
order transaction push; gtd order
1 parent f62730f commit 48ad1c4

File tree

9 files changed

+41
-17
lines changed

9 files changed

+41
-17
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
TRADE_ASSET = 'trade/asset'
1010
TRADE_POSITION = 'trade/position'
1111
TRADE_ORDER = 'trade/order'
12-
TRADE_EXECUTION = 'trade/execution'
12+
TRADE_TRANSACTION = 'trade/transaction'

tigeropen/common/consts/push_subscriptions.py

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

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: 9 additions & 9 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, TRADE_EXECUTION
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, SUBSCRIPTION_TRADE_EXECUTION
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,7 +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.execution_changed = None
100+
self.transaction_changed = None
101101
self.connect_callback = None
102102
self.disconnect_callback = None
103103
self.subscribe_callback = None
@@ -276,14 +276,14 @@ def on_message(self, frame):
276276
self.order_changed(account, items)
277277
elif response_type == str(ResponseType.SUBSCRIBE_TRADE_EXECUTION.value):
278278
data = json.loads(body)
279-
if self.execution_changed:
279+
if self.transaction_changed:
280280
if 'account' in data:
281281
account = data.pop('account', None)
282282
items = []
283283
for key, value in data.items():
284284
items.append((camel_to_underline(key), value))
285285
if items:
286-
self.execution_changed(account, items)
286+
self.transaction_changed(account, items)
287287
elif response_type == str(ResponseType.GET_SUBSCRIBE_END.value):
288288
if self.subscribe_callback:
289289
self.subscribe_callback(headers.get('destination'), json.loads(body))
@@ -356,19 +356,19 @@ def unsubscribe_order(self, id=None):
356356
"""
357357
self._handle_trade_unsubscribe(TRADE_ORDER, SUBSCRIPTION_TRADE_ORDER, sub_id=id)
358358

359-
def subscribe_execution(self, account=None):
359+
def subscribe_transaction(self, account=None):
360360
"""
361361
订阅订单执行明细
362362
:return:
363363
"""
364-
return self._handle_trade_subscribe(TRADE_EXECUTION, SUBSCRIPTION_TRADE_EXECUTION, account)
364+
return self._handle_trade_subscribe(TRADE_TRANSACTION, SUBSCRIPTION_TRADE_TRANSACTION, account)
365365

366-
def unsubscribe_execution(self, id=None):
366+
def unsubscribe_transaction(self, id=None):
367367
"""
368368
退订订单执行明细
369369
:return:
370370
"""
371-
self._handle_trade_unsubscribe(TRADE_EXECUTION, SUBSCRIPTION_TRADE_EXECUTION, sub_id=id)
371+
self._handle_trade_unsubscribe(TRADE_TRANSACTION, SUBSCRIPTION_TRADE_TRANSACTION, sub_id=id)
372372

373373
def subscribe_quote(self, symbols, quote_key_type=QuoteKeyType.TRADE, focus_keys=None):
374374
"""

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 til cancel / 'GTD' good til date
4949
- outside_rth: 是否允许盘前盘后交易(outside of regular trading hours 美股专属). True 允许, False 不允许
5050
- contract: 合约对象
5151
- status: Order_Status 的枚举, 表示订单状态

tigeropen/trade/response/orders_response.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'contractId': 'contract_id', 'algoStrategy': 'algo_strategy',
2323
'trailStopPrice': 'trail_stop_price', 'trailingPercent': 'trailing_percent',
2424
'percentOffset': 'percent_offset', 'identifier': 'identifier', 'algoParameters': 'algo_params',
25-
'userMark': 'user_mark', 'updateTime': 'update_time'
25+
'userMark': 'user_mark', 'updateTime': 'update_time', 'expireTime': 'expire_time'
2626
}
2727

2828

@@ -87,6 +87,7 @@ def parse_order(item, secret_key=None):
8787
trailing_percent = order_fields.get('trailing_percent')
8888
percent_offset = order_fields.get('percent_offset')
8989
time_in_force = order_fields.get('time_in_force')
90+
expire_time = order_fields.get('expire_time')
9091
outside_rth = order_fields.get('outside_rth')
9192
filled = order_fields.get('filled')
9293
avg_fill_price = order_fields.get('avg_fill_price')
@@ -110,7 +111,7 @@ def parse_order(item, secret_key=None):
110111
filled=filled, avg_fill_price=avg_fill_price, commission=commission,
111112
realized_pnl=realized_pnl, id=id_, order_id=order_id, parent_id=parent_id,
112113
algo_params=algo_params, liquidation=liquidation, algo_strategy=algo_strategy, discount=discount,
113-
attr_desc=attr_desc, source=source, user_mark=user_mark)
114+
attr_desc=attr_desc, source=source, user_mark=user_mark, expire_time=expire_time)
114115
if 'order_time' in order_fields:
115116
order.order_time = order_fields.get('order_time')
116117
if 'trade_time' in order_fields:

0 commit comments

Comments
 (0)