This page will help you get started with Orderbook Websocket.

Channel: book

The book channel provides updates on the order book. One snapshot of the orderbook is returned upon subscribing and every minute after that.

Subsequently, updates are streamed to the consumer every 25ms where bids and asks contain updates to the order-book (with the new sizes if there are changes to a price level). If there is no update, nothing is returned to the client.

// npm install -g wscat first if needed
wscat -c wss://ws.testnet.bsx.exchange/ws -x '{"op":"sub","channel":"book","product":"BTC-PERP"}'
{"type":"message", "connection_id":"f54bbfe6-8094-4ecf-ae50-2940a6c9a41e"}
{"channel":"book","product":"BTC-PERP","type":"subscribed"}
{"channel":"book","product":"BTC-PERP","type":"snapshot","data":{"bids":[["43819.4","5.032"],["43819.3","0.3404"],["43819","1.108"],["43818.5","9.304"],["43818.4","9.484"],["43818","0.844"],["43817.7","1.058"],["43817.5","0.3745"],["43817.4","0.572"],["43817.3","0.572"],["43817.1","0.572"],["43817","0.3981"],["43816.9","0.572"],["43816.7","0.814"],["43816.6","0.3989"],["43816.5","0.602"],["43816.4","0.806"],["43816.3","0.724"],["43816.2","0.2344"],["43816.1","0.3434"],["41406","9.1387817992"],["40975","11.3028006654"],["40543","10.4170936861"],["40112","11.2345924311"],["39681","10.7408332685"],["39250","10.044012845"],["38818","9.2584477015"],["38387","10.1848947882"],["37956","10.4609309698"],["37524","10.4694053539"],["37093","11.2792580907"],["36662","10.3093380471"],["36230","10.1161782723"],["35799","11.1926349266"],["35368","10.3116959204"],["34936","10.85440864"],["34505","9.6640676947"],["34074","8.6868607909"],["33642","8.8807217956"],["33211","9.081117076"],["32780","9.6824559416"],["32349","10.2323135528"],["31917","9.7527924597"],["31486","10.0548889007"],["31055","10.5536502322"],["30623","9.1065043551"],["30192","10.0563139061"],["29761","8.9523143418"],["29329","11.2027069102"],["28898","9.7796567712"]],"asks":[["43819.5","5.1517"],["43819.6","0.3374"],["43820","0.2359"],["43821.5","0.3901"],["43822","0.2712"],["43822.5","0.3203"],["43822.7","0.2661"],["43823","0.654"],["43823.1","0.446"],["43823.2","0.2043"],["43823.3","0.726"],["43823.4","1.682"],["43823.5","0.2468"],["43823.6","0.3572"],["43823.7","0.308"],["43823.8","0.206"],["43823.9","0.386"],["43824","0.2319"],["43824.1","0.494"],["43824.4","0.3273"],["44857","11.2473428425"],["45288","9.0380567312"],["45719","9.2780106747"],["46151","10.0732553887"],["46582","10.5499338212"],["47013","8.6723820503"],["47444","9.4842676944"],["47876","11.289711845"],["48307","10.1125494974"],["48738","8.7489316873"],["49170","9.6657702921"],["49601","9.0767740282"],["50032","8.5758524109"],["50464","9.4337114592"],["50895","10.0043046906"],["51326","8.7292068701"],["51758","11.1838263741"],["52189","10.342823656"],["52620","11.2904585316"],["53052","10.3978502117"],["53483","11.028628085"],["53914","10.5149926661"],["54346","10.0857076581"],["54777","11.1036485246"],["55208","8.7400925043"],["55639","9.153419372"],["56071","9.3220106591"],["56502","10.7412173059"],["56933","9.6204733797"],["57365","9.2027229748"]],"timestamp":"1703513231967311000","gsn":1053133}}
{"channel":"book","product":"BTC-PERP","type":"update","data":{"asks":[["43819.5","5.1517"]],"timestamp":"1703513232200701000","gsn":1053134}}
{"channel":"book","product":"BTC-PERP","type":"update","data":{"bids":[["43819.4","4.3399"]],"timestamp":"1703513232242688000","gsn":1053137}}
{"channel":"book","product":"BTC-PERP","type":"update","data":{"asks":[["43819.5","4.8917"]],"timestamp":"1703513233324540000","gsn":1053147}}
// Request
{
  "op": "sub", 
  "channel": "book",
  "product": "BTC-PERP"
}
// Response
{
  "channel": "book",
  "product": "BTC-PERP",
  "type": "snapshot",
  "data": {
    "bids": [ 
      ["36000", "50"],
      ["36200", "20"],
      ["36300", "10"]
    ], 
    "asks": [ 
      ["36500", "10"],
      ["36650", "20"],
      ["36800", "50"]
    ],
    "timestamp": 1701798871000000000 // unix nano
  }
}
// Response
{
  "channel": "book",
  "product": "BTC-PERP",
  "type": "update",
  "data": {
    "bids": [ 
      ["36000", "0"], // the new size of price 36000 is 0 (no order at this price level)
      ["36200", "20"], // the new size of price 36200 is 20
      ["36300", "10"]
    ], 
    "asks": [ 
      ["36500", "12"],
      ["36650", "23"],
      ["36800", "50"]
    ],
    "timestamp": 1701798871000000000 // unix nano
  }
}