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":"dae030e0-7791-4c6f-a7c5-f38dc4fb2ab3"}
{"channel":"book","product":"BTC-PERP","type":"subscribed"}
{"channel":"book","product":"BTC-PERP","type":"snapshot","data":{"bids":[["64648","0.772"],["64646","0.775"],["64644","1.377"],["64642","0.94"],["64641","0.998"],["64639","0.909"],["64636","0.776"],["64635","0.912"],["64631","2.252"],["64626","1.177"],["64625","0.984"],["64623","1.209"],["64620","1.021"],["64618","1.135"],["64616","0.817"],["64613","1.159"],["64611","1.479"],["64609","1.135"],["64606","1.199"],["64604","0.958"],["64602","1.348"],["64601","1.006"],["64599","1.385"],["64597","1.297"],["64596","0.953"],["64591","0.982"],["64590","1.199"]],"asks":[["64655","0.792"],["64661","1.175"],["64663","1.187"],["64664","0.955"],["64668","0.983"],["64669","2.455"],["64672","1.206"],["64675","1.022"],["64679","2.749"],["64680","1.136"],["64682","1.181"],["64686","1.251"],["64687","0.863"],["64690","0.98"],["64691","1.166"],["64695","1.029"],["64698","2.232"],["64699","0.822"],["64702","1.127"],["64705","1.452"],["64707","0.872"],["64708","1.317"],["64713","2.336"],["64716","1.155"],["64719","0.929"],["64721","1.199"]],"timestamp":"1721281176903905000","gsn":108639724},"timestamp":"1721281176903905000"}
{"channel":"book","product":"BTC-PERP","type":"update","data":{"bids":[],"asks":[["65970","0.027"]],"timestamp":"1721281177084223000","gsn":108639771},"timestamp":"1721281177084223000"}
{"channel":"book","product":"BTC-PERP","type":"update","data":{"bids":[],"asks":[["65970","0"]],"timestamp":"1721281177240916000","gsn":108639794},"timestamp":"1721281177240916000"}
{"channel":"book","product":"BTC-PERP","type":"update","data":{"bids":[["63380","0.025"]],"asks":[],"timestamp":"1721281178041572000","gsn":108639872},"timestamp":"1721281178041572000"}
// 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
  },
  "timestamp": "1701798871000000000" // unix nano timestamp as a string
}
// 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
  },
  "timestamp": "1701798871000000000" // unix nano timestamp as a string
}
{
  "channel": "book",
  "type": "error",
  "message": "given channel/product is unsupported",
  "code": 400
}