Processing
Realtime
- GoldRush-native.
l2BookDiff2is not exposed onwss://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 aSnapshotframe. Every message is anUpdatesbatch. Seed your local book from the RESTl2BookDiffSnapshotinfo method, then apply diffs on top — see Bootstrapping & gap detection below. - Sequenced for gap detection. Each per-coin diff carries a monotonic
seqand theprev_seqit follows; each batch carries a serverepochand acursor. This lets a client detect a dropped message or a server reset and re-bootstrap deterministically. coinis optional. Omit it to stream every asset on a single subscription; usemarketTypesto 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 samesubscription 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 haschannel: "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.
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:
- Subscribe to
l2BookDiff2for your coin(s) and start buffering the incomingUpdates. - Fetch a snapshot for each coin from the REST
l2BookDiffSnapshotinfo method. Note itsheight,epoch, and per-coinseq. - Discard already-applied diffs. Drop any buffered batch whose
block_heightis ≤ the snapshot’sheight(the snapshot already includes those blocks). You may equivalently discard per coin byseq- drop any diff whoseseq≤ the snapshot’sseq- for the tightest alignment. - Verify the epoch. Every remaining diff’s
epochmust equal the snapshot’sepoch. A differentepochmeans the stream reset after your snapshot - re-fetch the snapshot and restart. - 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 whenszis"0". - Ongoing gap detection. Per coin, each diff’s
prev_seqmust equal the lastseqyou applied for that coin. On a mismatch (a dropped message) or anepochchange (a server reset), re-bootstrap that coin from step 2.
Response fields
string
Always
"l2BookDiff2".object
Contains an
Updates batch.Related endpoints
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.