Skip to content

Commit 73cb7c4

Browse files
committed
add secret_key config
1 parent 2c789a8 commit 73cb7c4

File tree

8 files changed

+136
-136
lines changed

8 files changed

+136
-136
lines changed

setup.py

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

1313
setup(
1414
name='tigeropen',
15-
version='1.4.0',
15+
version='1.4.1',
1616
description='TigerBrokers Open API',
1717
packages=find_packages(exclude=[]),
1818
author='TigerBrokers',

tigeropen/common/util/order_utils.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tigeropen.common.consts import OrderStatus
99

1010

11-
def market_order(account, contract, action, quantity, user_id=None):
11+
def market_order(account, contract, action, quantity, secret_key=None):
1212
"""
1313
市价单
1414
:param account:
@@ -17,10 +17,10 @@ def market_order(account, contract, action, quantity, user_id=None):
1717
:param quantity:
1818
:return:
1919
"""
20-
return Order(account, contract, action, 'MKT', quantity, user_id=user_id)
20+
return Order(account, contract, action, 'MKT', quantity, secret_key=secret_key)
2121

2222

23-
def limit_order(account, contract, action, quantity, limit_price, user_id=None):
23+
def limit_order(account, contract, action, quantity, limit_price, secret_key=None):
2424
"""
2525
限价单
2626
:param account:
@@ -30,10 +30,10 @@ def limit_order(account, contract, action, quantity, limit_price, user_id=None):
3030
:param limit_price: 限价的价格
3131
:return:
3232
"""
33-
return Order(account, contract, action, 'LMT', quantity, limit_price=limit_price, user_id=user_id)
33+
return Order(account, contract, action, 'LMT', quantity, limit_price=limit_price, secret_key=secret_key)
3434

3535

36-
def stop_order(account, contract, action, quantity, aux_price, user_id=None):
36+
def stop_order(account, contract, action, quantity, aux_price, secret_key=None):
3737
"""
3838
止损单
3939
:param account:
@@ -43,10 +43,10 @@ def stop_order(account, contract, action, quantity, aux_price, user_id=None):
4343
:param aux_price: 触发止损单的价格
4444
:return:
4545
"""
46-
return Order(account, contract, action, 'STP', quantity, aux_price=aux_price, user_id=user_id)
46+
return Order(account, contract, action, 'STP', quantity, aux_price=aux_price, secret_key=secret_key)
4747

4848

49-
def stop_limit_order(account, contract, action, quantity, limit_price, aux_price, user_id=None):
49+
def stop_limit_order(account, contract, action, quantity, limit_price, aux_price, secret_key=None):
5050
"""
5151
限价止损单
5252
:param account:
@@ -58,10 +58,10 @@ def stop_limit_order(account, contract, action, quantity, limit_price, aux_price
5858
:return:
5959
"""
6060
return Order(account, contract, action, 'STP_LMT', quantity, limit_price=limit_price, aux_price=aux_price,
61-
user_id=user_id)
61+
secret_key=secret_key)
6262

6363

64-
def trail_order(account, contract, action, quantity, trailing_percent=None, aux_price=None, user_id=None):
64+
def trail_order(account, contract, action, quantity, trailing_percent=None, aux_price=None, secret_key=None):
6565
"""
6666
移动止损单
6767
:param account:
@@ -73,7 +73,7 @@ def trail_order(account, contract, action, quantity, trailing_percent=None, aux_
7373
:return:
7474
"""
7575
return Order(account, contract, action, 'TRAIL', quantity, trailing_percent=trailing_percent, aux_price=aux_price,
76-
user_id=user_id)
76+
secret_key=secret_key)
7777

7878

7979
def order_leg(leg_type, price, time_in_force='DAY', outside_rth=None):
@@ -87,7 +87,7 @@ def order_leg(leg_type, price, time_in_force='DAY', outside_rth=None):
8787
return OrderLeg(leg_type=leg_type, price=price, time_in_force=time_in_force, outside_rth=outside_rth)
8888

8989

