l2Book channel on wss://hypercore.goldrushdata.com/ws?key=<GOLDRUSH_API_KEY> is wire-equal to the public Hyperliquid feed but with coin made optional and the per-IP subscription cap removed. This recipe shows how to turn that stream into common trading and analytics building blocks. For the raw subscription shape see the l2Book reference; for the connection model see the Hyperliquid WebSocket API overview. To track many coins with less bandwidth, use the L2 order book diff stream, which sends only the price levels that changed each block; for order-level detail, see the L4 order book guide.
What you get
- Complete snapshots, not diffs. Every
l2Bookmessage contains the currenttime,coin, and a full[bids, asks]tuple in best-first order, withpx/sz/nper level. Consume each message in isolation - no sequence numbers to track, no diff replay buffer, no REST snapshot to bootstrap. - Self-healing on packet loss. Drop a message, reconnect mid-session, or restart your process - the next message arrives with the full book state, so your in-memory view is correct on the very next tick.
- Upstream-compatible aggregation knobs.
nSigFigsaccepts2,3,4,5, ornull(full precision).mantissaaccepts1,2, or5, and is only valid whennSigFigsis5. - Wildcard coverage. Omit
cointo stream every asset’s book over a single subscription, instead of fanning out one subscription per asset. The wildcard defaults to perps only (marketTypes: ["perp"]); pass["spot"],["outcome"], a mix, or["*"]to opt into spot, outcome, and future market types.
Pair address format
Hyperliquid markets use a deployer-prefix naming scheme. The exact string differs by surface, so pass the value each API expects - matching is case- and format-sensitive.deployer- wallet address of the HIP-3 builder that deployed the market. Omitted for canonical Hyperliquid markets.symbol- market ticker (e.g.GOLD,OIL).
HIP-4 outcome markets use a separate
#<encoding> scheme (e.g. #1230), not the deployer-prefix - see outcomeMeta.perpDexs Info API type) is on the roadmap. Until it ships, call metaAndAssetCtxs - the name field on each universe entry is the canonical pair address.
Subscribe and hold book state
The pattern below keeps aMap<coin, snapshot> in memory. Each incoming message replaces the entry for its coin, so the map is always current and never needs reconciliation.
Patterns
Top-of-book tracker
Readbids[0] and asks[0] directly from each message. The spread is Number(asks[0].px) - Number(bids[0].px). No state required - every message is self-contained, so a single-line transformation gives you a live ticker.
Depth-weighted mid quote
Sumpx * sz across the first K levels on each side, then average. This produces a fair-value mid that’s robust to thin top-of-book liquidity, and is useful as a hedging or pricing reference.
TypeScript
Slippage / impact estimator
Walk levels on the relevant side until cumulativesz covers the requested notional. Return the size-weighted average fill price - the difference vs the top-of-book is your expected slippage.
TypeScript
Liquidity heatmap
On each message, append[time, coin, side, px, sz] rows to your time-series store (Clickhouse, TimescaleDB, Parquet). Because every message is a complete snapshot of the top levels, the heatmap rebuilds correctly from any contiguous slice of history - you don’t need a separate “initial book” record to seed the visualisation.
Handling reconnects
Reconnect logic is a one-liner: open a new socket and resend the samesubscribe payload. The first message after subscribe is a full book snapshot, so your books map is correct on the next tick - there’s nothing to replay, nothing to buffer, and no sequence numbers to reconcile against a separately-fetched REST snapshot.
TypeScript
Related
l2BookAPI reference - full subscription and message schema.- L2 order book diff guide - the same book as per-block diffs, for one coin, a list, or every asset.
- L4 order book guide - order-level book with
user,oid, andcloidper resting order. - Hyperliquid WebSocket API overview - endpoint URL, auth, and limits.
clearinghouseState- pair the live book with per-account position and margin state.candleSnapshot- candles instead of raw book state.