Skip to content

Commit 444af12

Browse files
authored
Merge pull request #42 from tigerfintech/fix_unsubscribe_depth_quote
fix depth quote unsubscribe; remove config standard_account/paper_account
2 parents 8049c70 + 6be4ef8 commit 444af12

File tree

7 files changed

+26
-49
lines changed

7 files changed

+26
-49
lines changed

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
@author: gaoan
66
"""
77
from os import path
8-
98
from setuptools import find_packages, setup
9+
from tigeropen import __VERSION__
10+
1011

1112
with open(path.join(path.abspath(path.dirname(__file__)), 'requirements.txt')) as f:
1213
install_requires = f.read()
1314

1415
setup(
1516
name='tigeropen',
16-
version='2.0.1',
17+
version=__VERSION__,
1718
description='TigerBrokers Open API',
1819
packages=find_packages(exclude=[]),
1920
author='TigerBrokers',

tigeropen/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
Created on 2018/9/16
44
55
@author: gaoan
6-
"""
6+
"""
7+
__VERSION__ = '2.0.2'

tigeropen/common/consts/params.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
P_VERSION = "version"
1515
P_NOTIFY_URL = "notify_url"
1616
P_DEVICE_ID = "device_id"
17+
P_SDK_VERSION = "sdk-version"
18+
P_SDK_VERSION_PREFIX = "python-"
1719

1820
COMMON_PARAM_KEYS = {P_TIGER_ID, P_METHOD, P_CHARSET, P_SIGN_TYPE, P_SIGN, P_TIMESTAMP, P_VERSION, P_NOTIFY_URL,
1921
P_DEVICE_ID}

tigeropen/examples/client_config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ 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-
# standard_account 属性和 paper_account 属性只是为多账户时取用方便, 一般可忽略
23-
client_config.standard_account = None
24-
client_config.paper_account = None
21+
client_config.account = 'your account'
2522
client_config.secret_key = None # 机构交易员专有密钥 (机构用户需要填写, 个人开发者无需填写)
2623
client_config.language = Language.en_US
2724
return client_config

tigeropen/push/push_client.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import stomp
1313
from stomp.exception import ConnectFailedException
1414

15+
from tigeropen import __VERSION__
1516
from tigeropen.common.consts import OrderStatus
17+
from tigeropen.common.consts.params import P_SDK_VERSION, P_SDK_VERSION_PREFIX
1618
from tigeropen.common.consts.push_destinations import QUOTE, QUOTE_DEPTH, QUOTE_FUTURE, QUOTE_OPTION, TRADE_ASSET, \
1719
TRADE_ORDER, TRADE_POSITION
1820
from tigeropen.common.consts.push_types import RequestType, ResponseType
@@ -107,7 +109,7 @@ def _connect(self):
107109
self._stomp_connection.set_listener('push', self)
108110
self._stomp_connection.start()
109111
try:
110-
self._stomp_connection.connect(self._tiger_id, self._sign, wait=True)
112+
self._stomp_connection.connect(self._tiger_id, self._sign, wait=True, headers=self._generate_headers())
111113
except ConnectFailedException as e:
112114
raise e
113115

@@ -241,6 +243,8 @@ def on_message(self, headers, body):
241243
def on_error(self, headers, body):
242244
if self.error_callback:
243245
self.error_callback(body)
246+
else:
247+
logging.error(body)
244248

245249
def _update_subscribe_id(self, destination):
246250
self._destination_counter_map[destination] += 1
@@ -341,7 +345,7 @@ def query_subscribed_quote(self):
341345
查询已订阅行情的合约
342346
:return:
343347
"""
344-
headers = dict()
348+
headers = self._generate_headers()
345349
headers['destination'] = QUOTE
346350
headers['req-type'] = RequestType.REQ_SUB_SYMBOLS.value
347351
self._stomp_connection.send(QUOTE, "{}", headers=headers)
@@ -358,7 +362,7 @@ def unsubscribe_depth_quote(self, symbols=None, id=None):
358362
退订深度行情更新
359363
:return:
360364
"""
361-
self._handle_quote_unsubscribe(destination=QUOTE_DEPTH, subscription='AskBid', sub_id=id, symbols=symbols)
365+
self._handle_quote_unsubscribe(destination=QUOTE_DEPTH, subscription='QuoteDepth', sub_id=id, symbols=symbols)
362366

363367
def _handle_trade_subscribe(self, destination, subscription, account=None, extra_headers=None):
364368
if extra_headers is None:
@@ -385,25 +389,28 @@ def _handle_quote_unsubscribe(self, destination, subscription, sub_id=None, symb
385389
extra_headers=extra_headers)
386390

387391
def _handle_subscribe(self, destination, subscription, extra_headers=None):
388-
headers = dict()
392+
headers = self._generate_headers(extra_headers)
389393
headers['destination'] = destination
390394
headers['subscription'] = subscription
391395
self._update_subscribe_id(destination)
392396
sub_id = self._get_subscribe_id(destination)
393397
headers['id'] = sub_id
394398

395-
if extra_headers is not None:
396-
headers.update(extra_headers)
397399
self._stomp_connection.subscribe(destination, id=sub_id, headers=headers)
398400
return sub_id
399401

400402
def _handle_unsubscribe(self, destination, subscription, sub_id=None, extra_headers=None):
401-
headers = dict()
403+
headers = self._generate_headers(extra_headers)
402404
headers['destination'] = destination
403405
headers['subscription'] = subscription
404406
id_ = sub_id if sub_id is not None else self._get_subscribe_id(destination)
405407
headers['id'] = id_
406-
if extra_headers:
407-
headers.update(extra_headers)
408408

409409
self._stomp_connection.unsubscribe(id=id_, headers=headers)
410+
411+
def _generate_headers(self, extra_headers=None):
412+
headers = {P_SDK_VERSION: P_SDK_VERSION_PREFIX + __VERSION__}
413+
if extra_headers is not None:
414+
headers.update(extra_headers)
415+
return headers
416+

tigeropen/tiger_open_config.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ def __init__(self, sandbox_debug=False):
3838
self._tiger_id = ''
3939
# 授权账户
4040
self._account = ''
41-
# 综合账户
42-
self._standard_account = ''
43-
# 模拟账户
44-
self._paper_account = ''
4541
# 开发者应用私钥
4642
self._private_key = ''
4743
# 请求签名类型,推荐RSA2
@@ -83,22 +79,6 @@ def account(self):
8379
@account.setter
8480
def account(self, value):
8581
self._account = value
86-
87-
@property
88-
def standard_account(self):
89-
return self._standard_account
90-
91-
@standard_account.setter
92-
def standard_account(self, value):
93-
self._standard_account = value
94-
95-
@property
96-
def paper_account(self):
97-
return self._paper_account
98-
99-
@paper_account.setter
100-
def paper_account(self, value):
101-
self._paper_account = value
10282

10383
@property
10484
def sign_type(self):
@@ -173,16 +153,13 @@ def secret_key(self, value):
173153
self._secret_key = value
174154

175155

176-
def get_client_config(private_key_path, tiger_id, account, standard_account=None, paper_account=None,
177-
sandbox_debug=False, sign_type=None, timeout=None, language=None, charset=None,
178-
server_url=None, socket_host_port=None, secret_key=None):
156+
def get_client_config(private_key_path, tiger_id, account, sandbox_debug=False, sign_type=None, timeout=None,
157+
language=None, charset=None, server_url=None, socket_host_port=None, secret_key=None):
179158
"""
180159
生成客户端配置
181160
:param private_key_path: 私钥文件路径, 如 '/Users/tiger/.ssh/rsa_private_key.pem'
182161
:param tiger_id: 开发者应用 id
183162
:param account: 授权账户 (必填. 作为发送请求时的默认账户. 不论是环球账户, 综合账户或是模拟账户, 都使用此参数)
184-
:param standard_account: 多账户时可将综合账户填在此处, 一般可忽略
185-
:param paper_account: 多账户时可将模拟账户填在此处, 一般可忽略
186163
:param sandbox_debug: 是否请求 sandbox 环境
187164
:param sign_type: 签名类型
188165
:param timeout: 请求超时时间, 单位秒
@@ -197,10 +174,6 @@ def get_client_config(private_key_path, tiger_id, account, standard_account=None
197174
config.private_key = read_private_key(private_key_path)
198175
config.tiger_id = tiger_id
199176
config.account = account
200-
if standard_account:
201-
config.standard_account = standard_account
202-
if paper_account:
203-
config.paper_account = paper_account
204177
if sign_type:
205178
config.sign_type = sign_type
206179
if timeout:

tigeropen/trade/trade_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ def __init__(self, client_config, logger=None):
3131
super(TradeClient, self).__init__(client_config, logger=logger)
3232
if client_config:
3333
self._account = client_config.account
34-
self._standard_account = client_config.standard_account
35-
self._paper_account = client_config.paper_account
3634
self._lang = client_config.language
3735
self._secret_key = client_config.secret_key
3836
else:
3937
self._account = None
40-
self._standard_account = None
41-
self._paper_account = None
4238
self._secret_key = None
4339

4440
def get_managed_accounts(self, account=None):

0 commit comments

Comments
 (0)