Skip to main content

Market Data

Subscription Examples

Sample Requests and Stream

Request → Receipt Confirmation → Stream (continuous feed)

Candlesticks

Continuous feed of candlestick data with default/provided depth.

Valid channels are: candles_minute_1, candles_minute_5, candles_minute_10, candles_minute_15, candles_minute_30, candles_hour_1, candles_hour_2, candles_hour_4, candles_hour_6, candles_hour_12, candles_day_1, candles_day_3, candles_week_1 and candles_month_1

Stream Response FieldData TypeDescription
symbolStringsymbol name
amountStringquote units traded over the interval
highStringhighest price over the interval
quantityStringbase units traded over the interval
tradeCountIntegercount of trades
lowStringlowest price over the interval
closeTimeLongclose time of interval
startTimeLongstart time of interval
closeStringprice at the end time
openStringprice at the start time
tsLongtime the record was pushed
Example:
# --> Request
{
"event": "subscribe",
"channel": ["candles_minute_1"],
"symbols": ["btc_usdt"]
}

# <-- Receipt Confirmation
{
"channel": "candles_minute_1",
"event": "subscribe",
"symbols": ["BTC_USDT"]
}

# <-- Stream
{
"channel": "candles_minute_1",
"data": [{
"symbol": "BTC_USDT",
"amount": "0",
"high": "9999.07",
"quantity": "0",
"tradeCount": 0,
"low": "9999.07",
"closeTime": 1648057199999,
"startTime": 1648057140000,
"close": "9999.07",
"open": "9999.07",
"ts": 1648057141081
}
}]
}

Trades

Continuous feed of recent trades with default/provided depth.

Stream Response FieldData TypeDescription
symbolStringsymbol name
amountStringquote units traded
takerSideStringtrade side (buy, sell)
quantityStringbase units traded
createTimeLongtime the trade was created
priceStringtrade price
idLongtrade id
tsLongtime the record was pushed
Example:
# --> Request
{
"event": "subscribe",
"channel": ["trades"],
"symbols": ["BTC_USDT"]
}

# <-- Receipt Confirmation
{
"channel": "trades",
"event": "subscribe",
"symbols": ["BTC_USDT"]
}

# <-- Stream
{
"channel": "trades",
"data": [{
"symbol": "BTC_USDT",
"amount": "70",
"takerSide": "buy",
"quantity": "4",
"createTime": 1648059516810,
"price": "104",
"id": 1648059516810,
"ts": 1648059516832
}]
}

Ticker

Continuous feed (updated every second) of current day ticker data

Stream Response FieldData TypeDescription
symbolStringsymbol name
dailyChangeStringdaily change in decimal
highStringhighest price over the last 24h
amountStringquote units traded over the last 24h
quantityStringbase units traded over the last 24h
tradeCountIntegercount of trades
lowStringlowest price over the last 24h
closeTimeLongclose time for the 24h interval
startTimeLongstart time for the 24h interval
closeStringprice at the end time
openStringprice at the start time
tsLongtime the record was pushed
markPriceStringmark price at the end time
Example:
# --> Request
{
"event": "subscribe",
"channel": ["ticker"],
"symbols": ["ETH_USDT"]
}

# <-- Receipt Confirmation
{
"channel": "ticker",
"event": "subscribe",
"symbols": ["ETH_USDT"]
}

# <-- Stream
{
"channel": "ticker",
"data": [{
"symbol": "ETH_USDT",
"dailyChange": "0.9428",
"high": "507",
"amount": "20",
"quantity": "3",
"tradeCount": 11,
"low": "16",
"closeTime": 1634062351868,
"startTime": 1633996800000,
"close": "204",
"open": "105",
"ts": 1648052794867,
"markPrice": "205",
}]
}

Ticker (All Symbols)

# --> Request
{
"event": "subscribe",
"channel": ["ticker"],
"symbols": ["all"]
}

# <-- Receipt Confirmation
{
"channel": "ticker",
"event": "subscribe",
"symbols": ["all"]
}

