Fetch Historical Prices
Fetch historical price series with CoingeckoPricingClient.
Use getHistoricalPrice(from, to, opts) for chart data over a time range.
Fetch a Range
Pass start and end as Unix timestamps in milliseconds:
const end = Date.now()
const start = end - 7 * 24 * 60 * 60 * 1000
const series = await client.getHistoricalPrice('BTC', 'USD', {
start,
end
})
console.log(series)Each point has a price and timestamp:
type HistoricalPriceResult = {
price: number
timestamp: number
}Results are ordered oldest first.
Downsample Long Series
Use maxEntries when you only need a fixed number of points for a chart:
const series = await client.getHistoricalPrice('BTC', 'USD', {
start,
end,
maxEntries: 100
})The client keeps the first and last point and samples the middle of the series evenly.
Free and Pro Ranges
CoinGecko's public and Demo API host supports historical data inside the trailing 365-day window. For older ranges, configure the Pro host and a Pro key:
const client = new CoingeckoPricingClient({
baseURL: 'https://pro-api.coingecko.com/api/v3',
apiKey: process.env.COINGECKO_PRO_API_KEY
})