Candlestick
List candles (klines) for one instrument and interval, newest first.
On this page
Write a small program that calls `candlestick.candlestick` on Grvt {environment} {using}.
Target environment: {environment} (chain ID {chainId}). Recorded signing cases keep their original environment.
{executionGuidance}
Read this first: {origin}/bundle/reference/rpc/candlestick.md (~52 KB, plain Markdown: this page plus the AGENTS.md rules, Errors and retries, Python SDK, Environments).
Fetch other pages from the index at {origin}/llms.txt only as you need them. {origin}/downloads/contract.json is a machine-readable contract for tools, not for reading.
Rules: follow AGENTS.md; do not send requests without the user asking you to; read credentials from environment variables; never retry writes automatically; show me the code and how to run it. URLs and generated code samples on this page: Testnet (chain ID 326). Other code on this page doesn't change: it stays on testnet until you switch it in your code. Tutorials, signing cases and live tools always use testnet.
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. Ifend_timeis not set, we start from the most recent data. - The lookup is limited to
limitrecords. If more data is requested, the response will contain anextcursor for you to query the next page. - If a
cursoris provided, it will be used to fetch results from that point onwards. - Pagination will continue until the
start_timeis reached. Ifstart_timeis not set, pagination will continue as far back as our data retention policy allows.
| SDK | client. |
|---|---|
| HTTP | POST https:/, or /lite/v1/kline for lite names (the SDKs' default) |
| WebSocket | method v1/kline on wss:/, or /ws/lite for lite names |
| Auth | None (public) |
| Retries | Read: the SDKs retry retryable errors (rules) |
| Contract id | candlestick. (RPCCandlestickV1) |
Request
Body type ApiCandlestickRequest. Fields the server fills are left out.
- The instrument name, e.g.
BTC_USDT_Perp(perpetual),BTC_USDT_SFP(stable funding perp) orBTC_USDT_SpotSwap(spot swap). - The interval of each candlestick
18 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). - The type of candlestick data to retrieve. Note: For spot instruments, only
tradeandmidare available4 values
- Start time of kline data in unix nanoseconds
- End time of kline data in unix nanoseconds
- The limit to query for. Defaults to 500; Max 1000
- The cursor to indicate when to start the query from
Response
Body type ApiCandlestickResponse (the same object is the JSON-RPC result over WebSocket).
- The candlestick result set for given interval
10 fields of
Candlestick- Open time of kline bar in unix nanoseconds
- Close time of kline bar in unix nanosecond
- The open price, expressed in underlying currency resolution units
- The close price, expressed in underlying currency resolution units
- The high price, expressed in underlying currency resolution units
- The low price, expressed in underlying currency resolution units
- The underlying volume transacted. Decimal string, e.g. "0.01"; up to the instrument's base_decimals.
- The quote volume transacted, in the quote asset. Decimal string, e.g. "12.5".
- The number of trades transacted
- The instrument name, e.g.
BTC_USDT_Perp(perpetual),BTC_USDT_SFP(stable funding perp) orBTC_USDT_SpotSwap(spot swap).
- 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 (all error codes):
3042InvalidCandlestickTypeForSpot400- Candlestick type is not applicable for spot instruments
3043InvalidCandlestickTypeForStablePerp400- Candlestick type not supported for this instrument
Plus 5 errors any call can return
1002InternalServer500- Internal Server Error
1003InvalidRequest400- Request could not be processed due to malformed syntax
1006RateLimit429retryable- You have surpassed the allocated rate limit for your tier
1014GatewayTimeout504retryable- Upstream data service timed out, please try again
1015ServiceUnavailable503retryable- Upstream data service is temporarily unavailable, please try again
Example
Example code
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):
With full field names:
curl -sS "https://market-data.testnet.grvt.io/full/v1/kline" \
-H "Content-Type: application/json" \
--data @- <<EOF
{
"instrument": "BTC_USDT_Perp",
"interval": "CI_1_M",
"type": "TRADE",
"limit": 500
}
EOFWith lite field names:
curl -sS "https://market-data.testnet.grvt.io/lite/v1/kline" \
-H "Content-Type: application/json" \
--data @- <<EOF
{
"i": "BTC_USDT_Perp",
"i1": "CI_1_M",
"t": "TRADE",
"l": 500
}
EOF