Options Chain

Learn to get the options chain using YH Finance API.

An options chain is a contract that allows the traders to buy or sell securities at a preset price within a specified interval of time. Options chains are of the following two types:

  • Put options: Contracts that allow the traders to sell a security at a preset price within a specified interval of time.
  • Call options: Contracts that allow the traders to buy a security at a preset price.

Endpoint for options chains

The endpoint https://yfapi.net/v7/finance/options/{symbol} is used to get a list of options chain for a particular security. The {symbol} parameter at the end of the endpoint will be replaced with the symbol of the security we want to search for when making an API call. For example, if we want to look at the options chain for Apple Inc., our endpoint will be https://yfapi.net/v7/finance/options/AAPL.

Request parameters

This endpoint has only one query parameter, which is as follows:

Parameters

Category

Type

Description

date

optional

number

This is the timestamp for which you want the data.

The code below shows how we can get the options chain for a particular symbol. Click "Run" to get the options chain for Apple Inc.

Press + to interact
const endpointUrl = new URL('https://yfapi.net/v7/finance/options/AAPL');
//AAPL is the symbol for Apple Inc.
const queryParameters = new URLSearchParams({
date: Date.now()
});
const headerParameters = {
'X-API-KEY': '{{API_KEY}}'
}
const options = {
method: 'GET',
headers: headerParameters
};
async function fetchOptionsChain() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
fetchOptionsChain();

Let's look at the code in the widget above:

  • Line 1: We set the URL to https://yfapi.net/v7/finance/options/AAPL.

  • Lines 4–6: We define the query parameters. We generate the timestamp for the current time and save it in the variable date.

  • Lines 17–25: We define a function fetchOptionsChain() that calls the API and prints the response.

We can search for the option chain of other securities by replacing AAPL in line 1 with the symbol of the security we want to search for.

Note: The table in the Appendix contains some symbols that we can use to test this endpoint.

Response fields

The response will contain the list of available strikes, their expiration dates, real-time quotes of the stock, and the available put and call options. Some important response fields are as follows:

Response fields

Description

expirationDates

This is a list of expiration dates of the options chain whose strikes options are given in another array. These represent the time intervals after which the options cannot be used.

strikes

This is a list that contains strikes for all the available options chains. These represent the price at which the options are available.

quote

This contains the information of a delayed quote for the security.

options

This list contains the details for all the available options chains.

puts

This list contains information about all the available put options.

calls

This list contains information about all the available call options.

Note: The response also contains other important information. This information can vary depending on the security we search for.