# <-- Stream
{
"channel": "ticker",
"data": [{
"symbol": "BTC_USDT",
"dailyChange": "-0.7409",
"high": "38596.3",
"amount": "26843.353145272",
"quantity": "101.00438344",
"tradeCount": 13,
"low": "0.8654",
"closeTime": 1648054681007,
"startTime": 1647968280000,
"close": "9999.07",
"open": "38596.3"
"ts": 1648054693082,
"markPrice": "38234.43"
}]
}

# <-- Stream (continued)
{
"channel": "ticker",
"data": [{
"symbol": "ETH_USDT",
"dailyChange": "0.9428",
"high": "507",
"amount": "20",
"quantity": "3",
"tradeCount": 11,
"low": "16",
"closeTime": 1634062351868,
"startTime": 1633996800000,
"close": "204",
"open": "105",
"ts": "1648052794867",
"markPrice": "205"
}]
}

Book

Continuous feed of order book data containing asks and bids with default/provided depth. Default depth is 5. Valid depths are 5, 10, or 20, which can be specified using depth field as shown in the example. Order book is updated every 100ms.

Stream Response FieldData TypeDescription
symbolStringsymbol name
createTimeLongtime the record was created
asksList<String>sell orders, in ascending order of price
bidsList<String>buy orders, in descending order of price
idLongid of the record (SeqId)
tsLongsend timestamp
Example:
# --> Request
{
"event": "subscribe",
"channel": ["book"],
"symbols": ["BTC_USDT"]
}

# --> Request With Depth Parameter

{
"event": "subscribe",
"channel": ["book"],
"symbols": ["BTC_USDT"],
"depth": 10
}

# <-- Receipt Confirmation
{
"channel": "book",
"event": "subscribe",
"symbols": ["BTC_USDT"]
}

# <-- Stream
{
"channel": "book",
"data": [{
"symbol": "BTC_USDT",
"createTime": 1648052239156,
"asks": [],
"bids": [
["40001.5", "2.87"],
["39999.4", "1"]
],
"id": 123456,
"ts": 1648052239192
},

{
"symbol": "BTC_USDT",
"createTime": 1648052239156,
"asks": [],
"bids": [
["40001", "2.87"],
["39999", "1"]
],
"id": 345678,
"ts": 1648052239192
}]
}

Book Level 2

Receive a snapshot of the full 20 level order book. Then, continuously in realtime receive an updated order book when the first 20 levels change.

To maintain a copy of the order book locally:

  1. Send a book_lv2 subscription message.
  2. Receive a snapshot message from the server.
  3. Use an appropriate data structure to store the received book.
  4. Receive an incremental order book message (update) from the server and make changes depending on [price, quantity] pair data:
    • When quantity is positive, update the corresponding price of your order book with this quantity.
    • When quantity is 0, delete this price from your order book.
  5. Receive an order book message (snapshot) from the server, reset your order book data structure to match this new order book.

Note: If id of the last message does not match lastId of the current message then the client has lost connection with the server and must re-subscribe to the channel.

Stream Response FieldData TypeDescription
symbolStringsymbol name
asksList<String>sell orders, in ascending order of price
bidsList<String>buy orders, in descending order of price
createTimeLongtime the record was created
lastIdLongthe id of the previous message
idLongid of the record (SeqId)
tsLongsend timestamp
Example:
# --> Request
{
"event": "subscribe",
"channel": ["book_lv2"],
"symbols": ["btc_usdt"]
}

# <-- Receipt confirmation
{
"channel": "book_lv2",
"event": "subscribe",
"symbols": ["BTC_USDT"]
}

# <-- Stream (snapshot)
{
"channel": "book_lv2",
"action": "snapshot",
"data": [{
"symbol": "BTC_USDT",
"asks": [
["6.16", "0.6"],
["6.17", "1"],
["6.18", "1"],
...
],
"bids": [
["5.65", "0.02"],
["5.61", "1.68"],
["5.6", "25.38"],
...
],
"createTime": 1653029116343,
"lastId": 10409,
"id": 10410,
"ts": 1652774727337
}]
}


# <-- Stream (update)
{
"channel": "book_lv2",
"action": "update",
"data": [{
"symbol": "BTC_USDT",
"asks": [
["6.35", "3"]
],
"bids": [
["5.65", "0.02"]
],
"createTime": 1653029116345,
"lastId": 10410,
"id": 10421,
"ts": 1653029116529
}]
}