Back to home
Crypto API

How to Get OHLC Candlestick Data for Any Coin

Coinranking
Coinranking
How to Get OHLC Candlestick Data for Any Coin

A price is one number. A candle is the range that number moved through. Open, high, low, close, and volume are what a chart, a backtest, and most trading signals actually need. Coinranking returns that as OHLCV for any coin, from one-minute bars to one-month bars.

The endpoint is one path, with the coin UUID in it:

https://api.coinranking.com/v2/coin/:uuid/ohlcv

Bitcoin is Qwsogvtv82FCd. Ethereum is razxDUgYGNAdQ. The same key and header as the rest of the API, x-access-token. This endpoint is on the Professional plan. Price history without candles is available on every plan, on the coin price history endpoint. Candles are a REST call. Keeping the last candle live is a stream, covered in REST vs WebSocket for crypto prices.

Latest candles

With no from, the call returns the most recent candles for the interval you ask for. The default interval is day, and the default limit is 50. The cap is 5,000.

curl "https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/ohlcv?interval=hour&limit=200" \
  -H "x-access-token: YOUR_API_KEY"

Intervals are minute, 5minutes, hour, 8hours, day, week, and month. Candles come back newest first. Each one has a start and an end as Unix seconds, so a chart does not have to guess the bucket.

{
  "status": "success",
  "data": {
    "ohlc": [
      {
        "startingAt": 1733011200,
        "endingAt": 1735689600,
        "open": "96447.1775503152",
        "high": "108201.88415847138",
        "low": "91546.14889956331",
        "close": "92757.25601337428",
        "avg": "98498.05461116068",
        "24hVolume": "46442676990.360725",
        "intervalVolume": "2002368626068.8618"
      }
    ]
  }
}

endingAt is exclusive. 24hVolume is the rolling 24-hour volume at the end of that bucket, not the volume of the candle. intervalVolume is the volume of the bucket itself. In this latest-candles mode it is filled for week and month only. Finer intervals leave it null.

Prices are strings. Parse them as decimals, not as floating-point numbers, if the value is going into a calculation.

A specific range

Pass from, and optionally to, and the call switches to a historical window. Both are Unix timestamps in seconds. from is snapped down to the start of its interval, so the bucket that contains it is included. to is not snapped. The window is half-open: every bucket that starts before to is included, and a candle that starts exactly at to is not. Leave to out and the window runs to now.

Minute candles go back to December 2018. Every interval accepts from and to, not only minutes.

curl "https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/ohlcv?interval=hour&from=1614556800&to=1617235200" \
  -H "x-access-token: YOUR_API_KEY"

limit is ignored in this mode. A response holds at most 1,440 candles, which is one day of minutes. If that does not cover the window, data.paging.next is a timestamp. Call again with from set to that value and the same to. Stop when next is null.

Page from next, not from the number of candles. A short page can still have more to follow.

async function candles(uuid, from, to, interval = "hour") {
  const rows = [];
  let cursor = from;

  while (cursor != null) {
    const url = new URL(`https://api.coinranking.com/v2/coin/${uuid}/ohlcv`);
    url.searchParams.set("interval", interval);
    url.searchParams.set("from", String(cursor));
    url.searchParams.set("to", String(to));

    const body = await fetch(url, {
      headers: { "x-access-token": "YOUR_API_KEY" }
    }).then((response) => response.json());

    rows.push(...body.data.ohlc);
    cursor = body.data.paging.next;
  }

  return rows;
}

The same window always returns the same candles, and pages do not overlap. A finished window is cached for an hour (Cache-Control: max-age=3600). A window that touches the present is cached for 60 seconds. Deep history shares a daily fair-use quota. Over it, the API returns 429 with TOO_MANY_REQUESTS. Wait, then resume from the same next cursor.

What older candles leave out

The archive did not always store every field, and the API does not invent them.

  • avg is null in deep history.
  • Where only a close was kept, open, high, and low are set to that close. The candle is flat. Those fields are null only when the bucket has no data at all, in which case close is null too.
  • intervalVolume is null where the source did not record it.
  • 24hVolume on an old candle is still a rolling 24-hour snapshot at the end of the bucket, not a sum of the interval.

Treat a flat candle as a close, not as a traded range.

A currency other than USD

referenceCurrencyUuid converts the candle from the USD calculation. It does not rebuild the candle from trades in that currency. Because the reference rate moves during the bucket, open or close can land outside high and low. For a true OHLC range, stay in USD. The default reference currency is USD, yhjMzLPhuIDl. UUIDs for EUR and the rest are on the reference currencies endpoint.

Drawing the chart

Fetch the candles, reverse them if the chart wants oldest first, and map startingAt to the x axis. Seven intervals cover the usual chart buttons, so the button can be the query parameter.

Keep the last candle open. REST is the history. A WebSocket rate can move the close of the current bucket, and the high and low if the tick breaks them. On the next interval, append a new candle and leave the closed one alone. Do not rebuild history from the stream. A reconnect leaves a gap, and the socket will not fill it. For a page that only displays the price, Server-Sent Events are the preferred stream. Working browser code is in how to stream live crypto prices in JavaScript.

An unknown UUID returns 404 with COIN_NOT_FOUND. Match on the type, not the message.

Futures

Spot candles are aggregated across the exchanges Coinranking tracks. Perpetual futures for the same coin are a different path, /v2/futures/coin/:uuid/ohlcv, alongside open interest and the funding rate. The candle shape is the same. Indicators calculated on these intervals, including moving averages, RSI, and MACD, are on the indicators endpoints.

Bottom line

One path, seven intervals, newest first. Use limit for the latest candles. Use from and to for a range, and follow data.paging.next until it is null. Minute history starts in December 2018. Load the chart from this endpoint, then stream only the candle that is still open. How that stream fits the rest of the API is in the complete guide to real-time crypto price streaming.

The full parameter list is in the OHLCV docs. Candles are on the Professional plan, free for 30 days at coinranking.com/api.



Stay Updated

Join 30,000+ readers. Get the latest crypto news, analysis, and insights delivered to your inbox weekly. No spam, unsubscribe anytime.