Skip to content

Commit 1f9df93

Browse files
committed
tick push
1 parent a38583f commit 1f9df93

File tree

5 files changed

+184
-0
lines changed

5 files changed

+184
-0
lines changed

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/6/24
4+
# @Author : sukai

tests/test_push_client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/6/24
4+
# @Author : sukai
5+
import unittest
6+
7+
from tigeropen.push.push_client import PushClient
8+
9+
10+
class TestPushClient(unittest.TestCase):
11+
12+
def test_tick_convert(self):
13+
body = '{"symbol":"QQQ","tickType":"*****","serverTimestamp":1656062042242,"priceOffset":2,' \
14+
'"volumes":[99,10,10,10,800],"partCode":["t","p","p","p","t"],"cond":"IIIIT","type":"TradeTick",' \
15+
'"times":[1656062084833,11,0,0,31],"quoteLevel":"usStockQuote","priceBase":28770,"sn":878,' \
16+
'"prices":[6,3,2,2,0],"timestamp":1656062085570}'
17+
18+
expected = 'QQQ', [{'tick_type': '*', 'price': 287.76, 'volume': 99, 'part_code': 'NSDQ',
19+
'part_code_name': 'NASDAQ Stock Market, LLC (NASDAQ)', 'cond': 'US_ODD_LOT_TRADE',
20+
'time': 1656062084833, 'server_timestamp': 1656062042242, 'type': 'TradeTick',
21+
'quote_level': 'usStockQuote', 'sn': 878, 'timestamp': 1656062085570},
22+
{'tick_type': '*', 'price': 287.73, 'volume': 10, 'part_code': 'ARCA',
23+
'part_code_name': 'NYSE Arca, Inc. (NYSE Arca)', 'cond': 'US_ODD_LOT_TRADE',
24+
'time': 1656062084844, 'server_timestamp': 1656062042242, 'type': 'TradeTick',
25+
'quote_level': 'usStockQuote', 'sn': 878, 'timestamp': 1656062085570},
26+
{'tick_type': '*', 'price': 287.72, 'volume': 10, 'part_code': 'ARCA',
27+
'part_code_name': 'NYSE Arca, Inc. (NYSE Arca)', 'cond': 'US_ODD_LOT_TRADE',
28+
'time': 1656062084844, 'server_timestamp': 1656062042242, 'type': 'TradeTick',
29+
'quote_level': 'usStockQuote', 'sn': 878, 'timestamp': 1656062085570},
30+
{'tick_type': '*', 'price': 287.72, 'volume': 10, 'part_code': 'ARCA',
31+
'part_code_name': 'NYSE Arca, Inc. (NYSE Arca)', 'cond': 'US_ODD_LOT_TRADE',
32+
'time': 1656062084844, 'server_timestamp': 1656062042242, 'type': 'TradeTick',
33+
'quote_level': 'usStockQuote', 'sn': 878, 'timestamp': 1656062085570},
34+
{'tick_type': '*', 'price': 287.7, 'volume': 800, 'part_code': 'NSDQ',
35+
'part_code_name': 'NASDAQ Stock Market, LLC (NASDAQ)', 'cond': 'US_FORM_T',
36+
'time': 1656062084875, 'server_timestamp': 1656062042242, 'type': 'TradeTick',
37+
'quote_level': 'usStockQuote', 'sn': 878, 'timestamp': 1656062085570}]
38+
self.assertEqual(expected, PushClient._convert_tick(body))
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/6/23
4+
# @Author : sukai
5+
6+
HK_QUOTE_LEVEL_PREFIX = "hk"
7+
US_QUOTE_LEVEL_PREFIX = "us"
8+
9+
PART_CODE_NAME_MAP = {
10+
"a": "NYSE American, LLC (NYSE American)",
11+
"b": "NASDAQ OMX BX, Inc. (NASDAQ OMX BX)",
12+
"c": "NYSE National, Inc. (NYSE National)",
13+
"d": "FINRA Alternative Display Facility (ADF)",
14+
"h": "MIAX Pearl Exchange, LLC (MIAX)",
15+
"i": "International Securities Exchange, LLC (ISE)",
16+
"j": "Cboe EDGA Exchange, Inc. (Cboe EDGA)",
17+
"k": "Cboe EDGX Exchange, Inc. (Cboe EDGX)",
18+
"l": "Long-Term Stock Exchange, Inc. (LTSE)",
19+
"m": "NYSE Chicago, Inc. (NYSE Chicago)",
20+
"n": "New York Stock Exchange, LLC (NYSE)",
21+
"p": "NYSE Arca, Inc. (NYSE Arca)",
22+
"s": "Consolidated Tape System (CTS)",
23+
"t": "NASDAQ Stock Market, LLC (NASDAQ)",
24+
"u": "Members Exchange, LLC (MEMX)",
25+
"v": "Investors’ Exchange, LLC. (IEX)",
26+
"w": "CBOE Stock Exchange, Inc. (CBSX)",
27+
"x": "NASDAQ OMX PSX, Inc. (NASDAQ OMX PSX)",
28+
"y": "Cboe BYX Exchange, Inc. (Cboe BYX)",
29+
"z": "Cboe BZX Exchange, Inc. (Cboe BZX)",
30+
}
31+
32+
PART_CODE_MAP = {
33+
"a": "AMEX",
34+
"b": "BX",
35+
"c": "NSX",
36+
"d": "ADF",
37+
"h": "MIAX",
38+
"i": "ISE",
39+
"j": "EDGA",
40+
"k": "EDGX",
41+
"l": "LTSE",
42+
"m": "CHO",
43+
"n": "NYSE",
44+
"p": "ARCA",
45+
"s": "CTS",
46+
"t": "NSDQ",
47+
"u": "MEMX",
48+
"v": "IEX",
49+
"w": "CBSX",
50+
"x": "PSX",
51+
"y": "BYX",
52+
"z": "BZX",
53+
}
54+
55+
US_TRADE_COND_MAP = {
56+
" ": "US_REGULAR_SALE", # 自动对盘
57+
"B": "US_BUNCHED_TRADE", # 批量交易
58+
"C": "US_CASH_TRADE", # 现金交易
59+
"F": "US_INTERMARKET_SWEEP", # 跨市场交易
60+
"G": "US_BUNCHED_SOLD_TRADE", # 批量卖出
61+
"H": "US_PRICE_VARIATION_TRADE", # 离价交易
62+
"I": "US_ODD_LOT_TRADE", # 碎股交易
63+
"K": "US_RULE_127_OR_155_TRADE", # 纽交所 第127条交易 或 第155条交易
64+
"L": "US_SOLD_LAST", # 延迟交易
65+
"M": "US_MARKET_CENTER_CLOSE_PRICE", # 中央收市价
66+
"N": "US_NEXT_DAY_TRADE", # 隔日交易
67+
"O": "US_MARKET_CENTER_OPENING_TRADE", # 中央开盘价交易
68+
"P": "US_PRIOR_REFERENCE_PRICE", # 前参考价
69+
"Q": "US_MARKET_CENTER_OPEN_PRICE", # 中央开盘价
70+
"R": "US_SELLER", # 卖方
71+
"T": "US_FORM_T", # 盘前盘后交易
72+
"U": "US_EXTENDED_TRADING_HOURS", # 延长交易时段
73+
"V": "US_CONTINGENT_TRADE", # 合单交易
74+
"W": "US_AVERAGE_PRICE_TRADE", # 均价交易
75+
"X": "US_CROSS_TRADE", #
76+
"Z": "US_SOLD_OUT_OF_SEQUENCE", # 场外售出
77+
"0": "US_ODD_LOST_CROSS_TRADE", # 碎股跨市场交易
78+
"4": "US_DERIVATIVELY_PRICED", # 衍生工具定价
79+
"5": "US_MARKET_CENTER_RE_OPENING_TRADE", # 再开盘定价
80+
"6": "US_MARKET_CENTER_CLOSING_TRADE", # 收盘定价
81+
"7": "US_QUALIFIED_CONTINGENT_TRADE", # 合单交易
82+
"9": "US_CONSOLIDATED_LAST_PRICE_PER_LISTING_PACKET", # 综合延迟价格
83+
}
84+
85+
HK_TRADE_COND_MAP = {
86+
" ": "HK_AUTOMATCH_NORMAL", # 自动对盘
87+
"D": "HK_ODD_LOT_TRADE", # 碎股交易
88+
"U": "HK_AUCTION_TRADE", # 竞价交易
89+
"*": "HK_OVERSEAS_TRADE", # 场外交易
90+
"P": "HK_LATE_TRADE_OFF_EXCHG", # 开市前成交
91+
"M": "HK_NON_DIRECT_OFF_EXCHG_TRADE", # 非自动对盘
92+
"X": "HK_DIRECT_OFF_EXCHG_TRADE", # 同券商自动对盘
93+
"Y": "HK_AUTOMATIC_INTERNALIZED", # 同券商非自动对盘
94+
}

