---
title: "Candlestick"
description: "List candles (klines) for one instrument and interval, newest first."
---

Klines are uniquely identified by their instrument, type, interval, and open time.

Pagination works as follows:

- We perform a reverse chronological lookup, starting from `end_time`. If `end_time` is not set, we start from the most recent data.
- The lookup is limited to `limit` records. If more data is requested, the response will contain a `next` cursor for you to query the next page.
- If a `cursor` is provided, it will be used to fetch results from that point onwards.
- Pagination will continue until the `start_time` is reached. If `start_time` is not set, pagination will continue as far back as our data retention policy allows.

| | |
|---|---|
| SDK | `client.candlestick(...)` |
| HTTP | `POST https://market-data.<domain>/full/v1/kline`, or `/lite/v1/kline` for [lite names](../../guides/environments.md#encoding-full-or-lite) (the SDKs' default) |
| WebSocket | method `v1/kline` on `wss://market-data.<domain>/ws/full`, or `/ws/lite` for lite names |
| Auth | None (public) |
| Retries | Read: the SDKs retry retryable errors ([rules](../../guides/errors-and-retries.md)) |
| Contract id | `candlestick.candlestick` (`RPCCandlestickV1`) |

## Request

Body type `ApiCandlestickRequest`. Fields the server fills are left out.

- `instrument` · lite `i` · string (instrument name) · required — The instrument name, e.g. `BTC_USDT_Perp` (perpetual), `BTC_USDT_SFP` (stable funding perp) or `BTC_USDT_SpotSwap` (spot swap).
- `interval` · lite `i1` · enum CandlestickInterval · required — The interval of each candlestick
  Values: `CI_1_M`, `CI_3_M`, `CI_5_M`, `CI_15_M`, `CI_30_M`, `CI_1_H`, `CI_2_H`, `CI_4_H`, `CI_6_H`, `CI_8_H`, `CI_12_H`, `CI_1_D`, `CI_3_D`, `CI_5_D`, `CI_1_W`, `CI_2_W`, `CI_3_W`, `CI_4_W` ([details](../enums.md#candlestickinterval)).
- `type` · lite `t` · enum CandlestickType · required — The type of candlestick data to retrieve. Note: For spot instruments, only `trade` and `mid` are available
  Values: `TRADE`, `MARK`, `INDEX`, `MID` ([details](../enums.md#candlesticktype)).
- `start_time` · lite `st` · string (int64 unix ns) · optional, default `0` — Start time of kline data in unix nanoseconds
- `end_time` · lite `et` · string (int64 unix ns) · optional, default `now()` — End time of kline data in unix nanoseconds
- `limit` · lite `l` · integer (uint32) · optional, default `500` — The limit to query for. Defaults to 500; Max 1000
- `cursor` · lite `c` · string · optional — The cursor to indicate when to start the query from

## Response

Body type `ApiCandlestickResponse` (the same object is the JSON-RPC `result` over WebSocket).

- `result` · lite `r` · object Candlestick[] · required — The candlestick result set for given interval
- `result[].open_time` · lite `ot` · string (int64 unix ns) · required — Open time of kline bar in unix nanoseconds
- `result[].close_time` · lite `ct` · string (int64 unix ns) · required — Close time of kline bar in unix nanosecond
- `result[].open` · lite `o` · string · required — The open price, expressed in underlying currency resolution units
- `result[].close` · lite `c` · string · required — The close price, expressed in underlying currency resolution units
- `result[].high` · lite `h` · string · required — The high price, expressed in underlying currency resolution units
- `result[].low` · lite `l` · string · required — The low price, expressed in underlying currency resolution units
- `result[].volume_b` · lite `vb` · string · required — The underlying volume transacted. Decimal string, e.g. "0.01"; up to the instrument's base_decimals.
- `result[].volume_q` · lite `vq` · string · required — The quote volume transacted, in the quote asset. Decimal string, e.g. "12.5".
- `result[].trades` · lite `t` · integer (uint32) · required — The number of trades transacted
- `result[].instrument` · lite `i` · string (instrument name) · required — The instrument name, e.g. `BTC_USDT_Perp` (perpetual), `BTC_USDT_SFP` (stable funding perp) or `BTC_USDT_SpotSwap` (spot swap).
- `next` · lite `n` · string · optional — The cursor to indicate when to start the next query from

## Errors

Errors come back as `{"code", "message", "status"}` (lite `{"c", "m", "s"}`) with the HTTP status. Codes this call can return, as code, name (HTTP status) ([all error codes](../errors.md)):

`1002` InternalServer (500) · `1003` InvalidRequest (400) · `1006` RateLimit (429, retryable) · `1014` GatewayTimeout (504, retryable) · `1015` ServiceUnavailable (503, retryable) · `3042` InvalidCandlestickTypeForSpot (400) · `3043` InvalidCandlestickTypeForStablePerp (400)

## Example

```python
from grvt import Grvt, enums as e

with Grvt(env="testnet") as client:
    resp = client.candlestick(
        instrument="BTC_USDT_Perp",
        interval=e.CandlestickInterval("CI_1_M"),
        type=e.CandlestickType("TRADE"),
        limit=500,
    )
    print(resp)
```

Raw HTTP (set `GRVT_DOMAIN`, see [Environments](../../guides/environments.md)):

With full field names:

```sh
curl -sS "https://market-data.$GRVT_DOMAIN/full/v1/kline" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "instrument": "BTC_USDT_Perp",
  "interval": "CI_1_M",
  "type": "TRADE",
  "limit": 500
}
EOF
```

With lite field names:

```sh
curl -sS "https://market-data.$GRVT_DOMAIN/lite/v1/kline" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "i": "BTC_USDT_Perp",
  "i1": "CI_1_M",
  "t": "TRADE",
  "l": 500
}
EOF
```
