WebSocket API is a convenient tool for obtaining real–time data. You can receive orderbook updates, ongoing orders, kline information and ticker information in real time.

Currently, there are 4 types of subscriptions and 2 requests to the WebSocket API.

Heartbeat

Every once in a while, the server will send a PING message. The client needs to reply to the PONG message, otherwise the server will close the connection.

  • ping message
{
    "ping": 1535975085052
}
  • pong message
{
    "pong": 1535975085052
}

Subscription Full Depth

To subscribe to these events, you must send the following message:

  • $symbol – example: btcusdt
  • cb_id – Business ID (not required)
{
    "event": "sub",
    "params": {
        "channel": "market_$symbol_depth_step0",
        "cb_id": "1"
    }
}

An example of an event that will be sent to you after subscribing to these events:

  • The maximum number of returned orders is 30.
{
    "channel": "market_btcusdt_depth_step0",
    "ts": 1506584998239,
    "tick": {
        "asks": [
            [10000.19, 0.93],
            [10001.21, 0.2],
            [10002.22, 0.34]
        ],
        "buys": [ 
            [9999.53, 0.93],
            [9998.2, 0.2],
            [9997.19, 0.21]
        ]
    }
}

Subscription Real Time Trade

To subscribe to these events, you must send the following message:

  • $symbol – example: btcusdt
  • cb_id – Business ID (not required)
{
    "event": "sub",
    "params": {
        "channel": "market_$symbol_trade_ticker",
        "cb_id": "1"
    }
}

An example of an event that will be sent to you after subscribing to these events:

{
    "channel": "market_$symbol_trade_ticker",
    "ts": 1506584998239,
    "tick": {
        "data": [
            {
                "side": "buy",
                "price": 32.233,
                "vol": 232,
                "amount": 323,
                "ds": "2017-09-10 23:12:21"
            }
        ]
    }
}

Subscription Kline Market

To subscribe to these events, you must send the following message:

  • $symbol – example: btcusdt
  • $interval – 1min / 5min / 15min / 30min / 60min / 1day /1week / 1month
  • cb_id – Business ID (not required)
{
    "event": "sub",
    "params": {
        "channel": "market_$symbol_kline_$interval",
        "cb_id": "1"
    }
}

An example of an event that will be sent to you after subscribing to these events:

{
    "channel": "market_$symbol_kline_1min",
    "ts": 1506584998239,
    "tick": {
        "id": 1506602880,
        "vol": 1212.12211,
        "open": 2233.22,
        "close": 1221.11,
        "high": 22322.22,
        "low": 2321.22
    }
}

Subscription Market Tickers

To subscribe to these events, you must send the following message:

  • $symbol – example: btcusdt
  • cb_id – Business ID (not required)
{
    "event": "sub",
    "params": {
        "channel": "market_$symbol_ticker",
        "cb_id": "1"
    }
}

An example of an event that will be sent to you after subscribing to these events:

{
    "channel": "market_$symbol_ticker",
    "ts": 1506584998239,
    "tick": {
        "amount": 123.1221,
        "vol": 1212.12211,
        "open": 2233.22,
        "close":1 221.11,
        "high": 22322.22,
        "low": 2321.22,
        "rose": -0.2922
    }
}

Request Kline History Data

To subscribe to these events, you must send the following message:

  • $symbol – example: btcusdt
  • $interval – 1min / 5min / 15min / 30min / 60min / 1day /1week / 1month
  • cb_id – Business ID (not required)
  • endIdx – Return pageSize data before endIdx (not required)
  • pageSize – page size (not required)
{
    "event": "req",
    "params": {
        "channel": "market_$symbol_kline_$interval",
        "cb_id": "1",
        "endIdx": "1506602880",
        "pageSize": 100
    }
}

An example of an event that will be sent to you after subscribing to these events:

  • data – No more than 300 events
{
    "event_rep": "rep",
    "channel": "market_$symbol_kline_$interval",
    "ts": 1506584998239,
    "data": [
        {
            "id": 1506602880,
            "amount": 123.1221,
            "vol": 1212.12211,
            "open": 2233.22,
            "close": 1221.11,
            "high": 22322.22,
            "low": 2321.22
        },
        {
            "id": 1506602880,
            "amount": 123.1221,
            "vol": 1212.12211,
            "open": 2233.22,
            "close": 1221.11,
            "high": 22322.22,
            "low": 2321.22
        }
    ]
}

Request Trade History

To subscribe to these events, you must send the following message:

  • $symbol – example: btcusdt
  • cb_id – Business ID is not required
{
    "event": "req",
    "params": {
        "channel": "market_$symbol_trade_ticker",
        "cb_id": "1"
    }
}

An example of an event that will be sent to you after subscribing to these events:

{
    "event_rep": "rep",
    "channel": "market_$symbol_trade_ticker",
    "ts": 1506584998239,
    "status": "ok",
    "data":[
        {
            "side": "buy",
            "price": 32.233,
            "vol": 232,
            "amount": 323,
            "ts": 1729091475895,
            "ds": "2024-10-16 18:11:17"
        },
        {
            "side": "buy",
            "price": 32.233,
            "vol": 232,
            "amount": 323,
            "ts": 1729091475895,
            "ds": "2024-10-16 18:11:17"
        }
    ]
}