The SDK exports a set of standalone utility functions alongside the main adapter. These functions have no side effects and no dependency on an initialized adapter instance - import and call them directly. They cover four areas: tick-aligned price formatting, market discovery and classification, coin name encoding, and orderbook cost estimation. Two stream constructors for live chart feeds are also covered here.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.
Pricing utilities
These functions handle Hyperliquid’s magnitude-based decimal precision and minimum order size constraints.computeTickSize(price)
Returns the tick size for a given price using 5 significant figures.
roundToTick(price)
Rounds a price to the nearest tick boundary.
formatPrice(price)
Formats a price as a tick-aligned string with trailing zeros stripped. Prices below 1 receive 4 decimal places.
stripZeros(str)
Removes trailing zeros from a numeric string.
getMinShares(markPx)
Returns the minimum number of shares required to meet the 10 USDH minimum notional for a given mark price.
MIN_NOTIONAL
The minimum order size in USDH. Currently 10. Orders below this threshold are rejected before submission.
Market discovery
These functions help you find and describe recurring HIP-4 markets from raw metadata.parseDescription(desc)
Parses a pipe-delimited recurring market description string into a structured object.
discoverPriceBinaryMarkets(meta)
Scans raw outcomeMeta and returns all outcomes that are recurring price binary markets.
periodMinutes(period)
Converts a period string to its equivalent number of minutes.
formatMarketLabel(market)
Returns a short human-readable label for a market, combining the underlying asset and period.
timeToExpiry(expiry)
Returns a human-readable string describing how long until a market expires.
Market classification
These functions classify raw HIP-4 outcomes into typedHIP4Market objects.
classifyOutcome(outcome, questions)
Classifies a single outcome from the raw API response. Returns a HIP4Market with the appropriate type discriminant.
classifyAllOutcomes(meta)
Classifies all outcomes from a full outcomeMeta response. Returns an array of HIP4Market objects.
Coin helpers
HIP-4 uses a specific coin naming convention for order book lookups and order placement. These helpers encode and decode those identifiers.| Helper | Example output | Description |
|---|---|---|
sideCoin(outcomeId, sideIndex) | "#5160" | Tradeable side coin string |
sideAssetId(outcomeId, sideIndex) | 100005160 | Numeric asset ID for order wire format |
parseSideCoin(coin) | { outcomeId: 516, sideIndex: 0 } | Decode a side coin string |
outcomeCoin(outcomeId) | "@516" | Outcome-level coin for price lookups |
Use
sideCoin output (e.g. "#5160") as the outcome field when calling hip4.trading.placeOrder. Use outcomeCoin output (e.g. "@516") for price lookups via hip4.marketData.fetchPrice.Orderbook utilities
These functions estimate trade cost and potential return from token amounts and prices. Prices are expressed in cents (0–100 range) internally.computeEstimatedCost(tokenAmount, orderType, limitPriceCents, marketPriceCents?)
Estimates the USDH cost for a given token amount. For limit orders, uses limitPriceCents. For market orders, uses marketPriceCents when provided, otherwise returns tokenAmount as a fallback.
computeTradeCost(params)
Returns a TradeCostResult with all three values needed to display a trade preview.
computePotentialReturn(tokenAmount)
Returns the maximum payout for a given number of shares. Each share pays 1 USDH if the outcome resolves in your favor.
Price feed streams
These constructors create continuously-updating chart feeds by merging historical candle data with real-time WebSocket ticks.createPriceFeed(marketData, marketId, onSnapshot, options?)
Creates a live price feed for a single prediction market outcome. Returns an unsubscribe function.
PriceFeedSnapshot fields:
| Field | Type | Description | |
|---|---|---|---|
marketId | string | The market ID passed to the constructor | |
candles | PriceFeedCandle[] | Full candle array (historical + live updates) | |
currentMid | `number | null` | Latest mid-price tick; may be newer than the last candle |
ready | boolean | false until the initial historical candle fetch completes |
createPerpPriceFeed(client, coin, onSnapshot, options?)
Creates a live price feed for a perpetual market coin (e.g. "BTC", "ETH"). Uses the candle WebSocket channel for authoritative OHLCV data and allMids for the initial mid-price.
PerpPriceFeedSnapshot differs from PriceFeedSnapshot in its coin field (instead of marketId).