Skip to content

Commit d12ad3d

Browse files
committed
push error callback add log; fix unsubscribe depth quote; subscribe add
sdk version
1 parent 016239a commit d12ad3d

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
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/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+

0 commit comments

Comments
 (0)