Skip to content

Commit 9471275

Browse files
author
Kai Su
committed
modified: tigeropen/common/consts/service_types.py
modified: tigeropen/examples/quote_client_demo.py modified: tigeropen/quote/quote_client.py modified: tigeropen/quote/request/model.py deleted: tigeropen/quote/response/quote_depth_entry_response.py new file: tigeropen/quote/response/quote_order_book_response.py
1 parent f3d78c2 commit 9471275

File tree

6 files changed

+74
-64
lines changed

6 files changed

+74
-64
lines changed

tigeropen/common/consts/service_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
QUOTE_REAL_TIME = "quote_real_time"
4343
QUOTE_SHORTABLE_STOCKS = "quote_shortable_stocks"
4444
QUOTE_STOCK_TRADE = "quote_stock_trade"
45-
DEPTH_ENTRY = "ask_bid" # level2 深度行情
45+
ORDER_BOOK = "ask_bid" # level2 深度行情
4646

4747
# 期权行情
4848
OPTION_EXPIRATION = "option_expiration"

tigeropen/examples/quote_client_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def get_quote():
4040
short_interest = openapi_client.get_short_interest(['GOOG', 'AAPL', '00700'])
4141
print(short_interest)
4242
# 获取深度行情
43-
depth_entry = openapi_client.get_depth_entry(['02828'])
44-
print(depth_entry)
43+
order_book = openapi_client.get_order_book(['02828'])
44+
print(order_book)
4545

4646

4747
def get_option_quote():

tigeropen/quote/quote_client.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
from tigeropen.quote.response.stock_trade_meta_response import TradeMetaResponse
3636
from tigeropen.quote.response.symbol_names_response import SymbolNamesResponse
3737
from tigeropen.quote.response.symbols_response import SymbolsResponse
38-
from tigeropen.quote.response.quote_depth_entry_response import DepthEntryResponse
38+
from tigeropen.quote.response.quote_order_book_response import OrderBookResponse
3939
from tigeropen.tiger_open_client import TigerOpenClient
4040
from tigeropen.quote.request.model import MarketParams, MultipleQuoteParams, MultipleContractParams, \
4141
FutureQuoteParams, FutureExchangeParams, FutureTypeParams, FutureTradingTimeParams, SingleContractParams, \
42-
SingleOptionQuoteParams, DepthEntryParams
42+
SingleOptionQuoteParams, OrderBookParams
4343
from tigeropen.quote.request import OpenApiRequest
4444
from tigeropen.quote.response.quote_ticks_response import TradeTickResponse
4545
from tigeropen.quote.response.market_status_response import MarketStatusResponse
@@ -48,7 +48,7 @@
4848
OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \
4949
FUTURE_TRADING_DATE, QUOTE_SHORTABLE_STOCKS, FUTURE_REAL_TIME_QUOTE, \
5050
FUTURE_CURRENT_CONTRACT, QUOTE_REAL_TIME, QUOTE_STOCK_TRADE, FINANCIAL_DAILY, FINANCIAL_REPORT, CORPORATE_ACTION, \
51-
DEPTH_ENTRY
51+
ORDER_BOOK
5252
from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod
5353
from tigeropen.common.util.contract_utils import extract_option_info
5454
from tigeropen.common.util.common_utils import eastern
@@ -375,22 +375,51 @@ def get_short_interest(self, symbols, lang=None):
375375

376376
return None
377377

