Market Data Logo
api
Last Update: February 20, 2024

How To Use The Option Chain API — With Examples!

The Option Chain API allows for ample sorting & filtering during each request, making it easy to get exactly the data you need.

Market Data’s Option Chain API allows you to get real-time option chains for equities or indices. The query can be as simple or complex as you need and it is possible to sort and filter your request so that only contracts that meet your criteria are returned. You can even backtest your strategies by looking up historical option chains going back to 2005.

Our Option Chain API allows you to experiment with the AAPL ticker without registration (no API key needed). So, just click on each of the examples below to see the output in a new tab. If you find the API useful, you can register an account and get a free API key that will work for 100 requests daily so you can download option chains for other tickers.

Endpoint: https://api.marketdata.app/v1/options/chain/{ticker}

Throughout this example, we’ll add the dateformat=timestamp parameter to each link so that you can click the examples and read the dates & times in human-readable format. However, the default date/time output of the API is unix format. Omit the dateformat=timestamp parameter and you can see the output in seconds after the Unix epoch.

How To Get A Live Option Chain from the API

To get a live option chain, use the endpoint without any optional parameters. So, to get a real-time quote for AAPL, just add the ticker to the endpoint.

Example: https://api.marketdata.app/v1/options/chain/AAPL

The option chain will output the option symbol, the underlying symbol, the expiration date, the strike, whether the option is a call or a put, and when the contract was first traded. Once you obtain the option symbols in the chain, you can then send a query to the quotes API endpoint to get a quote, greeks, and other data for the contracts you need.

How To Get A Historical Option Chain from the API

To get a historical option chain, add the parameter date to the query and the date in YYYY-MM-DD format. So, if you needed the quote for January 6, 2020 the query would be date=2020-01-06.

Option chains go back to 2005 and data is not adjusted for splits, dividends, or any other corporate actions. All data is as-traded on the date you query. So if you are backtesting options strategies on stocks that have split, make sure to keep this in mind.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?date=2020-01-06

Filter The Option Chain API

Sometimes you may only be interested in a specific strike, expiration, side, or moneyness. The Option Chain API includes a number of filters that let you search the chain and return only the contracts you are looking for. Best yet, multiple filters can be stacked and used together to further restrict the result, narrowing in on specific contracts that match your needs.

Filter the Option Chain API for Strike

Often times you may be looking for a specific strike and you don’t need all the data in the chain. Instead of downloading the entire chain and filtering locally, you can query the API with a filter for strike and the API will remove contracts that don’t match your strike. For example, if you needed the option chain with the $150 strike, you could filter using strike=150 and the API will filter out the other strikes.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?strike=150

Filter the Option Chain API by Side

If you only need calls or puts, you can omit the side you don’t need by filtering by side. Just use the side parameter and request the side you need.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?side=call

Filter the Option Chain API by Moneyness

Sometimes you only want in the money or out of the money options. There’s a filter for that. Combine the range parameter with itm or otm to filter out the options you don’t want. If you just wanted in the money options for AAPL, you could use range=itm.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?range=itm

Filter the Option Chain API by Expiration Date

There are numerous ways to filter the option chain for expirations. You can filter for a single expiration, a range of expirations, or use days to expiry to most closely match a date in the future, relative to the current date.

Filter the Option Chain API For a Single Expiration Date

Filter for expiration by using the expiration parameter and the expiration date you need. For example, expiration=2024-01-19 will return just the options expiring January of 2024.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?expiration=2024-01-19

Filter the Option Chain API For Expirations Between Two Dates

Let’s say you wanted to get all options expiring in the first half of 2024. You could use the from=2024-01-01 and to=2024-06-30 parameters to filter out all options that don’t fall between those dates

Example: https://api.marketdata.app/v1/options/chain/AAPL/?from=2024-01-01&to=2024-06-30.

Filter the Option Chain API For Expirations From A Specific Year or Month

Use the month and year parameter to filter the chain for options that expire in a specific month or year. For example, if you use month=1 you will get all the LEAP options for AAPL that expire in January. And if you use year=2022 only options from 2022 will be returned, filtering out those long-term LEAP options.

Examples: https://api.marketdata.app/v1/options/chain/AAPL/?month=1
Examples: https://api.marketdata.app/v1/options/chain/AAPL/?year=2022

Filter the Option Chain API Using A Days To Expiration (DTE) Target

Sometimes it is useful to target an expiration a fixed number of days in the future. You can use the dte parameter to accomplish this. For example, if you wanted to get the expirations for AAPL 45 days in the future, you could use dte=45. If there is no exact match, the dte parameter will provide the expiration that most closely matches the number of days you provide.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?dte=45

Filter In or Out Monthly, Quarterly, or Weekly Options As Needed

You may not want to trade quarterly options. Or perhaps you only want to trade monthly expirations. You can use the weekly, monthly or quarterly parameters along with true or false to filter these options in or out. If you use true, you will only return those options, excluding all others. If you use false, you will omit them from your results.

For example, if you wanted to exclude monthly options and get weeklies and quarterlies, set monthly=false. You could get monthly options only and exclude both weeklies and quarterlies by using monthly=true.

Examples: https://api.marketdata.app/v1/options/chain/AAPL/?monthly=false
Examples: https://api.marketdata.app/v1/options/chain/AAPL/?monthly=true

Filter the Option Chain API By Liquidity

If you are only analyzing liquid options, it can be helpful to exclude non-liquid contracts from the chain. The API makes this easy using several liquidity filters, allowing each trader to filter options according to his or her own liquidity preferences.

Filter by Minimum Open Interest

Remove options with a low open interest using the minOpenInterest parameter. For example, if we only wanted AAPL options with an open interest of 1000 or more, we would set minOpenInterest=1000 and the query will remove options that don’t have many open contracts outstanding.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?minOpenInterest=1000

Filter by Minimum Volume

Remove options that are not actively traded by setting a minVolume filter. For example, filter out AAPL options with less than 100 trades by using minVolume=100.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?minVolume=100

Filter by Maximum Bid/Ask Spread

Sometimes it is helpful to remove options that have large bid/ask spreads due to the impossibility of closing the contracts at a profit. Use the maxBidAskSpread parameter to filter out options that don’t offer enough liquidity. In this example, we’ll filter out AAPL contracts that have a spread larger than $0.10 by using maxBidAskSpread=0.10

Example: https://api.marketdata.app/v1/options/chain/AAPL/?maxBidAskSpread=0.10

Filter by Maximum Bid/Ask Spread, Relative to the Underlying

Sometimes it can be helpful to filter out contracts based on the price of the underlying. A $250 stock with a $0.25 bid/ask spread may be acceptable while a $2.5 stock with a $0.25 bid/ask spread could be excessive. By pegging the bid/ask spread relative to the underlying using maxBidAskSpreadPct, a more accurate picture of liquidity can be obtained.

In our example, we’ll use maxBidAskSpreadPct=.1 to filter out contracts of AAPL that have a bid/ask spread higher than 0.1% of the underlying.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?maxBidAskSpreadPct=.1

Stack Multiple Filters At Once To Further Refine the Option Chain API Output

Want to get all options for $150 AAPL puts for 2023? You can stack 3 filters together to do that. Set strike=150, side=put and year=2023. There is no limit to the number of filters you can stack together to filter the option chain to your exact specifications.

Example: https://api.marketdata.app/v1/options/chain/AAPL/?strike=150&side=put&year=2023

On this page
    Add a header to begin generating the table of contents
    Share this article
    Comments & Questions
    Shopping Basket
    //