← All articles

Bitget WebSocket books50 goes incremental (1 Dec 2026): keep your local order book right in Node.js

From 1 December 2026, Bitget’s UTA books50 WebSocket channel changes from a full snapshot on every push to incremental updates. The first message after you subscribe is still a full action: "snapshot". Every message after that is an action: "update" with only the levels that changed. The same change applies to the SBE Depth50 channel. It is already live on demo trading.

If your Node.js code treats every books50 message as the complete book, the local book will shrink to the levels in the latest update. This post shows how to merge those updates with bitget-api (3.2.9 at the time of writing). Public depth does not need API keys.

What changes on 1 December

  • books50: first push after subscribe is a snapshot, later pushes are incremental updates. pseq, which used to be set only on the full-depth books channel, is now also set on books50 so you can detect packet loss.
  • books is already snapshot then incremental. books1 and books5 still send a full snapshot on every push.
  • Until 1 December, live books50 still sends a snapshot every time. Code that resets the book on snapshot and merges on update is correct on both sides of the cutover. You can test the new behaviour now with demoTrading: true.

The official depth docs already describe books50 the new way. Use the UTA update preview for the live date.

Subscribe, reset on snapshot, merge updates

With WebsocketClientV3, subscribe to books50 on the public connection, the same way as in examples/V3 - UTA/Websocket/ws-public.ts. Each depth row has a (asks, price then size, ascending) and b (bids, descending). On a snapshot, replace the local book. On an update, merge by price. Bitget’s SBE docs for this same channel say a level with size 0 has been removed; apply that when you merge JSON updates too.

The SDK types seq and pseq as string | number. Turn them into strings with String() and compare those strings. Equality is a straight ===. The snapshot range check compares length first, then lexicographic order, so it stays correct for long numeric strings.

import { WebsocketClientV3, WS_KEY_MAP } from 'bitget-api';
import type { WsOrderBookDataV3 } from 'bitget-api';

const topic = {
  topic: 'books50' as const,
  payload: { instType: 'usdt-futures' as const, symbol: 'BTCUSDT' },
};

const ws = new WebsocketClientV3({
  // Already live on demo. Pass demoTrading: true to try it before 1 December.
  // demoTrading: true,
});

type Side = Map<string, string>;

const asks: Side = new Map();
const bids: Side = new Map();
let lastSeq: string | undefined;
let lastWasSnapshot = false;
let resubscribing = false;

function applyLevels(side: Side, levels: [string, string][]) {
  for (const [price, size] of levels) {
    if (size === '0') side.delete(price);
    else side.set(price, size);
  }
}

function toSeq(value: string | number): string {
  return String(value);
}

// Non-negative integer strings, no leading zeros: shorter is smaller.
function cmpSeq(a: string, b: string): number {
  if (a.length !== b.length) return a.length < b.length ? -1 : 1;
  if (a === b) return 0;
  return a < b ? -1 : 1;
}

function sequenceOk(row: WsOrderBookDataV3): boolean {
  const seq = toSeq(row.seq);
  if (lastSeq === undefined) return false;
  if (row.pseq === undefined || row.pseq === '') return false;
  const pseq = toSeq(row.pseq);
  if (lastWasSnapshot) {
    // Official: snapshot seq should fall within [pseq, seq] of the first update.
    return cmpSeq(lastSeq, pseq) >= 0 && cmpSeq(lastSeq, seq) <= 0;
  }
  // Official: seq of the previous update must equal pseq of this update.
  return pseq === lastSeq;
}

function resetBook() {
  asks.clear();
  bids.clear();
  lastSeq = undefined;
  lastWasSnapshot = false;
}

async function resubscribeForSnapshot() {
  if (resubscribing) return;
  resubscribing = true;
  resetBook();
  await ws.unsubscribe(topic, WS_KEY_MAP.v3Public);
  await ws.subscribe(topic, WS_KEY_MAP.v3Public);
}

interface Books50Event {
  action: 'snapshot' | 'update' | string;
  arg?: { topic?: string; symbol?: string; instType?: string };
  data: WsOrderBookDataV3[];
}

ws.on('update', (event: Books50Event) => {
  if (event.arg?.topic !== 'books50') return;
  const row = event.data[0];
  if (!row) return;

  if (event.action === 'snapshot') {
    asks.clear();
    bids.clear();
    applyLevels(asks, row.a);
    applyLevels(bids, row.b);
    lastSeq = toSeq(row.seq);
    lastWasSnapshot = true;
    resubscribing = false;
    return;
  }

  if (event.action !== 'update') return;

  if (!sequenceOk(row)) {
    console.warn('books50 sequence gap, resubscribing', {
      lastSeq,
      pseq: row.pseq,
      seq: row.seq,
    });
    void resubscribeForSnapshot();
    return;
  }

  applyLevels(asks, row.a);
  applyLevels(bids, row.b);
  lastSeq = toSeq(row.seq);
  lastWasSnapshot = false;
});

ws.on('exception', console.error);

ws.on('reconnected', () => {
  // The SDK resubscribes on its own. Clear the book so a stale merge is not applied first.
  resetBook();
});

ws.subscribe(topic, WS_KEY_MAP.v3Public);

Check pseq, and resubscribe if there is a gap

Official rules for pseq on books and books50:

  • The seq of one incremental update must equal the pseq of the next incremental update.
  • After a snapshot, that snapshot’s seq should fall within the [pseq, seq] range of the first update that follows it. That first update’s pseq is not always equal to the snapshot’s seq.
  • seq on updates should increase, except during symbol maintenance.
  • After a system release or restart you may see pseq=0. Snapshot examples also use pseq: 0.

The docs do not spell out a recovery procedure. A new subscribe starts with a full snapshot, so the reliable fix for a gap is to unsubscribe() and subscribe() again, then rebuild from that snapshot. The SDK resubscribes on its own after reconnected; clear the local book there and wait for the new snapshot.

Bitget removed the checksum field from UTA depth channels, including books50, on 19 May 2026. Use seq and pseq to check consistency. Do not expect a checksum on these frames.

rToken symbols

If you use books50 on rToken (tokenized stock) pairs, Bitget’s 13 October 2026 changelog is worth a look. After the matching-engine upgrade, books1 pushes at all times, during and outside market hours. books5, books50 and books push only outside market hours. During market hours, use books1 or the dedicated rToken depth channels if you need more than the top of book.

Checklist

Symptom Likely cause Fix
Book has only a few levels after the first updates Each update replaced the book instead of merging Reset only on action === 'snapshot'. Merge a and b by price on update, and delete a level when size is 0
Book drifts, or levels look stale A gap in the incremental stream Compare pseq with the official rules above, then unsubscribe and subscribe for a fresh snapshot
No books50 messages during the US session, on an rToken symbol Expected: books50 does not push during market hours for those pairs Use books1, or the rToken depth channels, while the market is open
  • Do not treat every books50 message as a full book after 1 December (and not on demo now).
  • Compare seq and pseq as strings.
  • Rebuild from a snapshot after a gap and after reconnected.

Further reading