|
35 | 35 | from tigeropen.quote.response.stock_trade_meta_response import TradeMetaResponse |
36 | 36 | from tigeropen.quote.response.symbol_names_response import SymbolNamesResponse |
37 | 37 | from tigeropen.quote.response.symbols_response import SymbolsResponse |
| 38 | +from tigeropen.quote.response.quote_order_book_response import OrderBookResponse |
38 | 39 | from tigeropen.tiger_open_client import TigerOpenClient |
39 | 40 | from tigeropen.quote.request.model import MarketParams, MultipleQuoteParams, MultipleContractParams, \ |
40 | 41 | FutureQuoteParams, FutureExchangeParams, FutureTypeParams, FutureTradingTimeParams, SingleContractParams, \ |
41 | | - SingleOptionQuoteParams |
| 42 | + SingleOptionQuoteParams, OrderBookParams |
42 | 43 | from tigeropen.quote.request import OpenApiRequest |
43 | 44 | from tigeropen.quote.response.quote_ticks_response import TradeTickResponse |
44 | 45 | from tigeropen.quote.response.market_status_response import MarketStatusResponse |
45 | 46 | from tigeropen.common.consts.service_types import MARKET_STATE, ALL_SYMBOLS, ALL_SYMBOL_NAMES, BRIEF, \ |
46 | 47 | TIMELINE, KLINE, TRADE_TICK, OPTION_EXPIRATION, OPTION_CHAIN, FUTURE_EXCHANGE, OPTION_BRIEF, \ |
47 | 48 | OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \ |
48 | 49 | FUTURE_TRADING_DATE, QUOTE_SHORTABLE_STOCKS, FUTURE_REAL_TIME_QUOTE, \ |
49 | | - FUTURE_CURRENT_CONTRACT, QUOTE_REAL_TIME, QUOTE_STOCK_TRADE, FINANCIAL_DAILY, FINANCIAL_REPORT, CORPORATE_ACTION |
| 50 | + FUTURE_CURRENT_CONTRACT, QUOTE_REAL_TIME, QUOTE_STOCK_TRADE, FINANCIAL_DAILY, FINANCIAL_REPORT, CORPORATE_ACTION, \ |
| 51 | + ORDER_BOOK |
50 | 52 | from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod |
51 | 53 | from tigeropen.common.util.contract_utils import extract_option_info |
52 | 54 | from tigeropen.common.util.common_utils import eastern |
@@ -373,6 +375,54 @@ def get_short_interest(self, symbols, lang=None): |
373 | 375 |
|
374 | 376 | return None |
375 | 377 |
|
| 378 | + def get_order_book(self, symbols): |
| 379 | + """ |
| 380 | + 获取深度行情 |
| 381 | + :param symbols: |
| 382 | + :return: |
| 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() |
| 414 | + params.symbols = symbols if isinstance(symbols, list) else [symbols] |
| 415 | + |
| 416 | + request = OpenApiRequest(ORDER_BOOK, biz_model=params) |
| 417 | + response_content = self.__fetch_data(request) |
| 418 | + if response_content: |
| 419 | + response = OrderBookResponse() |
| 420 | + response.parse_response_content(response_content) |
| 421 | + if response.is_success(): |
| 422 | + return response.order_book |
| 423 | + else: |
| 424 | + raise ApiException(response.code, response.message) |
| 425 | + |
376 | 426 | def get_option_expirations(self, symbols): |
377 | 427 | """ |
378 | 428 | 返回美股期权的过期日 |
|
0 commit comments