# Charts

> Price candles in USD or NEAR, fetched once or kept live.

This page is part of the Intear API docs. The Intear API is at `https://api.intea.rs` and `wss://api.intea.rs/ws`, with no API key. https://docs.intear.tech/api/llms-full.txt has all of its pages in one file, and https://docs.intear.tech/llms.txt lists every page of the Intear docs.

[`candles.get`](https://docs.intear.tech/api/reference/candles.md#candlesget) returns price candles of up to 200 tokens at once, and [`candles.subscribe`](https://docs.intear.tech/api/reference/candles.md#candlessubscribe) keeps them live.

## Fetching candles

Candles come as columns rather than one object per candle, so a chart library can often take them as they are:

```json
{
  "height": 219969220,
  "timestamp_millis": 1792003477277,
  "tokens": {
    "wrap.near": {
      "time": [1791921600000, 1791925200000],
      "usd": { "open": [4.79, 4.8], "high": [4.83, 4.82], "low": [4.77, 4.79], "close": [4.8, 4.81] }
    }
  },
  "missing": []
}
```

`time` is when each candle opens, in milliseconds, oldest first.

```js
const params = new URLSearchParams({
  tokens: 'wrap.near',
  resolution: '60',
  count_back: '24',
  series: 'open,high,low,close',
});
const response = await fetch(`https://api.intea.rs/candles?${params}`);
const result = await response.json();
if (!response.ok) throw new Error(result.error.message);
const { time, usd } = result.tokens['wrap.near'];
const candles = [];
for (const [i, openedAt] of time.entries()) {
  candles.push({ time: openedAt, open: usd.open[i], high: usd.high[i], low: usd.low[i], close: usd.close[i] });
}
```

The whole file, tested in CI: https://docs.intear.tech/snippets/js/src/intear-api.js

## Resolutions

| `resolution` | Candle | Also accepted |
| --- | --- | --- |
| `1S` | 1 second | |
| `1` | 1 minute | `1m` |
| `5` | 5 minutes | `5m` |
| `15` | 15 minutes | `15m` |
| `60` | 1 hour | `60m`, `1h` |
| `240` | 4 hours | `240m`, `4h` |
| `D` | 1 day | `24h`, `1d` |
| `W` | 1 week | `7d`, `1w` |

The aliases work in any case.

:::note
1-second chart skips empty candles without trades, while other resolutions also reflect the price of the asset it's paired with (usually NEAR) even when the token itself was not traded.
:::

## In NEAR

`"quote": "near"` gives prices in NEAR instead of USD: the token's USD price over NEAR's at the same block. A token traded against NEAR then stays flat while only NEAR moves. Ask for both with `"quote": ["usd", "near"]`, and each token has a `usd` and a `near` object.

## Live charts

[`candles.subscribe`](https://docs.intear.tech/api/reference/candles.md#candlessubscribe) takes the same params except `to_millis`, with `count_back` defaulting to `0`. Set `count_back` to get the chart's history in the reply too. Each push has the candles that changed in that block: the latest one, and a new one when it opens. A push can also carry the candle before the latest one. A candle replaces the one you have with the same `time`.

## Easy-to-embed TradingView chart

Embed `https://chart.intear.tech/?token=token.intear.near` in an iframe for a live TradingView chart, it already connects to the API and does all the work by itself.
