Hyperliquid’s l2Book feed sends price-level snapshots. The fast option changes their cadence and depth. The separate l2 feed starts with a snapshot and then sends diffs that the client applies to its copy of the book.

Three BTC feeds in the same 60-second window
The table compares simultaneous BTC mainnet subscriptions over 60 seconds. The bbo feed supplies the best bid and offer for comparison.
| Feed | Messages in 60 s | What each message holds |
|---|---|---|
l2Book (default) |
6 | Full snapshot, up to 20 levels a side; gaps of 8.9 s, then about 12.4 s |
l2Book with fast: true |
109 | Full snapshot, tagged fast: true, roughly every 0.55 s |
l2 |
1 + 108 | One snapshot, then diffs; every diff arrived compressed |
bbo |
201 in 20 s | Top of book only, sent when it changes on a block |
Hyperliquid describes WsBook as a snapshot “pushed on each block that is at least 0.5 since last push”. In this capture the fast feed followed that cadence. The default snapshots arrived about 12 seconds apart.
Requesting fast snapshots
Install the SDK with npm install @siebly/hyperliquid-api. Public market data needs no key. The SDK’s subscription type accepts fast, nSigFigs and mantissa on l2Book, and checking event.channel narrows event.data to the right type:
import { WebsocketClient } from '@siebly/hyperliquid-api';
const ws = new WebsocketClient();
ws.on('message', (event) => {
if (event.channel === 'l2Book') {
const [bids, asks] = event.data.levels;
console.log(event.data.fast ? 'fast' : 'slow', bids[0]?.px, asks[0]?.px);
}
if (event.channel === 'bbo') {
const [bid, ask] = event.data.bbo;
console.log('bbo', bid?.px, ask?.px);
}
});
await ws.subscribe([
{ type: 'l2Book', coin: 'BTC', fast: true },
{ type: 'bbo', coin: 'BTC' },
]);
If you subscribe to both modes for the same coin, fast messages carry fast: true and default ones omit the field, so you can tell them apart. Fast snapshots are the easiest upgrade: the handler stays the same, every message is a whole book, and a missed message costs nothing because the next one replaces it.
Grouping price levels with nSigFigs and mantissa
Both the WebSocket feed and the REST getOrderBook() method accept aggregation. nSigFigs (2 to 5) rounds price levels to that many significant figures, and mantissa (1, 2 or 5) is only valid with nSigFigs: 5:
import { RestClient } from '@siebly/hyperliquid-api';
const client = new RestClient();
const full = await client.getOrderBook({ coin: 'BTC' });
const tens = await client.getOrderBook({ coin: 'BTC', nSigFigs: 4 });
const fives = await client.getOrderBook({ coin: 'BTC', nSigFigs: 5, mantissa: 5 });
console.log(full?.levels[0][0], tens?.levels[0][0], fives?.levels[0][0]);
Example bid levels with BTC near 60,100:
- no aggregation: 1 dollar steps (60104, 60103, 60102)
nSigFigs: 5, mantissa: 2: 2 dollar steps;mantissa: 5: 5 dollar stepsnSigFigs: 4: 10 dollar steps;3: 100;2: 1,000
Every response still had 20 levels a side, so coarser levels show more of the book in the same payload. Sending mantissa with nSigFigs: 4 returned an HTTP 500, which the SDK raised as a HyperliquidApiError. A coin the SDK doesn’t recognise fails before any request, with a hint to call refreshAssetMetadata() after a new listing.
Rebuild the book from l2 diffs
The l2 feed ({ type: 'l2', c: 'BTC' }, with optional s and m working like nSigFigs and mantissa) sends one snapshot under s, then diffs. A diff arrives either plain under u or as a base64 string under c holding raw DEFLATE data. The SDK types all three shapes as WsL2 and passes them through, so decode c yourself. fflate is already installed as a dependency of the SDK, but add it to your own package.json if you import it directly.
Hyperliquid’s rule for applying a diff: first remove the levels at the indexes in r (positions in the previous book), then add or replace the levels in l by price.
import { type WsL2, type WsL2Diff } from '@siebly/hyperliquid-api';
import { inflateSync, strFromU8 } from 'fflate';
type Level = { px: string; sz: string };
type Book = { coin: string; time: number; bids: Level[]; asks: Level[] };
function decodeL2(data: WsL2): { snapshot?: Book; diff?: WsL2Diff } {
if ('s' in data) {
const [bids, asks] = data.s.levels;
return {
snapshot: {
coin: data.s.coin,
time: data.s.time,
bids: bids.map(({ px, sz }) => ({ px, sz })),
asks: asks.map(({ px, sz }) => ({ px, sz })),
},
};
}
if ('u' in data) {
return { diff: data.u };
}
const bytes = Uint8Array.from(atob(data.c), (ch) => ch.charCodeAt(0));
return { diff: JSON.parse(strFromU8(inflateSync(bytes))) as WsL2Diff };
}
function applySide(
levels: Level[],
removed: number[],
updates: { p: string; s: string }[],
isBid: boolean,
): Level[] {
const drop = new Set(removed);
const next = levels.filter((_, index) => !drop.has(index));
for (const { p, s } of updates) {
const index = next.findIndex((level) => level.px === p);
if (index >= 0) {
next[index] = { px: p, sz: s };
} else {
next.push({ px: p, sz: s });
}
}
return next.sort((a, b) =>
isBid ? Number(b.px) - Number(a.px) : Number(a.px) - Number(b.px),
);
}
function applyDiff(book: Book, diff: WsL2Diff): Book {
return {
coin: book.coin,
time: diff.t,
bids: applySide(book.bids, diff.r[0], diff.l[0], true),
asks: applySide(book.asks, diff.r[1], diff.l[1], false),
};
}
Diffs contain price and size but no order count. To check a rebuilt book, compare its best bid and ask with bbo messages at matching timestamps.
Reset the book after a reconnect
On a forced disconnect, the SDK reconnected and resubscribed in about 1.7 seconds. The server then sent a fresh snapshot. Discard the local book on disconnect and wait for that snapshot before applying new diffs.
import { WebsocketClient } from '@siebly/hyperliquid-api';
const ws = new WebsocketClient();
let book: Book | undefined;
ws.on('reconnected', () => {
book = undefined; // wait for the fresh snapshot
});
ws.on('message', (event) => {
if (event.channel !== 'l2') {
return;
}
const { snapshot, diff } = decodeL2(event.data);
if (snapshot) {
book = snapshot;
} else if (book && diff) {
book = applyDiff(book, diff);
}
if (book) {
console.log(book.time, book.bids[0]?.px, book.asks[0]?.px);
}
});
await ws.subscribe({ type: 'l2', c: 'BTC' });
The same rule applies to the default and fast l2Book modes in a weaker form: after a reconnect, wait for the next snapshot before acting on the book.
Choosing between snapshots, diffs and REST
- Top of book only (spreads, simple price checks):
bbo. - Whole book, simple code:
l2Bookwithfast: true. - Whole book, smallest messages:
l2, with decoding, diff application and a reset on reconnect. - Occasional depth checks: REST
getOrderBook(), aggregated withnSigFigswhen you need a wider view. - Default
l2Book: only where a refresh every few seconds is acceptable.
Further reading
The Hyperliquid JavaScript tutorial covers market data, wallet setup, orders and WebSockets. For channel types and parameters, use the Hyperliquid SDK docs and its WebSocket subscriptions guide. If the process also places orders, keep its signing key scoped and separate as described in API key security best practices. Siebly maintains the MIT-licensed SDK alongside binance, bybit-api and okx-api.
