|
10 | 10 |
|
11 | 11 | import delorean |
12 | 12 |
|
13 | | -from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod |
| 13 | +from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod, OPEN_API_SERVICE_VERSION_V3 |
14 | 14 | from tigeropen.common.consts import THREAD_LOCAL, SecurityType, CorporateActionType, IndustryLevel |
15 | 15 | from tigeropen.common.consts.service_types import GRAB_QUOTE_PERMISSION, QUOTE_DELAY |
16 | 16 | from tigeropen.common.consts.service_types import MARKET_STATE, ALL_SYMBOLS, ALL_SYMBOL_NAMES, BRIEF, \ |
|
31 | 31 | from tigeropen.fundamental.response.financial_report_response import FinancialReportResponse |
32 | 32 | from tigeropen.fundamental.response.industry_response import IndustryListResponse, IndustryStocksResponse, \ |
33 | 33 | StockIndustryResponse |
| 34 | +from tigeropen.quote.domain.filter import OptionFilter |
34 | 35 | from tigeropen.quote.request import OpenApiRequest |
35 | 36 | from tigeropen.quote.request.model import MarketParams, MultipleQuoteParams, MultipleContractParams, \ |
36 | 37 | FutureQuoteParams, FutureExchangeParams, FutureTypeParams, FutureTradingTimeParams, SingleContractParams, \ |
37 | | - SingleOptionQuoteParams, DepthQuoteParams |
| 38 | + SingleOptionQuoteParams, DepthQuoteParams, OptionChainParams |
38 | 39 | from tigeropen.quote.response.future_briefs_response import FutureBriefsResponse |
39 | 40 | from tigeropen.quote.response.future_contract_response import FutureContractResponse |
40 | 41 | from tigeropen.quote.response.future_exchange_response import FutureExchangeResponse |
@@ -539,35 +540,40 @@ def get_option_expirations(self, symbols): |
539 | 540 |
|
540 | 541 | return None |
541 | 542 |
|
542 | | - def get_option_chain(self, symbol, expiry): |
543 | | - """ |
544 | | - 获取美股期权链 |
545 | | - :param symbol: 股票代码 |
546 | | - :param expiry: 过期日 ( 类似 '2021-06-18' 或者 1560484800000 ) |
547 | | - :return: pandas.DataFrame,各 column 含义如下: |
548 | | - identifier: 期权代码 |
549 | | - symbol: 期权对应的正股代码 |
550 | | - expiry: 期权到期日,毫秒级别的时间戳 |
551 | | - strike: 行权价 |
552 | | - put_call: 期权的方向 |
553 | | - multiplier: 乘数 |
554 | | - ask_price: 卖价 |
555 | | - ask_size: 卖量 |
556 | | - bid_price: 买价 |
557 | | - bid_size: 买量 |
558 | | - pre_close: 前收价 |
559 | | - latest_price: 最新价 |
560 | | - volume: 成交量 |
561 | | - open_interest: 未平仓数量 |
562 | | - """ |
563 | | - params = MultipleContractParams() |
| 543 | + def get_option_chain(self, symbol, expiry, option_filter=None, **kwargs): |
| 544 | + """ |
| 545 | + query option chain with filter |
| 546 | + :param symbol: underlying stock symbol |
| 547 | + :param expiry: expiration date ( like '2021-06-18' or 1560484800000 ) |
| 548 | + :param option_filter: option filter conditions, tigeropen.quote.domain.filter.OptionFilter |
| 549 | + :param kwargs: optional. specify option_filter parameters directly without option_filer, |
| 550 | + like: open_interest_min=100, delta_min=0.1 |
| 551 | + :return: pandas.DataFrame,the columns are as follows: |
| 552 | + identifier: option identifier |
| 553 | + symbol: underlying stock symbol |
| 554 | + expiry: option expiration date. timestamp in millisecond, like 1560484800000 |
| 555 | + strike: strike price |
| 556 | + put_call: option direction. 'CALL' or 'PUT' |
| 557 | + multiplier: option multiplier |
| 558 | + ask_price: |
| 559 | + ask_size: |
| 560 | + bid_price: |
| 561 | + bid_size: |
| 562 | + pre_close: |
| 563 | + latest_price: |
| 564 | + volume: |
| 565 | + open_interest: |
| 566 | + """ |
| 567 | + params = OptionChainParams() |
564 | 568 | param = SingleContractParams() |
565 | 569 | param.symbol = symbol |
566 | 570 | if isinstance(expiry, str) and re.match('[0-9]{4}-[0-9]{2}-[0-9]{2}', expiry): |
567 | 571 | param.expiry = int(delorean.parse(expiry, timezone=eastern, dayfirst=False).datetime.timestamp() * 1000) |
568 | 572 | else: |
569 | 573 | param.expiry = expiry |
570 | 574 | params.contracts = [param] |
| 575 | + params.option_filter = option_filter if option_filter else OptionFilter(**kwargs) |
| 576 | + params.version = OPEN_API_SERVICE_VERSION_V3 |
571 | 577 | request = OpenApiRequest(OPTION_CHAIN, biz_model=params) |
572 | 578 | response_content = self.__fetch_data(request) |
573 | 579 | if response_content: |
|
0 commit comments