How to Get OHLCV Candlestick Data for a Solana Token
Fetch OHLCV candlestick bars for any Solana token with one API call. Working TypeScript example for charts, TradingView, and backtests.
Introduction
To chart a Solana token you need OHLCV bars — call GET /chart/{mint}?type=1h (or use client.getChartData()) and you get timestamped open, high, low, close, and volume arrays ready for TradingView or any chart library.
What you need
- A Solana Tracker API key (free, 2,500 requests/month)
- Node.js 18+
Step 1 — Fetch hourly bars
import { Client } from '@solana-tracker/data-api';
const client = new Client({ apiKey: process.env.ST_API_KEY, baseUrl: 'https://data.solanatracker.io' });
const now = Math.floor(Date.now() / 1000);
const weekAgo = now - 7 * 24 * 3600;
const chart = await client.getChartData({
tokenAddress: MINT,
type: '1h',
timeFrom: weekAgo,
timeTo: now,
removeOutliers: true,
});
const bars = chart.oclhv ?? chart.ohlcv ?? [];
Step 2 — Map to TradingView format
TradingView expects time in seconds (UTC), not milliseconds:
const tvBars = bars.map((b) => ({
time: b.time,
open: b.open,
high: b.high,
low: b.low,
close: b.close,
volume: b.volume,
}));
Step 3 — Pick the right interval
Common type values: 1m, 5m, 15m, 1h, 4h, 1d. Use shorter intervals for scalping dashboards, longer for weekly views. Pass time_from / time_to as Unix seconds to limit the window and save credits.
Step 4 — Pool-specific charts
If a token trades on multiple pools, pass the pool address for pool-scoped OHLCV:
const poolChart = await client.getPoolChartData({
tokenAddress: MINT,
poolAddress: POOL_ID,
type: '15m',
});
Pitfall: mixing millisecond timestamps with the API's second-based
timefield will shift your chart by orders of magnitude. Always confirm the unit before plotting.
FAQ
Does the chart include volume?
Yes — each bar includes volume (and optionally volumeUsd depending on pool).
Can I get market-cap candles instead of price?
Pass marketCap: true in getChartData().
How is this different from the price REST endpoint?
/price returns the latest quote. /chart returns historical bars for plotting.
Related: Get a Solana token price (REST) → · Solana Data API
Download the example
Clone the full runnable project on GitHub — npm install && npm start with your keys in .env. Or open it in StackBlitz to run in your browser (free). See the tutorial for step-by-step context.
Runnable Node.js project — clone from GitHub, add keys to .env, then npm start. StackBlitz runs REST and Datastream examples in your browser for free.