Skip to content

Commit 47aa2af

Browse files
committed
Merge branch 'dev' into 'master'
Dev See merge request server/openapi/openapi-python-sdk!136
2 parents 720add9 + c1d691b commit 47aa2af

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
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.0 (2022-11-01)
2+
### New
3+
- 长链接支持期货逐笔推送. 可通过 `PushClient.subscribe_tick` 订阅,使用 `PushClient.tick_changed` 接收回调
4+
5+
16
## 2.1.9 (2022-10-12)
27
### New
38
- 支持多牌照配置, 分牌照请求不同域名. 可通过 client_config.license 指定牌照

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.1.9'
7+
__VERSION__ = '2.2.0'

tigeropen/examples/push_client_demo.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def on_tick_changed(symbol, items):
8989
'part_code_name': 'NASDAQ Stock Market, LLC (NASDAQ)', 'cond': 'US_FORM_T', 'time': 1656405616573,
9090
'server_timestamp': 1656405573461,
9191
'type': 'TradeTick', 'quote_level': 'usStockQuote', 'sn': 343, 'timestamp': 1656405617385}]
92+
93+
Futures tick items example:
94+
[{'tick_type': None, 'price': 15544.0, 'volume': 1, 'part_code': None, 'part_code_name': None, 'cond': None,
95+
'time': 1667285183000, 'sn': 636960, 'server_timestamp': 1667285184162, 'quote_level': 'quote-fut-tick',
96+
'type': 'TradeTick', 'timestamp': 1667285184156},
97+
{'tick_type': None, 'price': 15544.0, 'volume': 1, 'part_code': None, 'part_code_name': None, 'cond': None,
98+
'time': 1667285183000, 'sn': 636961, 'server_timestamp': 1667285184162, 'quote_level': 'quote-fut-tick',
99+
'type': 'TradeTick', 'timestamp': 1667285184156},
100+
{'tick_type': None, 'price': 15544.0, 'volume': 2, 'part_code': None, 'part_code_name': None,
101+
'cond': None, 'time': 1667285183000, 'sn': 636962, 'server_timestamp': 1667285184162,
102+
'quote_level': 'quote-fut-tick', 'type': 'TradeTick', 'timestamp': 1667285184156}]
92103
:return:
93104
"""
94105
print(symbol, items)
@@ -227,6 +238,7 @@ def disconnect_callback():
227238

228239
# 订阅逐笔数据
229240
push_client.subscribe_tick(['AMD', 'QQQ'])
241+
push_client.subscribe_tick(['HSImain'])
230242

231243
# 订阅资产变动
232244
push_client.subscribe_asset()

tigeropen/push/push_client.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ def _generate_headers(self, extra_headers=None):
482482
headers.update(extra_headers)
483483
return headers
484484

485-
@staticmethod
486-
def _convert_tick(tick):
485+
def _convert_tick(self, tick):
487486
data = json.loads(tick)
488487
symbol = data.pop('symbol')
489488
data = camel_to_underline_obj(data)
@@ -493,29 +492,50 @@ def _convert_tick(tick):
493492
price_items = [('price', (item + price_base) / price_offset) for item in data.pop('prices')]
494493
time_items = [('time', item) for item in accumulate(data.pop('times'))]
495494
volumes = [('volume', item) for item in data.pop('volumes')]
496-
tick_type_items = [('tick_type', item) for item in data.pop('tick_type')]
497-
part_codes = data.pop('part_code')
495+
tick_types = data.pop('tick_type') if 'tick_type' in data else None
496+
if tick_types:
497+
tick_type_items = [('tick_type', item) for item in tick_types]
498+
else:
499+
tick_type_items = [('tick_type', None) for _ in range(len(time_items))]
500+
part_codes = data.pop('part_code') if 'part_code' in data else None
498501
if part_codes:
499502
part_code_items = [('part_code', get_part_code(item)) for item in part_codes]
500503
part_code_name_items = [('part_code_name', get_part_code_name(item)) for item in part_codes]
501504
else:
502505
part_code_items = [('part_code', None) for _ in range(len(time_items))]
503506
part_code_name_items = [('part_code_name', None) for _ in range(len(time_items))]
504-
505-
conds = data.pop('cond')
507+
conds = data.pop('cond') if 'cond' in data else None
506508
cond_map = get_trade_condition_map(data.get('quote_level'))
507509
if conds:
508510
cond_items = [('cond', get_trade_condition(item, cond_map)) for item in conds]
509511
else:
510512
cond_items = [('cond', None) for _ in range(len(time_items))]
511513
sn = data.pop('sn')
512514
sn_list = [('sn', sn + i) for i in range(len(time_items))]
515+
merged_vols = data.pop('merged_vols') if 'merged_vols' in data else None
516+
if merged_vols:
517+
merged_vols_items = [('merged_vols', item) for item in merged_vols]
518+
else:
519+
merged_vols_items = [('merged_vols', None) for _ in range(len(time_items))]
513520
tick_data = zip_longest(tick_type_items, price_items, volumes, part_code_items,
514-
part_code_name_items, cond_items, time_items, sn_list)
521+
part_code_name_items, cond_items, time_items, sn_list, merged_vols_items)
515522
items = []
516523
for item in tick_data:
517-
item_dict = dict(item)
524+
try:
525+
item_dict = dict(item)
526+
except:
527+
self.logger.error('convert tick error')
528+
continue
518529
item_dict.update(data)
519-
items.append(item_dict)
530+
if item_dict.get('merged_vols'):
531+
vols = item_dict.pop('merged_vols').get('vols')
532+
for i, vol in enumerate(vols):
533+
sub_item = dict(item_dict)
534+
sub_item['sn'] = sub_item['sn'] * 10 + i
535+
sub_item['volume'] = vol
536+
items.append(sub_item)
537+
else:
538+
item_dict.pop('merged_vols', None)
539+
items.append(item_dict)
520540
return symbol, items
521541

0 commit comments

Comments
 (0)