Skip to main content

Processing

Realtime
  • GoldRush-native. l2BookDiff2 is not exposed on wss://api.hyperliquid.xyz/ws. Pointing a client at the public endpoint with this subscription type will fail.
  • Diff-only — no inline snapshot. Unlike l2BookDiff, this stream never sends a Snapshot frame. Every message is an Updates batch. Seed your local book from the REST l2BookDiffSnapshot info method, then apply diffs on top — see Bootstrapping & gap detection below.
  • Sequenced for gap detection. Each per-coin diff carries a monotonic seq and the prev_seq it follows; each batch carries a server epoch and a cursor. This lets a client detect a dropped message or a server reset and re-bootstrap deterministically.
  • coin is optional. Omit it to stream every asset on a single subscription; use marketTypes to choose which market families are included (defaults to ["perp"]).

Endpoint

string
required
Your GoldRush API key. Passed as a query parameter at connection time - no Authorization header is used.

Subscribe

Send this JSON message after the connection is established:
string
required
Always "subscribe".
object
required

Example

Unsubscribe

Send the same subscription body with method: "unsubscribe":
Unsubscribe matches subscriptions by exact body. A subscription created with coin: ["BTC", "ETH"] is a different subscription from one created with coin: "BTC". To narrow a multi-coin set, unsubscribe the original coin array in full, then resubscribe with the smaller list.

Streamed messages

Every message has channel: "l2BookDiff2" and a data payload containing an Updates batch (this stream never emits a Snapshot). An Updates batch is emitted on each HyperCore block where the book for at least one subscribed coin changed.
Each entry in levels[0] (bids) and levels[1] (asks) replaces the current state at its px. A level with sz: "0" and n: 0 means the level at that price has been removed.

Bootstrapping & gap detection

l2BookDiff2 gives you diffs only, so you build the book yourself by seeding from a snapshot and applying diffs in order:
  1. Subscribe to l2BookDiff2 for your coin(s) and start buffering the incoming Updates.
  2. Fetch a snapshot for each coin from the REST l2BookDiffSnapshot info method. Note its height, epoch, and per-coin seq.
  3. Discard already-applied diffs. Drop any buffered batch whose block_height is the snapshot’s height (the snapshot already includes those blocks). You may equivalently discard per coin by seq - drop any diff whose seq the snapshot’s seq - for the tightest alignment.
  4. Verify the epoch. Every remaining diff’s epoch must equal the snapshot’s epoch. A different epoch means the stream reset after your snapshot - re-fetch the snapshot and restart.
  5. Apply in order. For each coin, the first diff you apply should have prev_seq == snapshot.seq. For each level, upsert {px, sz, n}, or remove the price when sz is "0".
  6. Ongoing gap detection. Per coin, each diff’s prev_seq must equal the last seq you applied for that coin. On a mismatch (a dropped message) or an epoch change (a server reset), re-bootstrap that coin from step 2.
The seq/prev_seq are per coin, tracked within the current epoch. Compare them per coin, not globally across the batch.

Response fields

string
Always "l2BookDiff2".
object
Contains an Updates batch.

l2BookDiffSnapshot

Full-depth L2 snapshot with the height/epoch/seq needed to bootstrap this stream.

l2BookDiff

Snapshot-then-diff L2 stream (self-seeding, no sequence numbers).

l2Book

Real-time L2 order book snapshots over WebSocket.