Comment on page
getHistoricalPrice
getHistoricalPrice method is used to fetch historical prices. It can fetch prices in a time range for a single or multiple tokens
▸ getHistoricalPrice(
symbol
: string, opts
: GetHistoricalPriceOptions): Promise<PriceData>Returns the historical price for a single token
Parameters:
Name | Type | Description |
symbol | string | Token symbol (string) |
opts | GetHistoricalPriceOptions | Optional params (object)
|
Returns: Promise<PriceData>
The historical price for token
▸ getHistoricalPrice(
symbol
: string, opts
: GetHistoricalPriceForIntervalOptions): Promise<PriceData[]>Returns the historical prices for a token in a time range with the specified interval
remarks
This method can be used to display charts with historical prices. Full list of supported tokens is available hereParameters:
Name | Type | Description |
symbol | string | Token symbol |
opts | GetHistoricalPriceForIntervalOptions | Options object. It must contain startDate, endDate, and interval properties.
|
Returns: Promise<PriceData[]>
The historical prices for the symbol with the passed interval
▸ getHistoricalPrice(
symbols
: string[], opts
: GetHistoricalPriceOptions): Promise<{ [token: string]: PriceData; }>Returns the historical prices for several tokens
Parameters:
Name | Type | Description |
symbols | string[] | Array of token symbols |
opts | GetHistoricalPriceOptions | Options object. It must contain the date property.
|
Returns: Promise<{ [token: string]: PriceData; }>
The historical prices for multiple tokens
To get the historical price use the
getHistoricalPrice
method.const price = await redstone.getHistoricalPrice("AR", {
date: "2021-03-30T12:35:09", // Any convertable to date type
});
console.log(price.value); // AR price for specific time
The
date
argument must be convertable to the Date type. You may pass a date (e.g. new Date(2021-04-01)
), a timestamp (e.g. 1617709771289
), or just a string (e.g. 2021-04-01
or 2021-04-01T12:30:58
)To fetch the historical price for several tokens pass an array of symbols to
getHistoricalPrice
method.const symbols = ["AR", "BTC", "UNI", "ETH", "EUR"];
const prices = await redstone.getHistoricalPrice(symbols, {
date: "2021-03-30T12:35:09",
});
console.log(prices["BTC"].value); // BTC price for specific time
To fetch the historical prices in a time range specify token symbol as the first argument of the
getHistoricalPrice
method, and startDate
, endDate
and interval
as fields of the second argument.Currently Redstone API supports fetching historical prices in a time range only for a single token
const prices = await redstone.getHistoricalPrice("AR", {
startDate: "2021-03-29T12:35:09",
endDate: "2021-03-30T12:35:09",
interval: 3600 * 1000, // 1 hour
});
console.log(prices); // Example output below
/*
[
{
value: 28.8,
timestamp: 1617016995624,
...
},
{
value: 28.59,
timestamp: 1617014111705,
...
},
...
]
*/
The
startDate
and endDate
arguments must be convertable to Date type.Last modified 2yr ago