378-
def get_depth_entry(self, symbols):
378+
def get_order_book(self, symbols):
379379
"""
380380
获取深度行情
381381
:param symbols:
382382
:return:
383-
"""
384-
params = DepthEntryParams()
383+
数据结构:
384+
若返回单个 symbol:
385+
{'symbol': '02833',
386+
'asks': [(27.4, 300, 2), (27.45, 500, 1), (27.5, 4400, 1), (27.55, 0, 0), (27.6, 5700, 3), (27.65, 0, 0),
387+
(27.7, 500, 1), (27.75, 0, 0), (27.8, 0, 0), (27.85, 0, 0)],
388+
'bids': [(27, 4000, 3), (26.95, 200, 1), (26.9, 0, 0), (26.85, 400, 1), (26.8, 0, 0), (26.75, 0, 0),
389+
(26.7, 0, 0), (26.65, 0, 0), (26.6, 0, 0), (26.55, 0, 0)]
390+
}
391+
392+
若返回多个 symbol:
393+
{'02833':
394+
{'symbol': '02833',
395+
'asks': [(27.35, 200, 1), (27.4, 2100, 2), (27.45, 500, 1), (27.5, 4400, 1), (27.55, 0, 0),
396+
(27.6, 5700, 3), (27.65, 0, 0), (27.7, 500, 1), (27.75, 0, 0), (27.8, 0, 0)],
397+
'bids': [(27.05, 100, 1), (27, 5000, 4), (26.95, 200, 1), (26.9, 0, 0), (26.85, 400, 1), (26.8, 0, 0),
398+
(26.75, 0, 0), (26.7, 0, 0), (26.65, 0, 0), (26.6, 0, 0)]
399+
},
400+
'02828':
401+
{'symbol': '02828',
402+
'asks': [(106.6, 6800, 7), (106.7, 110200, 10), (106.8, 64400, 8), (106.9, 80600, 8), (107, 9440, 16),
403+
(107.1, 31800, 5), (107.2, 11800, 4), (107.3, 9800, 2), (107.4, 9400, 1), (107.5, 21000, 9)],
404+
'bids': [(106.5, 62800, 17), (106.4, 68200, 9), (106.3, 78400, 6), (106.2, 52400, 4), (106.1, 3060, 4),
405+
(106, 33400, 4), (105.9, 29600, 3), (105.8, 9600, 2), (105.7, 15200, 2), (105.6, 0, 0)]}
406+
}
407+
408+
asks 和 bids 列表项数据含义为:
409+
[(ask_price1, ask_volume1, order_count), (ask_price2, ask_volume2, order_count), ...]
410+
[(bid_price1, bid_volume2, order_count), (bid_price2, bid_volume2, order_count), ...]
411+
412+
"""
413+
params = OrderBookParams()
385414
params.symbols = symbols if isinstance(symbols, list) else [symbols]
386415

387-
request = OpenApiRequest(DEPTH_ENTRY, biz_model=params)
416+
request = OpenApiRequest(ORDER_BOOK, biz_model=params)
388417
response_content = self.__fetch_data(request)
389418
if response_content:
390-
response = DepthEntryResponse()
419+
response = OrderBookResponse()
391420
response.parse_response_content(response_content)
392421
if response.is_success():
393-
return response.depth_entry
422+
return response.order_book
394423
else:
395424
raise ApiException(response.code, response.message)
396425

tigeropen/quote/request/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def to_openapi_dict(self):
650650
return params
651651

652652

653-
class DepthEntryParams(object):
653+
class OrderBookParams(object):
654654
def __init__(self):
655655
self._symbols = None
656656

tigeropen/quote/response/quote_depth_entry_response.py

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
from tigeropen.common.response import TigerResponse
3+
from tigeropen.common.util.string_utils import get_string
4+
5+
6+
class OrderBookResponse(TigerResponse):
7+
def __init__(self):
8+
super(OrderBookResponse, self).__init__()
9+
self.order_book = dict()
10+
self._is_success = None
11+
12+
def parse_response_content(self, response_content):
13+
response = super(OrderBookResponse, self).parse_response_content(response_content)
14+
if 'is_success' in response:
15+
self._is_success = response['is_success']
16+
17+
if self.data and isinstance(self.data, list):
18+
if len(self.data) == 1:
19+
for item in self.data:
20+
symbol = get_string(item.get('symbol'))
21+
asks = [(v['price'], v['volume'], v['count']) for v in item.get('asks', [])]
22+
bids = [(v['price'], v['volume'], v['count']) for v in item.get('bids', [])]
23+
self.order_book = {'symbol': symbol, 'asks': asks, 'bids': bids}
24+
else:
25+
for item in self.data:
26+
symbol = get_string(item.get('symbol'))
27+
asks = [(v['price'], v['volume'], v['count']) for v in item.get('asks', [])]
28+
bids = [(v['price'], v['volume'], v['count']) for v in item.get('bids', [])]
29+
self.order_book[symbol] = {'symbol': symbol, 'asks': asks, 'bids': bids}
30+
return self.order_book
31+
32+

0 commit comments

Comments
 (0)