|
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 |
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 |
@@ -508,35 +509,40 @@ def get_option_expirations(self, symbols): |
508 | 509 |
|
509 | 510 | return None |
510 | 511 |
|
511 | | - def get_option_chain(self, symbol, expiry): |
512 | | - """ |
513 | | - 获取美股期权链 |
514 | | - :param symbol: 股票代码 |
515 | | - :param expiry: 过期日 ( 类似 '2021-06-18' 或者 1560484800000 ) |
516 | | - :return: pandas.DataFrame,各 column 含义如下: |
517 | | - identifier: 期权代码 |
518 | | - symbol: 期权对应的正股代码 |
519 | | - expiry: 期权到期日,毫秒级别的时间戳 |
520 | | - strike: 行权价 |
521 | | - put_call: 期权的方向 |
522 | | - multiplier: 乘数 |
523 | | - ask_price: 卖价 |
524 | | - ask_size: 卖量 |
525 | | - bid_price: 买价 |
526 | | - bid_size: 买量 |
527 | | - pre_close: 前收价 |
528 | | - latest_price: 最新价 |
529 | | - volume: 成交量 |
530 | | - open_interest: 未平仓数量 |
531 | | - """ |
532 | | - params = MultipleContractParams() |
| 512 | + def get_option_chain(self, symbol, expiry, option_filter=None, **kwargs): |
| 513 | + """ |
| 514 | + query option chain with filter |
| 515 | + :param symbol: underlying stock symbol |
| 516 | + :param expiry: expiration date ( like '2021-06-18' or 1560484800000 ) |
| 517 | + :param option_filter: option filter conditions, tigeropen.quote.domain.filter.OptionFilter |
| 518 | + :param kwargs: optional. specify option_filter parameters directly without option_filer, |
| 519 | + like: open_interest_min=100, delta_min=0.1 |
| 520 | + :return: pandas.DataFrame,the columns are as follows: |
| 521 | + identifier: option identifier |
| 522 | + symbol: underlying stock symbol |
| 523 | + expiry: option expiration date. timestamp in millisecond, like 1560484800000 |
| 524 | + strike: strike price |
| 525 | + put_call: option direction. 'CALL' or 'PUT' |
| 526 | + multiplier: option multiplier |
| 527 | + ask_price: |
| 528 | + ask_size: |
| 529 | + bid_price: |
| 530 | + bid_size: |
| 531 | + pre_close: |
| 532 | + latest_price: |
| 533 | + volume: |
| 534 | + open_interest: |
| 535 | + """ |
| 536 | + params = OptionChainParams() |
533 | 537 | param = SingleContractParams() |
534 | 538 | param.symbol = symbol |
535 | 539 | if isinstance(expiry, str) and re.match('[0-9]{4}-[0-9]{2}-[0-9]{2}', expiry): |
536 | 540 | param.expiry = int(delorean.parse(expiry, timezone=eastern, dayfirst=False).datetime.timestamp() * 1000) |
537 | 541 | else: |
538 | 542 | param.expiry = expiry |
539 | 543 | params.contracts = [param] |
| 544 | + params.option_filter = option_filter if option_filter else OptionFilter(**kwargs) |
| 545 | + params.version = OPEN_API_SERVICE_VERSION_V3 |
540 | 546 | request = OpenApiRequest(OPTION_CHAIN, biz_model=params) |
541 | 547 | response_content = self.__fetch_data(request) |
542 | 548 | if response_content: |
|
0 commit comments