Real-Time Quotes

Take a look at how we can get real-time quotes for securities.

A real-time quote displays the actual price of a security at that very moment in time. These quotes are generally displayed with supplemental information—for example, the lowest price for the day, the highest price for the day, and the volume for that security in the exchange. These quotes are handy for traders.

Endpoint for real-time quotes

The YH Finance API provides us with an endpoint that we can call to get a real-time quote for a security. The base URL of that endpoint is https://yfapi.net/v6/finance/quote.

Request parameters

Three query parameters can be used with this endpoint, as shown in the table below:

Parameters

Category

Type

Description

symbols

required

string

This is the symbol of the security we want to search for. The table in the Appendix contains symbols of some important securities.

lang

optional

string

This parameter represents the language in which we want the information; possible values include en, es, de, fr, it, and zh. The table in the Appendix shows which language each of these symbols represents.

region

optional

string

This parameter represents the region for which we want the information. The possible options for this parameter are AU, CA, DE, ES, FR, GB, HK, IN, IT, and US. The table in the Appendix shows which region each of these symbols represents.

The code below shows how we can get a quote for Apple Inc. stocks using YH Finance API. Click the "Run" button to get the quote.

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

Let's look at a brief explanation of the above code:

  • Lines 1–11: We define the URL, query parameters, and header parameters.

  • Lines 13–16: We declare the request type and set the appropriate header.

  • Lines 18–26: We define an async function, fetchQuotes().

    • Line 20: The function embeds the query parameters in the URL.

    • Lines 21-24 It calls the API and saves the response in the response variable. In case of a successful request, it prints the response otherwise, it prints the error.

  • Line 28: We call the fetchQuotes() function.

We can search the quote for any other security by replacing AAPL in line 6 with the symbol of that security. We can also request quotes for multiple securities in one call. For that, our symbols parameter should contain the symbols of all the securities we want to search for, separated by a comma. For example, if we want quotes for both Apple Inc. and Bitcoin in one call, the symbols parameter should contain AAPL,BTC-USD.

Response fields

We'll get the quote for Apple Inc. stocks as a response. Some key output fields that we'll get are mentioned in the table below:

Response fields

Description

longName

This is the name of the issuer of the security.

quoteType

This is the type of security the selected symbol falls in—for example, equity, ETF, funds, and so on.

bid

This is the highest price a trader is willing to pay for the security.

ask

This is the lowest price a trader is willing to sell the security for.

bidSize

This represents the number of people willing to buy the security at the bid price mentioned in the quote.

askSize

This represents the number of people willing to sell the security at the ask price mentioned in the quote.

Note: The response also contains other important information. This information can vary depending on the type of security we are searching the quote for.