Status and Holidays

Learn to fetch the market status and upcoming holidays.

The marketstatus endpoint

The marketstatus endpoint tells us the current status of exchanges and other financial markets. This endpoint determines which markets are open or closed at a given point.

Press + to interact
The marketstatus endpoint
The marketstatus endpoint

The base URL for this endpoint is as follows:

https://api.polygon.io/v1/marketstatus/now

Request parameters

The marketstatus endpoint doesn’t require any request parameters other than our API key.

Let’s call the marketstatus endpoint in the following code. Click “Run” to see the output.

Press + to interact
// Importing libraries here
import fetch from "node-fetch";
// Define API key here
const apiKey = '{{API_KEY}}';
// Define endpoint URL here
const endpointUrl = new URL('https://api.polygon.io/v1/marketstatus/now');
// Define Header Parameters here
const headerParameters = {
authorization: `Bearer ${apiKey}`
};
// Setting API call options
const options = {
method: 'GET',
headers: headerParameters,
};
// Function to make API call
async function MarketStatus() {
try {
const response = await fetch(endpointUrl, options);
// Custom function for printing the API response
printResponse(response);
}
catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Calling function to make API call
MarketStatus();

Here’s an explanation for the above code:

  • Line 8: We define the endpoint URL.

  • Lines 11–13: We define the API key in the header parameter.

  • Lines 16–19: We define the options parameters and set the request type as GET.

  • Lines 22–32: We define the function, MarketStatus, which calls the endpoint.

    • Lines 23–27: We call the API in a try block and print the response.

    • Lines 28–31: We define a catch block to catch all errors and exceptions and print them.

  • Line 35: We call the MarketStatus function.

Response fields

The following table gives details about attributes in the response object.

Name

Type

Description

afterHours

Boolean

This is true if the market is in post-working hours.

currencies

Object

This gives us the current status of crypto and fx.

earlyHours

Boolean

This is true if the market is in preworking hours.

exchanges

Object

This gives the current status of Nasdaq, NYSE, and otc exchanges.

market

String

This gives the status of the overall market.

serverTime

String

The current time of the server.

The market holidays endpoint

The stock markets are closed on weekends. However, other regional holidays also affect the market opening and closing times. The market holiday endpoint gives information about market holidays and opening and closing times. Additionally, it provides information on unusual opening hours. This information is important as the market often faces a phenomenon known as the holiday effect, where an increase in trading is observed a day before the holiday.

Press + to interact
The market holiday endpoint
The market holiday endpoint

The base URL for this endpoint is as follows:

https://api.polygon.io/v1/marketstatus/upcoming

Request parameters

This endpoint doesn’t require any input parameters other than our API key. We’ll call the market holiday endpoint in the following code. Click the “Run” button to view the output of this endpoint.

Press + to interact
// Importing libraries here
import fetch from "node-fetch";
// Define API key here
const apiKey = '{{API_KEY}}';
// Define endpoint URL here
const endpointUrl = new URL('https://api.polygon.io/v1/marketstatus/upcoming');
// Define Header Parameters here
const headerParameters = {
authorization: `Bearer ${apiKey}`
};
// Setting API call options
const options = {
method: 'GET',
headers: headerParameters,
};
// Function to make API call
async function MarketHoliday() {
try {
const response = await fetch(endpointUrl, options);
// Custom function for printing the API response
printResponse(response);
}
catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Calling function to make API call
MarketHoliday();

Here’s an explanation for the above code:

  • Line 8: We define the endpoint URL.

  • Lines 11–13: We define the API key in the header parameter.

  • Lines 16–19: We define the options parameters and set the request type as GET.

  • Lines 22–32: We define the function, MarketHoliday, which calls the endpoint.

    • Lines 23–27: We call the API in a try block and print the response.

    • Lines 28–31: We define a catch block to catch all errors and exceptions and print them.

  • Line 35: We call the MarketHoliday function.

Response fields

The following table gives details about attributes in the response object.

Name

Type

Description

close

String

The closing time on a holiday.

date

String

The date when the holiday is observed.

exchange

String

The name of the exchange market.

name

String

The name of the holiday.

open

String

The special opening time of the exchange on the holiday.

status

String

This provides the status of the exchange place on holiday. It will be early-close to represent the special early closing time of the market, or closed when the market is closed on holiday.