Skip to main content
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.

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. Returns 0.00001 for a price of 0 or less.

roundToTick(price)

Rounds a price to the nearest tick boundary (5 significant figures).

formatPrice(price)

Formats a price as a tick-aligned string (5 significant figures) with trailing zeros stripped. Below 0.1 it can return 6 or more decimals, which HIP-4 outcome orders don’t accept, so use formatOutcomePrice for outcome prices. placeOrder uses formatOutcomePrice for limit prices.

formatOutcomePrice(price)

Formats a HIP-4 outcome price for the order wire: at most 5 significant figures and at most 5 decimals (a tick of 0.00001), with trailing zeros stripped. Accepts a number or a string, so user input never has to pass through a float. placeOrder and placeOrders apply it to limit prices, so you only need it to show or store the price that will be sent. Available from 1.3.0-beta.0.

stripZeros(str)

Removes trailing zeros from a numeric string.

getMinShares(markPx, minNotional?)

Returns the minimum number of shares required to meet the minimum notional at a given mark price. It divides by the cheaper side’s price, clamped to at least 0.01: ceil(minNotional / max(0.01, min(markPx, 1 - markPx))). minNotional defaults to MIN_NOTIONAL ($1).

MIN_NOTIONAL

The minimum order notional in USD. Currently 1. The SDK rejects limit orders below this threshold (or below the adapter’s higher minOrderNotional, if set) before submission.
Want a stricter floor than the protocol minimum? Don’t try to override MIN_NOTIONAL itself - it always reflects Hyperliquid’s real minimum. Instead, pass minOrderNotional to createHIP4Adapter to raise the client-side pre-submission floor for that adapter instance. See minOrderNotional in the Trading Adapter reference.

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. Returns null if the string isn’t a valid priceBinary description.

discoverPriceBinaryMarkets(meta, mids)

Scans raw outcomeMeta and returns the active recurring price binary markets as PriceBinaryMarket objects. A market is included when its description parses as priceBinary, its expiry is in the future, and mids has a price for its underlying.

periodMinutes(period)

Converts a period string to its equivalent number of minutes. Unrecognized strings return 15.

formatMarketLabel(market)

Returns a short human-readable label for a PriceBinaryMarket, combining the underlying asset and period.

timeToExpiry(market)

Returns the number of minutes until a PriceBinaryMarket expires, as a number. Negative means the market has already expired.

Market classification

These functions classify raw HIP-4 outcomes into typed HIP4Market objects.

classifyOutcome(outcome, questions, precomputedIndex?, templates?)

Classifies a single outcome from the raw API response. Returns a HIP4Market with the appropriate type discriminant. When you classify many outcomes in a loop, build the question index once with buildQuestionIndex(questions) and pass it as the third argument. name, sides[].name, and questionName are always the names Hyperliquid sends. Pass the outcomeTemplates registry (hip4.client.fetchOutcomeTemplates()) as the optional fourth argument to render readable parsedName, sides[].parsedName, and parsedQuestionName for template markets, as fetchMarkets does. Without it, the parsed fields keep the wire names, except that plain side names lose their template: prefix ("template:Yes" reads "Yes"). The parsed fields are available from 1.3.0.

classifyAllOutcomes(outcomes, questions, templates?)

Classifies all outcomes from a full outcomeMeta response. Returns an array of HIP4Market objects. The optional templates argument works as in classifyOutcome.

Coin helpers

HIP-4 uses a specific coin naming convention for order book lookups and order placement. These helpers encode and decode those identifiers.
Use sideCoin output (e.g. "#5160") as the outcome field when calling hip4.trading.placeOrder. hip4.marketData.fetchPrice takes the outcome ID as a string (e.g. "516"), not an @ coin.

Orderbook utilities

These functions estimate trade cost and potential return from token amounts and prices. You pass prices in cents (0 to 100).

computeEstimatedCost(tokenAmount, orderType, limitPriceCents, marketPriceCents?)

Estimates the USDC cost for a given token amount. For limit orders, uses limitPriceCents. For market orders, uses marketPriceCents when provided, otherwise returns tokenAmount as a fallback (the worst case of 1 USDC per share).

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 USDC 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: Historical candles always come from side 0. With sideIndex: 1, only the live ticks follow side 1.

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).