adapter.marketData) gives you both snapshot and streaming access to HIP-4 market data. You can poll for order books, prices, trades, and OHLCV candles, or subscribe to live WebSocket feeds that deliver updates as they arrive. All market methods accept a marketId, which is the outcome ID as a string (e.g. "516"). fetchOrderBook and fetchTrades default to side 0 (the first side). fetchCandles, subscribeOrderBook, and subscribeTrades always use side 0.
marketId is always the outcome ID as a string - not the event ID and not the coin string. For example, if the coin is "#5160", the market ID is "516".fetchOrderBook(marketId, sideIndex?)
Returns a full L2 order book snapshot for a given outcome side.
Parameters
Which side to fetch.
0 = first side (e.g. “Yes”), 1 = second side (e.g. “No”). Defaults to 0.Return type
Promise<PredictionOrderBook>
Buy-side price levels, each with
price (string) and size (string).Sell-side price levels, each with
price (string) and size (string).Example
fetchPrice(marketId)
Returns the current midpoint price for both sides of an outcome, with the real side names. Uses a 5-second cache backed by the allMids endpoint, so rapid successive calls avoid redundant network requests.
Parameters
Return type
Promise<PredictionPrice>
One entry per side. Each entry contains:
name- the side name from the outcome’ssideSpecs(e.g."Yes","No","Hypurr","template:Yes"). The adapter loads side names before resolving them, so you only see the generic"Side 0"/"Side 1"for an outcome it doesn’t know.parsedName- the readable side name. Template sides are rendered from Hyperliquid’s template registry ("template:Yes"reads"Yes"); other sides repeatname. Available from 1.3.0.price- current midpoint as a decimal string (0 to 1)."0"when no mid is available.midpoint- same value asprice(both fields are set identically).
Example
fetchTrades(marketId, limit?, sideIndex?)
Returns recent trades for one side of a market outcome.
Parameters
The
PredictionMarketDataAdapter interface type declares only marketId and limit, so TypeScript rejects a third argument on adapter.marketData. The HIP-4 implementation (HIP4MarketDataAdapter) accepts sideIndex.Return type
Promise<PredictionTrade[]>
Example
fetchCandles(marketId, interval?, startTime?, endTime?)
Returns OHLCV candle data for side 0 of a market outcome.
Parameters
Start of the time range as a Unix millisecond timestamp. Defaults to 14 days before the current time.
Return type
A promise for an array of candle objects. The SDK converts Hyperliquid’s raw candles (HLCandle) to numbers:
Example
subscribeOrderBook(marketId, cb)
Opens a real-time WebSocket subscription to the L2 order book for side 0 of a market outcome. The callback receives a full book snapshot on each update.
Parameters
Callback invoked on each book update. Receives a
PredictionOrderBook snapshot.Return type
Unsubscribe - a () => void function. Call it to stop receiving updates and release the WebSocket subscription.
subscribePrice(marketId, cb)
Opens a real-time WebSocket subscription to midpoint prices for both sides of a market outcome. The callback fires on every allMids frame that includes a mid for either side. Side names resolve once the adapter has loaded them (call initialize() first); until then they read "Side 0" and "Side 1". Each side carries name and parsedName, as in fetchPrice.
Parameters
Callback invoked whenever an
allMids frame includes a mid for either side of this outcome.Return type
Unsubscribe
subscribeTrades(marketId, cb)
Opens a real-time WebSocket subscription to the trade stream for side 0 of a market outcome. Each incoming trade is dispatched individually to your callback.
Parameters
Return type
Unsubscribe
Managing multiple subscriptions
You can hold multipleUnsubscribe functions and clean them all up together: