Skip to main content
The SDK maintains a single shared WebSocket connection to Hyperliquid and multiplexes all subscriptions over it. You subscribe to a market, receive a callback on every update, and call the returned unsubscribe function when you’re done. Reconnection and subscription restoration happen automatically in the background.
All subscriptions-order book, price, and trades-share one WebSocket connection. Opening multiple subscriptions does not open multiple connections.

Subscribe to the order book

subscribeOrderBook delivers a Level 2 book snapshot (bids and asks) for side 0 of the market on every change.

Subscribe to live prices

subscribePrice delivers both sides of a market via Hyperliquid’s allMids feed. Side names come from the outcome’s sideSpecs once the adapter has loaded them, so call initialize() first. Until then, they read "Side 0" and "Side 1".

Subscribe to the trade stream

subscribeTrades delivers each executed trade on side 0 of the market as it happens.
Call your unsubscribe function when a component unmounts or a view is hidden to prevent memory leaks and avoid processing updates for stale data.
Unsubscribe is safe to call more than once - a second call is a no-op (handy under React Strict Mode, which runs effect cleanups twice). And when several parts of your app subscribe to the same market, one unsubscribing never stops updates for the others: the shared subscription is reference-counted and only torn down when the last subscriber leaves.

Auto-reconnect

The WebSocket reconnects automatically if the connection drops. The retry schedule uses exponential backoff starting at 1 second, capped at 30 seconds, with a maximum of 10 attempts. Once reconnected, all active subscriptions are restored without any action on your part.

Create a price feed for charting

createPriceFeed merges historical candles with live price ticks into a single continuously-updating snapshot. It’s designed to power live charts without you needing to stitch together the initial fetch and the real-time stream yourself.

PriceFeedOptions

Historical candles always come from side 0, because fetchCandles reads side 0. With sideIndex: 1, only the live ticks follow side 1.

PriceFeedSnapshot

Subscribe to account positions

subscribePositions delivers updated position data for a wallet address. It polls fetchPositions instead of using a WebSocket: you get the first result right away, then a new one 10 seconds after each poll finishes.