The Market Data Adapter (Documentation Index
Fetch the complete documentation index at: https://docs.outcome.xyz/llms.txt
Use this file to discover all available pages before exploring further.
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 methods accept a marketId, which is the outcome ID as a string (e.g. "516"). Order book and trade feeds target side 0 (the first side) by default.
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
The outcome ID as a string (e.g.
"516").Which side to fetch.
0 = first side (e.g. “Yes”), 1 = second side (e.g. “No”). Defaults to 0.Return type
Promise<PredictionOrderBook>
The outcome ID echoed back.
Buy-side price levels, each with
price (string) and size (string).Sell-side price levels, each with
price (string) and size (string).Server-side timestamp of the snapshot.
Example
fetchPrice(marketId)
Returns the current midpoint price for both sides of an outcome. Uses a 5-second cache backed by the allMids endpoint, so rapid successive calls avoid redundant network requests.
Parameters
The outcome ID as a string.
Return type
Promise<PredictionPrice>
The outcome ID echoed back.
One entry per side. Each entry contains:
name- generic label ("Side 0"or"Side 1"). For real side names, cross-referenceevent.markets[].outcomes[].name.price- current midpoint as a decimal string (0–1)."0"when no mid is available.midpoint- same value asprice(both fields are set identically).
Millisecond timestamp of the fetch.
The
name field returns generic labels ("Side 0", "Side 1"). To display real side names such as "Yes" or "Hypurr", fetch the event via adapter.events.fetchEvent() and cross-reference the outcome names by index.Example
fetchTrades(marketId, limit?)
Returns recent trades for a market outcome.
Parameters
The outcome ID as a string.
Maximum number of trades to return.
Return type
Promise<PredictionTrade[]>
Trade ID (from the Hyperliquid
tid field).The outcome ID.
Raw coin string (e.g.
"#5160")."buy" or "sell".Execution price as a decimal string.
Trade size.
Trade time in milliseconds.
Example
fetchCandles(marketId, interval?, start?, end?)
Returns OHLCV candle data for a market outcome.
Parameters
The outcome ID as a string.
Candle interval. Common values:
"1m", "5m", "15m", "1h", "4h", "1d".Start of the time range as a Unix millisecond timestamp. Defaults to 14 days before
end.End of the time range as a Unix millisecond timestamp. Defaults to the current time.
Return type
Promise<HLCandle[]> - each candle contains:
| Field | Type | Description |
|---|---|---|
t | number | Open time (ms) |
T | number | Close time (ms) |
o | string | Open price |
c | string | Close price |
h | string | High price |
l | string | Low price |
v | string | Volume |
n | number | Number of trades |
Example
subscribeOrderBook(marketId, cb)
Opens a real-time WebSocket subscription to the L2 order book for a market outcome. The callback receives a full book snapshot on each update.
Parameters
The outcome ID as a string.
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. Updates are delivered whenever either side’s mid changes in the allMids feed.
Parameters
The outcome ID as a string.
Callback invoked whenever an update includes a new mid for either side of this outcome.
Return type
Unsubscribe
subscribeTrades(marketId, cb)
Opens a real-time WebSocket subscription to the trade stream for a market outcome. Each incoming trade is dispatched individually to your callback.
Parameters
The outcome ID as a string.
Callback invoked for each individual trade.
Return type
Unsubscribe
Managing multiple subscriptions
You can hold multipleUnsubscribe functions and clean them all up together: