# Get Option Chain

get_option_chain(code, index_option_type=IndexOptionType.NORMAL, start=None, end=None, option_type=OptionType.ALL, option_cond_type=OptionCondType.ALL, data_filter=None)

  • Description

    Query the option chain from an underlying stock. This interface only returns the static information of the option chain. If you need to obtain dynamic information such as quotation or trading, please use the security code returned by this interface to subscribe the required security.

  • Parameters

    Parameter Type Description
    code str Code of underlying stock.
    index_option_type IndexOptionType Index option type.
    start str Start date, for expiration date.
    end str End date (including this day), for expiration date.
    option_type OptionType Option type for call/put.
    option_cond_type OptionCondType Option type for in/out of the money.
    data_filter OptionDataFilter Data filter condition.
    • The combination of start and end is as follows:

      Start type End type Description
      str str start and end are the specified dates respectively.
      None str start is 30 days before end.
      str None end is 30 days after start.
      None None start is the current date, end is 30 days later.
    • OptionDataFilter fields are as follows

      Field Type Description
      implied_volatility_min float Min value of implied volatility.
      implied_volatility_max float Max value of implied volatility.
      delta_min float Min value of Greek value Delta.
      delta_max float Max value of Greek value Delta.
      gamma_min float Min value of Greek value Gamma.
      gamma_max float Max value of Greek value Gamma.
      vega_min float Min value of Greek value Vega.
      vega_max float Max value of Greek value Vega.
      theta_min float Min value of Greek value Theta.
      theta_max float Max value of Greek value Theta.
      rho_min float Min value of Greek value Rho.
      rho_max float Max value of Greek value Rho.
      net_open_interest_min float Min value of net open contract number.
      net_open_interest_max float Max value of net open contract number.
      open_interest_min float Min value of open contract number.
      open_interest_max float Max value of open contract number.
      vol_min float Min value of Volume.
      vol_max float Max value of Volume.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, option chain data is returned.
    str If ret != RET_OK, error description is returned.
    • Option chain data format as follows:
      Field Type Description
      code str Security code.
      name str Security name.
      lot_size int Number of shares per lot, number of shares per contract for options.
      stock_type SecurityType Stock type.
      option_type OptionType Option type.
      stock_owner str Underlying stock.
      strike_time str Exercise date.
      strike_price float Strike price.
      suspension bool Whether is suspended.
      stock_id int Stock ID.
      index_option_type IndexOptionType Index option type.
  • Example

from moomoo import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret1, data1 = quote_ctx.get_option_expiration_date(code='HK.00700')

filter1 = OptionDataFilter()
filter1.delta_min = 0
filter1.delta_max = 0.1

if ret1 == RET_OK:
    expiration_date_list = data1['strike_time'].values.tolist()
    for date in expiration_date_list:
        ret2, data2 = quote_ctx.get_option_chain(code='HK.00700', start=date, end=date, data_filter=filter1)
        if ret2 == RET_OK:
            print(data2)
            print(data2['code'][0])  # Take the first stock code
            print(data2['code'].values.tolist())  # Convert to list
        else:
            print('error:', data2)
        time.sleep(3)
else:
    print('error:', data1)
quote_ctx.close()  # After using the connection, remember to close it to prevent the number of connections from running out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  • Output
                     code                 name  lot_size stock_type option_type stock_owner strike_time  strike_price  suspension  stock_id index_option_type
0     HK.TCH210429C350000   腾讯 210429 350.00100       DRVT        CALL    HK.00700  2021-04-29         350.0       False  80235167               N/A
1     HK.TCH210429P350000   腾讯 210429 350.00100       DRVT         PUT    HK.00700  2021-04-29         350.0       False  80235247               N/A
2     HK.TCH210429C360000   腾讯 210429 360.00100       DRVT        CALL    HK.00700  2021-04-29         360.0       False  80235163               N/A
3     HK.TCH210429P360000   腾讯 210429 360.00100       DRVT         PUT    HK.00700  2021-04-29         360.0       False  80235246               N/A
4     HK.TCH210429C370000   腾讯 210429 370.00100       DRVT        CALL    HK.00700  2021-04-29         370.0       False  80235165               N/A
5     HK.TCH210429P370000   腾讯 210429 370.00100       DRVT         PUT    HK.00700  2021-04-29         370.0       False  80235248               N/A
HK.TCH210429C350000
['HK.TCH210429C350000', 'HK.TCH210429P350000', 'HK.TCH210429C360000', 'HK.TCH210429P360000', 'HK.TCH210429C370000', 'HK.TCH210429P370000']
...
                   code                name  lot_size stock_type option_type stock_owner strike_time  strike_price  suspension  stock_id index_option_type
0   HK.TCH220330C490000  腾讯 220330 490.00100       DRVT        CALL    HK.00700  2022-03-30         490.0       False  80235143               N/A
1   HK.TCH220330P490000  腾讯 220330 490.00100       DRVT         PUT    HK.00700  2022-03-30         490.0       False  80235193               N/A
2   HK.TCH220330C500000  腾讯 220330 500.00100       DRVT        CALL    HK.00700  2022-03-30         500.0       False  80233887               N/A
3   HK.TCH220330P500000  腾讯 220330 500.00100       DRVT         PUT    HK.00700  2022-03-30         500.0       False  80233912               N/A
4   HK.TCH220330C510000  腾讯 220330 510.00100       DRVT        CALL    HK.00700  2022-03-30         510.0       False  80233747               N/A
5   HK.TCH220330P510000  腾讯 220330 510.00100       DRVT         PUT    HK.00700  2022-03-30         510.0       False  80233766               N/A
HK.TCH220330C490000
['HK.TCH220330C490000', 'HK.TCH220330P490000', 'HK.TCH220330C500000', 'HK.TCH220330P500000', 'HK.TCH220330C510000', 'HK.TCH220330P510000']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Interface Limitations

  • A maximum of 10 requests per 30 seconds
  • The upper limit of the incoming time span is 30 days

Tips

  • This interface does not support the query of expired option chains, please enter today or future date to the End date parameter.
  • Open interest (OI) is updated daily and the specific timing depends on the exchange.
    • For U.S. stock options, the data is updated during the PRE_MARKET session.
    • For Hong Kong stock options, the data is updated after the Regular Trading Hours.