Developers

Candlestick

List candles (klines) for one instrument and interval, newest first.

On this page

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. 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.
SDKclient.candlestick(...)
HTTPPOST https://market-data.testnet.grvt.io/full/v1/kline, or /lite/v1/kline for lite names (the SDKs' default)
WebSocketmethod v1/kline on wss://market-data.testnet.grvt.io/ws/full, or /ws/lite for lite names
AuthNone (public)
RetriesRead: the SDKs retry retryable errors (rules)
Contract idcandlestick.candlestick (RPCCandlestickV1)

Request

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

  • instrumentlite name istring (instrument name)required#
    The instrument name, e.g. BTC_USDT_Perp (perpetual), BTC_USDT_SFP (stable funding perp) or BTC_USDT_SpotSwap (spot swap).
  • intervallite name i1enum CandlestickIntervalrequired#
    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).
  • typelite name tenum CandlestickTyperequired#
    The type of candlestick data to retrieve. Note: For spot instruments, only trade and mid are available
    4 values
    TRADE, MARK, INDEX, MID (details).
  • start_timelite name ststring (int64 unix ns)optionaldefault 0#
    Start time of kline data in unix nanoseconds
  • end_timelite name etstring (int64 unix ns)optionaldefault now()#
    End time of kline data in unix nanoseconds
  • limitlite name linteger (uint32)optionaldefault 500#
    The limit to query for. Defaults to 500; Max 1000
  • cursorlite name cstringoptional#
    The cursor to indicate when to start the query from

Response

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

  • resultlite name rarray<Candlestick>required#
    The candlestick result set for given interval
    10 fields of Candlestick
    • open_timelite name otstring (int64 unix ns)required#
      Open time of kline bar in unix nanoseconds
    • close_timelite name ctstring (int64 unix ns)required#
      Close time of kline bar in unix nanosecond
    • openlite name ostringrequired#
      The open price, expressed in underlying currency resolution units
    • closelite name cstringrequired#
      The close price, expressed in underlying currency resolution units
    • highlite name hstringrequired#
      The high price, expressed in underlying currency resolution units
    • lowlite name lstringrequired#
      The low price, expressed in underlying currency resolution units
    • volume_blite name vbstringrequired#
      The underlying volume transacted. Decimal string, e.g. "0.01"; up to the instrument's base_decimals.
    • volume_qlite name vqstringrequired#
      The quote volume transacted, in the quote asset. Decimal string, e.g. "12.5".
    • tradeslite name tinteger (uint32)required#
      The number of trades transacted
    • instrumentlite name istring (instrument name)required#
      The instrument name, e.g. BTC_USDT_Perp (perpetual), BTC_USDT_SFP (stable funding perp) or BTC_USDT_SpotSwap (spot swap).
  • nextlite name nstringoptional#
    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
}
EOF

With 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
Run on testnet
esc

↑ ↓ move↵ open⇧↵ open .mdTry an error code like 2002

Keyboard shortcuts

⌘ K
Search the docs
/
Search
l
Next code language (Python → TypeScript → Go → Rust → curl → WebSocket)
j / k
Next / previous page
t
Light / dark theme
?
This help
Esc
Close dialogs and drawers