90-
def limit_order_with_legs(account, contract, action, quantity, limit_price, order_legs=None, user_id=None):
90+
def limit_order_with_legs(account, contract, action, quantity, limit_price, order_legs=None, secret_key=None):
9191
"""
9292
限价单 + 附加订单(仅环球账户支持)
9393
:param account:
@@ -101,7 +101,7 @@ def limit_order_with_legs(account, contract, action, quantity, limit_price, orde
101101
if order_legs and len(order_legs) > 2:
102102
raise Exception('2 order legs at most')
103103
return Order(account, contract, action, 'LMT', quantity, limit_price=limit_price, order_legs=order_legs,
104-
user_id=user_id)
104+
secret_key=secret_key)
105105

106106

107107
def algo_order_params(start_time=None, end_time=None, no_take_liq=None, allow_past_end_time=None, participation_rate=None):
@@ -118,7 +118,7 @@ def algo_order_params(start_time=None, end_time=None, no_take_liq=None, allow_pa
118118
allow_past_end_time=allow_past_end_time, participation_rate=participation_rate)
119119

120120

121-
def algo_order(account, contract, action, quantity, strategy, algo_params=None, limit_price=None, user_id=None):
121+
def algo_order(account, contract, action, quantity, strategy, algo_params=None, limit_price=None, secret_key=None):
122122
"""
123123
算法订单
124124
:param account:
@@ -131,7 +131,7 @@ def algo_order(account, contract, action, quantity, strategy, algo_params=None,
131131
:return:
132132
"""
133133
return Order(account, contract, action, order_type=strategy, quantity=quantity, algo_params=algo_params,
134-
limit_price=limit_price, outside_rth=False, user_id=user_id)
134+
limit_price=limit_price, outside_rth=False, secret_key=secret_key)
135135

136136

137137
def get_order_status(value):

tigeropen/examples/client_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def get_client_config():
1818
client_config = TigerOpenClientConfig(sandbox_debug=is_sandbox)
1919
client_config.private_key = read_private_key('your private key file path')
2020
client_config.tiger_id = 'your tiger id'
21-
client_config.account = 'your account' # 环球账户.
22-
# 只使用一个账户时,不论是环球账户, 标准账户或是模拟账户, 都填在 client_config.account 下, 默认只会使用这里的账户.
21+
client_config.account = 'your account' # 账户. 不论是环球账户, 综合账户或是模拟账户, 都填在此处
2322
# standard_account 属性和 paper_account 属性只是为多账户时取用方便, 一般可忽略
24-
client_config.standard_account = None # 标准账户
25-
client_config.paper_account = None # 模拟账户
23+
client_config.standard_account = None
24+
client_config.paper_account = None
25+
client_config.secret_key = None # 机构密钥(机构用户需要填写, 个人开发者无需填写)
2626
client_config.language = Language.en_US
2727
return client_config

tigeropen/tiger_open_config.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ class TigerOpenClientConfig(object):
3636
def __init__(self, sandbox_debug=False):
3737
# 开发者应用id
3838
self._tiger_id = ''
39-
# 授权账户(环球账户,推荐)
39+
# 授权账户
4040
self._account = ''
41-
# 标准账户
41+
# 综合账户
4242
self._standard_account = ''
4343
# 模拟账户
4444
self._paper_account = ''
4545
# 开发者应用私钥
4646
self._private_key = ''
4747
# 请求签名类型,推荐RSA2
4848
self._sign_type = SIGN_TYPE
49-
# 用户id
50-
self._user_id = ''
49+
# 机构密钥
50+
self._secret_key = ''
5151

5252
# 老虎证券开放平台网关地址
5353
self._server_url = SERVER_URL
@@ -165,32 +165,32 @@ def timeout(self, value):
165165
self._timeout = value
166166

167167
@property
168-
def user_id(self):
169-
return self._user_id
168+
def secret_key(self):
169+
return self._secret_key
170170

171-
@user_id.setter
172-
def user_id(self, value):
173-
self._user_id = value
171+
@secret_key.setter
172+
def secret_key(self, value):
173+
self._secret_key = value
174174

175175

176176
def get_client_config(private_key_path, tiger_id, account, standard_account=None, paper_account=None,
177177
sandbox_debug=False, sign_type=None, timeout=None, language=None, charset=None,
178-
server_url=None, socket_host_port=None, user_id=None):
178+
server_url=None, socket_host_port=None, secret_key=None):
179179
"""
180180
生成客户端配置
181181
:param private_key_path: 私钥文件路径, 如 '/Users/tiger/.ssh/rsa_private_key.pem'
182182
:param tiger_id: 开发者应用 id
183-
:param account: 授权账户 (必填. 作为发送请求时的默认账户)
184-
:param standard_account:
185-
:param paper_account:
183+
:param account: 授权账户 (必填. 作为发送请求时的默认账户. 不论是环球账户, 综合账户或是模拟账户, 都使用此参数)
184+
:param standard_account: 多账户时可将综合账户填在此处, 一般可忽略
185+
:param paper_account: 多账户时可将模拟账户填在此处, 一般可忽略
186186
:param sandbox_debug: 是否请求 sandbox 环境
187187
:param sign_type: 签名类型
188188
:param timeout: 请求超时时间, 单位秒
189189
:param language: 语言, 取值为 tigeropen.common.consts.Language 中的枚举类型
190190
:param charset: 字符集编码
191191
:param server_url: 网关地址
192192
:param socket_host_port: 推送长连接的域名端口, 值为协议, 域名, 端口构成的三元组
193-
:param user_id: 用户id
193+
:param secret_key: 机构密钥(个人开发者无需指定)
194194
:return:
195195
"""
196196
config = TigerOpenClientConfig(sandbox_debug=sandbox_debug)
@@ -213,7 +213,7 @@ def get_client_config(private_key_path, tiger_id, account, standard_account=None
213213
config.server_url = server_url
214214
if socket_host_port:
215215
config.socket_host_port = socket_host_port
216-
if user_id:
217-
config.user_id = user_id
216+
if secret_key:
217+
config.secret_key = secret_key
218218
return config
219219

tigeropen/trade/domain/order.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class Order(object):
1616
__slots__ = ["account", "id", "order_id", "parent_id", "order_time", "reason", "trade_time", "contract", "action",
1717
"quantity", "filled", "_remaining", "avg_fill_price", "commission", "realized_pnl", "_status",
1818
"trail_stop_price", "limit_price", "aux_price", "trailing_percent", "percent_offset", "action",
19-
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params", "user_id"]
19+
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params", "secret_key"]
2020

2121
def __init__(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
2222
trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
2323
outside_rth=None, filled=0, avg_fill_price=0, commission=None, realized_pnl=None,
2424
id=None, order_id=None, parent_id=None, order_time=None, trade_time=None, order_legs=None,
25-
algo_params=None, user_id=None):
25+
algo_params=None, secret_key=None):
2626
"""
2727
- account: 订单所属的账户
2828
- id: 全局订单 id
@@ -50,7 +50,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
5050
- remaining: 未成交的数量
5151
- order_legs: 附加订单列表
5252
- algo_params: 算法订单参数
53-
- user_id: 用户id
53+
- secret_key: 机构密钥
5454
"""
5555

5656
self.id = id
@@ -79,7 +79,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
7979
self.trade_time = trade_time
8080
self.order_legs = order_legs
8181
self.algo_params = algo_params
82-
self.user_id = user_id
82+
self.secret_key = secret_key
8383

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

0 commit comments

Comments
 (0)