Skip to content

Commit 807cc20

Browse files
committed
Merge branch 'feature_institution_secret_key' into 'dev'
Feature institution secret key See merge request server/openapi/openapi-python-sdk!70
2 parents e419a4b + 4a92813 commit 807cc20

File tree

7 files changed

+144
-25
lines changed

7 files changed

+144
-25
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/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: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +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+
# 机构交易员专有密钥
50+
self._secret_key = ''
4951

5052
# 老虎证券开放平台网关地址
5153
self._server_url = SERVER_URL
@@ -162,24 +164,33 @@ def timeout(self):
162164
def timeout(self, value):
163165
self._timeout = value
164166

167+
@property
168+
def secret_key(self):
169+
return self._secret_key
170+
171+
@secret_key.setter
172+
def secret_key(self, value):
173+
self._secret_key = value
174+
165175

166176
def get_client_config(private_key_path, tiger_id, account, standard_account=None, paper_account=None,
167177
sandbox_debug=False, sign_type=None, timeout=None, language=None, charset=None,
168-
server_url=None, socket_host_port=None):
178+
server_url=None, socket_host_port=None, secret_key=None):
169179
"""
170180
生成客户端配置
171181
:param private_key_path: 私钥文件路径, 如 '/Users/tiger/.ssh/rsa_private_key.pem'
172182
:param tiger_id: 开发者应用 id
173-
:param account: 授权账户 (必填. 作为发送请求时的默认账户)
174-
:param standard_account:
175-
:param paper_account:
183+
:param account: 授权账户 (必填. 作为发送请求时的默认账户. 不论是环球账户, 综合账户或是模拟账户, 都使用此参数)
184+
:param standard_account: 多账户时可将综合账户填在此处, 一般可忽略
185+
:param paper_account: 多账户时可将模拟账户填在此处, 一般可忽略
176186
:param sandbox_debug: 是否请求 sandbox 环境
177187
:param sign_type: 签名类型
178188
:param timeout: 请求超时时间, 单位秒
179189
:param language: 语言, 取值为 tigeropen.common.consts.Language 中的枚举类型
180190
:param charset: 字符集编码
181191
:param server_url: 网关地址
182192
:param socket_host_port: 推送长连接的域名端口, 值为协议, 域名, 端口构成的三元组
193+
:param secret_key: 机构交易员专有密钥 (个人开发者无需指定)
183194
:return:
184195
"""
185196
config = TigerOpenClientConfig(sandbox_debug=sandbox_debug)
@@ -202,5 +213,7 @@ def get_client_config(private_key_path, tiger_id, account, standard_account=None
202213
config.server_url = server_url
203214
if socket_host_port:
204215
config.socket_host_port = socket_host_port
216+
if secret_key:
217+
config.secret_key = secret_key
205218
return config
206219

tigeropen/trade/domain/order.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
ALGO_PARAMS_TAG_MAP = {'noTakeLiq': 'no_take_liq', 'startTime': 'start_time', 'endTime': 'end_time',
1212
'participationRate': 'participation_rate', 'allowPastEndTime': 'allow_past_end_time'}
1313

14+
1415
class Order(object):
1516
__slots__ = ["account", "id", "order_id", "parent_id", "order_time", "reason", "trade_time", "contract", "action",
1617
"quantity", "filled", "_remaining", "avg_fill_price", "commission", "realized_pnl", "_status",
1718
"trail_stop_price", "limit_price", "aux_price", "trailing_percent", "percent_offset", "action",
18-
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params"]
19+
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params", "secret_key"]
1920

2021
def __init__(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
2122
trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
2223
outside_rth=None, filled=0, avg_fill_price=0, commission=None, realized_pnl=None,
2324
id=None, order_id=None, parent_id=None, order_time=None, trade_time=None, order_legs=None,
24-
algo_params=None):
25+
algo_params=None, secret_key=None):
2526
"""
2627
- account: 订单所属的账户
2728
- id: 全局订单 id
@@ -49,6 +50,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
4950
- remaining: 未成交的数量
5051
- order_legs: 附加订单列表
5152
- algo_params: 算法订单参数
53+
- secret_key: 机构交易员专有密钥
5254
"""
5355

5456
self.id = id
@@ -77,6 +79,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
7779
self.trade_time = trade_time
7880
self.order_legs = order_legs
7981
self.algo_params = algo_params
82+
self.secret_key = secret_key
8083

8184
def to_dict(self):
8285
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: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class AccountsParams(object):
1010
def __init__(self):
1111
self._account = None
12+
self._secret_key = None
1213

1314
@property
1415
def account(self):
@@ -18,17 +19,27 @@ def account(self):
1819
def account(self, value):
1920
self._account = value
2021

22+
@property
23+
def secret_key(self):
24+
return self._secret_key
25+
26+
@secret_key.setter
27+
def secret_key(self, value):
28+
self._secret_key = value
29+
2130
def to_openapi_dict(self):
2231
params = dict()
2332
if self.account:
2433
params['account'] = self.account
25-
34+
if self.secret_key:
35+
params['secret_key'] = self.secret_key
2636
return params
2737

2838

2939
class AssetParams(object):
3040
def __init__(self):
3141
self._account = None
42+
self._secret_key = None
3243
self._segment = False
3344
self._market_value = False
3445
self._sub_accounts = None
@@ -41,6 +52,14 @@ def account(self):
4152
def account(self, value):
4253
self._account = value
4354

55+
@property
56+
def secret_key(self):
57+
return self._secret_key
58+
59+
@secret_key.setter
60+
def secret_key(self, value):
61+
self._secret_key = value
62+
4463
@property
4564
def segment(self):
4665
return self._segment
@@ -70,6 +89,9 @@ def to_openapi_dict(self):
7089
if self.account:
7190
params['account'] = self.account
7291

92+
if self.secret_key:
93+
params['secret_key'] = self.secret_key
94+
7395
if self.segment:
7496
params['segment'] = self.segment
7597

@@ -85,6 +107,7 @@ def to_openapi_dict(self):
85107
class PositionParams(object):
86108
def __init__(self):
87109
self._account = None
110+
self._secret_key = None
88111
self._symbol = None
89112
self._sec_type = None
90113
self._currency = None
@@ -99,6 +122,14 @@ def account(self):
99122
def account(self, value):
100123
self._account = value
101124

125+
@property
126+
def secret_key(self):
127+
return self._secret_key
128+
129+
@secret_key.setter
130+
def secret_key(self, value):
131+
self._secret_key = value
132+
102133
@property
103134
def symbol(self):
104135
return self._symbol
@@ -144,6 +175,9 @@ def to_openapi_dict(self):
144175
if self.account:
145176
params['account'] = self.account
146177

178+
if self.secret_key:
179+
params['secret_key'] = self.secret_key
180+
147181
if self.symbol:
148182
params['symbol'] = self.symbol
149183

@@ -165,6 +199,7 @@ def to_openapi_dict(self):
165199
class ContractParams(object):
166200
def __init__(self):
167201
self._account = None
202+
self._secret_key = None
168203
self._symbol = None
169204
self._symbols = None
170205
self._sec_type = None
@@ -182,6 +217,14 @@ def account(self):
182217
def account(self, value):
183218
self._account = value
184219

220+
@property
221+
def secret_key(self):
222+
return self._secret_key
223+
224+
@secret_key.setter
225+
def secret_key(self, value):
226+
self._secret_key = value
227+
185228
@property
186229
def symbol(self):
187230
return self._symbol
@@ -251,6 +294,9 @@ def to_openapi_dict(self):
251294
if self.account:
252295
params['account'] = self.account
253296

297+
if self.secret_key:
298+
params['secret_key'] = self.secret_key
299+
254300
if self.symbol:
255301
params['symbol'] = self.symbol
256302

@@ -281,6 +327,7 @@ def to_openapi_dict(self):
281327
class OrderParams(object):
282328
def __init__(self):
283329
self._account = None # 账户
330+
self._secret_key = None
284331
self._id = None # 订单号(全局)
285332
self._order_id = None # 订单号(账户维度)
286333
self._is_brief = None
@@ -294,6 +341,14 @@ def account(self):
294341
def account(self, value):
295342
self._account = value
296343

344+
@property
345+
def secret_key(self):
346+
return self._secret_key
347+
348+
@secret_key.setter
349+
def secret_key(self, value):
350+
self._secret_key = value
351+
297352
@property
298353
def order_id(self):
299354
return self._order_id
@@ -331,6 +386,9 @@ def to_openapi_dict(self):
331386
if self.account:
332387
params['account'] = self.account
333388

389+
if self.secret_key:
390+
params['secret_key'] = self.secret_key
391+
334392
if self.order_id:
335393
params['order_id'] = self.order_id
336394

@@ -349,6 +407,7 @@ def to_openapi_dict(self):
349407
class OrdersParams(object):
350408
def __init__(self):
351409
self._account = None # 账户
410+
self._secret_key = None
352411
self._market = None # 市场
353412
self._sec_type = None # 合约类型
354413
self._symbol = None # 合约代码
@@ -368,6 +427,14 @@ def account(self):
368427
def account(self, value):
369428
self._account = value
370429

430+
@property
431+
def secret_key(self):
432+
return self._secret_key
433+
434+
@secret_key.setter
435+
def secret_key(self, value):
436+
self._secret_key = value
437+
371438
@property
372439
def market(self):
373440
return self._market
@@ -453,6 +520,9 @@ def to_openapi_dict(self):
453520
if self.account:
454521
params['account'] = self.account
455522

523+
if self.secret_key:
524+
params['secret_key'] = self.secret_key
525+
456526
if self.market:
457527
params['market'] = self.market
458528

@@ -489,6 +559,7 @@ def to_openapi_dict(self):
489559
class PlaceModifyOrderParams(object):
490560
def __init__(self):
491561
self.account = None
562+
self.secret_key = None
492563
self.id = None
493564
self.order_id = None
494565
self.contract = None
@@ -530,6 +601,8 @@ def to_openapi_dict(self):
530601

531602
if self.account:
532603
params['account'] = self.account
604+
if self.secret_key:
605+
params['secret_key'] = self.secret_key
533606

534607
if self.order_id:
535608
params['order_id'] = self.order_id
@@ -591,6 +664,7 @@ def to_openapi_dict(self):
591664
class CancelOrderParams(object):
592665
def __init__(self):
593666
self._account = None
667+
self._secret_key = None
594668
self._id = None
595669
self._order_id = None
596670

@@ -602,6 +676,14 @@ def account(self):
602676
def account(self, value):
603677
self._account = value
604678

679+
@property
680+
def secret_key(self):
681+
return self._secret_key
682+
683+
@secret_key.setter
684+
def secret_key(self, value):
685+
self._secret_key = value
686+
605687
@property
606688
def order_id(self):
607689
return self._order_id
@@ -623,6 +705,9 @@ def to_openapi_dict(self):
623705
if self.account:
624706
params['account'] = self.account
625707

708+
if self.secret_key:
709+
params['secret_key'] = self.secret_key
710+
626711
if self.order_id:
627712
params['order_id'] = self.order_id
628713

0 commit comments

Comments
 (0)