Skip to main content

Kline

Subscribe to the klines stream.

tip

If confirm=true, this means that the candle has closed. Otherwise, the candle is still open and updating.

Available intervals:

  • 1 3 5 15 30 (min)
  • 60 120 240 360 720 (min)
  • D (day)
  • W (week)
  • M (month)

Push frequency: 1-60s

Topic:
kline.{interval}.{symbol} e.g., kline.30.BTCUSDT

Response Parameters

ParameterTypeComments
topicstringTopic name
typestringData type. snapshot
tsnumberThe timestamp (ms) that the system generates the data
dataarrayObject
> startnumberThe start timestamp (ms)
> endnumberThe end timestamp (ms)
> intervalstringKline interval
> openstringOpen price
> closestringClose price
> highstringHighest price
> lowstringLowest price
> volumestringTrade volume
> turnoverstringTurnover
> confirmbooleanWeather the tick is ended or not
> timestampnumberThe timestamp (ms) of the last matched order in the candle

Subscribe Example

from pybit.unified_trading import WebSocket
from time import sleep
ws = WebSocket(
testnet=True,
channel_type="linear",
)
def handle_message(message):
print(message)
ws.kline_stream(
interval=5,
symbol="BTCUSDT",
callback=handle_message
)
while True:
sleep(1)

Response Example

{
"topic": "kline.5.BTCUSDT",
"data": [
{
"start": 1672324800000,
"end": 1672325099999,
"interval": "5",
"open": "16649.5",
"close": "16677",
"high": "16677",
"low": "16608",
"volume": "2.081",
"turnover": "34666.4005",
"confirm": false,
"timestamp": 1672324988882
}
],
"ts": 1672324988882,
"type": "snapshot"
}