Trending Securities

Learn to retrieve the trending securities of a region using the YH Finance API.

As discussed in the previous lesson, we can know which markets are doing better overall using the endpoint for market summary. The next logical step would be to find the trending securities of that region that are helping its market grow.

We can get trending securities of a region by using the https://yfapi.net/v1/finance/trending/{region} endpoint. The {region} parameter of this endpoint will be replaced with the symbol of the region we want the trending securities of while calling this endpoint. The possible options for this parameter are AU, CA, DE, ES, FR, GB, HK, IN, IT, and US.

Note: The table in the Appendix shows which region each of these symbols represents.

Request parameters

This endpoint has no request parameters.

The code below demonstrates how we can get the trending securities for a specific region—in this case, the US—using this endpoint. Click "Run" to get the list of trending securities.

Press + to interact
const endpointUrl = new URL('https://yfapi.net/v1/finance/trending/US');
const headerParameters = {
'X-API-KEY': '{{API_KEY}}'
}
const options = {
method: 'GET',
headers: headerParameters
};
async function fetchTrendingStocks() {
try {
const response = await fetch(endpointUrl, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
fetchTrendingStocks();

Let's look at the code explanation:

  • Line 1: We set the URL to https://yfapi.net/v1/finance/trending/US.

  • Lines 12–19: We define a function named fetchTrendingStocks() that calls the endpoint and prints the response.

We can change the US at the end of the URL in line 1 with the symbol of any other region to get the trending securities of that region.

Response fields

The table below discusses some important response fields.

Response fields

Description

count

This is the number of trending securities returned in the response.

symbol

This is the symbol of the trending securities.