≈ the.bay.news

Hyperliquid in Node.js: how do you resync the order book after a WebSocket reconnect?

programming.dev
Hyperliquid in Node.js: how do you resync the order book after a WebSocket reconnect?
Picked up Hyperliquid’s WebSocket API for a Node service this week and hit the reconnect problem twice already: the incremental l2Book diffs resume when the socket comes back, but they resume into a book that has already drifted, and without a fresh snapshot the local copy never lines up again. What I ended up doing: 1. buffer diffs from the moment the socket closes 2. on reconnect, fetch a fresh snapshot and take its sequence number 3. replay only the buffered diffs newer than that snapshot, drop the rest 4. sanity-check with a crossed-book test (best bid > best ask means the buffer was wrong, so rebuild) I wrote the flow up while I was in it: https://siebly.io/sdk/hyperliquid/javascript/tutorial [https://siebly.io/sdk/hyperliquid/javascript/tutorial] Two questions for anyone running this in production: - is there a sequence field on Hyperliquid you actually trust, or do you timestamp-match? - does buffer-and-replay hold at high message rates, or do you just rebuild the book on every reconnect?

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.