> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Get token OHLCV

> USD OHLCV candles for a token, built from its most active pool, from 1-second to 1-month periods.

Returns open, high, low, close and volume candles for a token, priced in USD. The candles come from the token's most active pool, so you only need the token address. For a specific pool, use [`GET /market/ohlcv`](https://sonar-cf3aeac7.mintlify.site/api-reference/market/get-market-ohlcv). For a cross-chain series, use [`GET /asset/ohlcv`](https://sonar-cf3aeac7.mintlify.site/api-reference/asset/get-asset-ohlcv).

To keep a chart live after loading history, subscribe to the [`ohlcv` WebSocket channel](https://sonar-cf3aeac7.mintlify.site/websocket/channels/ohlcv). The [live price chart guide](https://sonar-cf3aeac7.mintlify.site/guides/live-price-chart.md) shows both steps.

## Query parameters

**address** `string` *required*

Token contract address: `0x` followed by 40 hex characters. Case-insensitive. 32-byte pool IDs are not accepted here.

**chain** `string` *required*

Chain ID, as a number (`8453`) or in `evm:<id>` form (`evm:8453`). See [Chains and identifiers](https://sonar-cf3aeac7.mintlify.site/concepts/chains-and-identifiers.md).

**period** `string` (default: 1h)

Candle size. One of `1s`, `5s`, `15s`, `30s`, `1m`, `5m`, `15m`, `30m`, `1h`, `4h`, `6h`, `12h`, `1d`, `1w`, `1M`.

Case matters: `1m` is one minute and `1M` is one calendar month.

**from** `integer`

Start of the range, in Unix epoch **milliseconds**. Defaults to `to` minus `limit` candles (`limit × period`, counting `1M` as 31 days). Must not be after `to`.

**to** `integer`

End of the range, in Unix epoch milliseconds. Defaults to now. The candle that contains `to` is included, so with the default you get the current, still-open candle.

**limit** `integer` (default: 500)

Maximum number of candles. Between `1` and `2000`.

**fill** `string` (default: false)

`true` to insert flat candles for periods without trades, `false` to skip them. Only the literal strings `true` and `false` are accepted.

## Response

**status** `string`

Always `"success"`.

**data** `OhlcvCandle[]`

Candles in **ascending** time order (oldest first, newest last). An empty array when there were no trades in the range.

**OhlcvCandle**

**t** `number`

Bucket start time in Unix epoch **milliseconds** (UTC).

**o** `number`

Open price in USD.

**h** `number`

High price in USD.

**l** `number`

Low price in USD.

**c** `number`

Close price in USD.

**v** `number`

Volume in USD. `0` when the bucket has no volume.

## How candles are built

### Which pool and which price

* **Best pool.** The API looks at up to 25 of the token's pools on that chain and uses the one with the highest 24h volume. If the token has no pool, the response is `404`.
* **Your token's side.** Candles are the USD price of the token you requested, whichever side of the pool it is on.

### Launchpad tokens: bonding-curve stitching

When the best pool is the DEX pool a launchpad token graduated to, its history starts at graduation. If all of these are true:

* the pool records a bonding-curve pool,
* the token is bonded and has a graduation time, and
* the DEX pool returns fewer than `limit` candles,

then candles from the bonding-curve pool (up to the graduation time and before the first DEX candle) are added in front, up to `limit` candles in total. The series continues across graduation without you having to query both pools.

### Which trades count

* **Price** (`o`, `h`, `l`, `c`) uses only trades worth **at least \$0.10** with a USD price above 0 and below 1,000,000,000. This keeps dust trades and broken prices out of the chart.
* **Volume** (`v`) is the USD volume of all trades in the bucket, including those below \$0.10.
* A bucket with no priced trade is treated as empty.

### Joined candles

Each candle's `o` is set to the **previous candle's `c`**, and `h` and `l` are widened to include that open. The chart has no gaps between consecutive candles. The first candle in the response keeps its own open.

### Empty periods and `fill`

* `fill=false` (default): empty buckets are left out, so consecutive candles may be more than one `period` apart.
* `fill=true`: flat candles (`o = h = l = c =` previous close, `v = 0`) are inserted for empty buckets **between** returned candles. Nothing is added before the first candle or after the last one. Filled candles count towards `limit`, and the most recent `limit` candles are kept.

### Time range and buckets

* Buckets start on round UTC boundaries for the period. `1w` buckets start on **Monday 00:00 UTC**. `1M` buckets are **calendar months** in UTC, so they vary in length.
* If more than `limit` buckets fall between `from` and `to`, you get the **most recent** `limit` candles.
* **Sub-minute periods** (`1s`, `5s`, `15s`, `30s`) are built from raw swaps, and their look-back is capped at `limit × period` before `to`, even if you pass an earlier `from`. For example, `period=1s&limit=500` covers at most the 500 seconds before `to`.

> [!TIP]
>
> To load older history, request again with `to` set to the first candle's `t` minus 1.

> [!WARNING]
>
> `from` and `to` are **milliseconds**. A value in seconds is accepted, but it is read as a date in January 1970. A `to` in seconds returns no candles. A `from` in seconds silently widens the range back to 1970.

> [!NOTE]
>
> OHLCV candles are returned **oldest first**. [`GET /token/history`](https://sonar-cf3aeac7.mintlify.site/api-reference/token/get-token-history) returns points **newest first**.

## Errors

| HTTP | `code` | When |
| - | - | - |
| 400 | `INVALID_ADDRESS` | `address` is not a valid 40-hex address, and that is the only problem. |
| 400 | `INVALID_PARAMETERS` | A required parameter is missing, `chain` is malformed, `period` is not in the list, `limit` is outside 1 to 2000, `fill` is not `true`/`false`, `from` is after `to` (`from: from must be before to`), or several problems at once. |
| 404 | `TOKEN_NOT_FOUND` | `Token or pool not found`: no pool for this token is indexed on that chain. |
| 500 | `INTERNAL_ERROR` | Unexpected server error. |

```bash cURL theme={null}
curl "https://api.example.com/api/v1/token/ohlcv?address=0x4200000000000000000000000000000000000006&chain=8453&period=1h&limit=3"
```

```javascript JavaScript theme={null}
const params = new URLSearchParams({
  address: "0x4200000000000000000000000000000000000006",
  chain: "8453",
  period: "1h",
  limit: "3",
  to: String(Date.now()), // milliseconds
});
const res = await fetch(`https://api.example.com/api/v1/token/ohlcv?${params}`);
const body = await res.json();
if (body.status !== "success") throw new Error(`${body.code}: ${body.message}`);

for (const { t, o, h, l, c, v } of body.data) {
  console.log(new Date(t).toISOString(), o, h, l, c, v);
}
```

```python Python theme={null}
import time
import requests

res = requests.get(
    "https://api.example.com/api/v1/token/ohlcv",
    params={
        "address": "0x4200000000000000000000000000000000000006",
        "chain": "8453",
        "period": "1h",
        "limit": 3,
        "to": int(time.time() * 1000),  # milliseconds
    },
    timeout=10,
)
body = res.json()
if body["status"] != "success":
    raise RuntimeError(f'{body["code"]}: {body["message"]}')

for candle in body["data"]:
    print(candle["t"], candle["o"], candle["h"], candle["l"], candle["c"], candle["v"])
```

```json 200 theme={null}
{
  "status": "success",
  "data": [
    { "t": 1796288400000, "o": 3398.11, "h": 3411.9, "l": 3390.02, "c": 3405.02, "v": 1840221.4 },
    { "t": 1796292000000, "o": 3405.02, "h": 3420.55, "l": 3401.3, "c": 3417.8, "v": 2011873.92 },
    { "t": 1796295600000, "o": 3417.8, "h": 3418.4, "l": 3409.12, "c": 3412.57, "v": 523004.11 }
  ]
}
```

```json 400 theme={null}
{
  "status": "error",
  "statusCode": 400,
  "code": "INVALID_PARAMETERS",
  "message": "from: from must be before to",
  "details": [{ "field": "from", "message": "from must be before to" }]
}
```

```json 404 theme={null}
{
  "status": "error",
  "statusCode": 404,
  "code": "TOKEN_NOT_FOUND",
  "message": "Token or pool not found"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.