XRPL OHLC & Historical Price Data API
One request returns the price history of any XRP Ledger token as candles: for each period, the price it opened at, its high, its low, the price it closed at, and the volume. From 1-minute to 1-week candles, in XRP or a fiat currency, back to the token’s first trade.
What a candle is
The request
XRP’s last month of daily candles in US dollars. Each candle is [time, open, high, low, close, volume]:
curl "https://api.xrpl.to/v1/ohlc/84e5efeb89c4eae8f68188982dc290d8?range=1M&interval=1d&vs_currency=USD"
{
"success": true,
"interval": "1d",
"vs_currency": "USD",
"length": 30,
"ohlc": [
[
1792195200000,
1.3115,
1.3126,
1.2701,
1.2941,
41064361.7
],
[
1792281600000,
1.2941,
1.3101,
1.2562,
1.3071,
67755153.7
],
[
1792368000000,
1.3071,
1.3168,
1.3016,
1.31076638,
16242759.3
]
]
}Parameters
| range | 1D|5D|7D|1M|3M|1Y|5Y|ALL |
| interval | 1m|5m|15m|30m|1h|2h|4h|1d|1w |
| vs_currency | XRP|USD|EUR|JPY|CNH (default: XRP). EUR, JPY and CNH candles are converted at the ECB reference rate of their own day (the last business day before a weekend or holiday; CNH uses the ECB's CNY); a candle with no rate in the week before it is left out |
| resolution | int (minutes), or D|W |
| cb | int (candle bar count, max 5000) |
| to | unix ms (with resolution): a page of history, the cb candles that open before it. Page back by passing the first candle's time; an empty ohlc means the history ends there. Absent, or inside the current candle: the live window ending now |
| invert | bool |
Paging back through years
For a long history, ask for a fixed number of candles and walk backwards: set resolution (minutes, or D for a day) and cb (up to 5,000), then pass to as the time of the first candle you have. An empty list means you reached the token’s first trade.
// every daily candle a token has, oldest first
async function allDays(md5) {
const out = [];
let to;
for (;;) {
const url = `https://api.xrpl.to/v1/ohlc/${md5}?resolution=D&cb=5000${to ? `&to=${to}` : ''}`;
const { ohlc } = await (await fetch(url)).json();
if (!ohlc || !ohlc.length) return out;
out.unshift(...ohlc); // [time, open, high, low, close, volume]
to = ohlc[0][0]; // page back from the first candle
}
}What people build with it
- Charts: the arrays drop straight into charting libraries such as TradingView’s Lightweight Charts.
- Indicators and bots: moving averages, RSI and the like are computed from closes; the API also serves RSI directly at
/v1/rsi. - Backtests: years of candles in a few requests, with the to-paging above.
Any app that shows the data must credit xrpl.to visibly beside it; the API guide has the limits and plans.
Questions
- How do I get historical prices for an XRP Ledger token?
- GET /v1/ohlc/{id} with the token’s md5 or slug. range picks the window (1D to ALL), interval the candle size (1m to 1w), and vs_currency the unit (XRP or a fiat currency).
- How far back does the price history go?
- To the token’s first trade. Pass resolution and cb (up to 5,000 candles) and page back with to, set to the first candle’s time, until the API returns an empty list.
- What is in each candle?
- An array: time in Unix milliseconds, then open, high, low and close prices, then volume.