tigeropen/common/util/tick_util.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/6/24
4+
# @Author : sukai
5+
6+
from tigeropen.common.consts.tick_constants import PART_CODE_MAP, PART_CODE_NAME_MAP, HK_QUOTE_LEVEL_PREFIX, \
7+
HK_TRADE_COND_MAP, US_TRADE_COND_MAP
8+
9+
10+
def get_part_code(code):
11+
return PART_CODE_MAP.get(code)
12+
13+
14+
def get_part_code_name(code):
15+
return PART_CODE_NAME_MAP.get(code)
16+
17+
18+
def get_trade_condition_map(quote_level):
19+
if quote_level.lower().startswith(HK_QUOTE_LEVEL_PREFIX):
20+
return HK_TRADE_COND_MAP
21+
return US_TRADE_COND_MAP
22+
23+
24+
def get_trade_condition(cond, cond_map):
25+
return cond_map.get(cond)
26+
27+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2021-04-16
4+
# @Author : sukai
5+
from tigeropen.common.response import TigerResponse
6+
from tigeropen.common.util import string_utils
7+
8+
9+
class TradingCalendarResponse(TigerResponse):
10+
def __init__(self):
11+
super(TradingCalendarResponse, self).__init__()
12+
self.calendar = None
13+
self._is_success = None
14+
15+
def parse_response_content(self, response_content):
16+
response = super(TradingCalendarResponse, self).parse_response_content(response_content)
17+
if 'is_success' in response:
18+
self._is_success = response['is_success']
19+
20+
if self.data:
21+
self.calendar = string_utils.camel_to_underline_obj(self.data)

0 commit comments

Comments
 (0)