Utilities

Helper functions for formatting orders and resolving asset symbols, imported from @nktkas/hyperliquid/utils.

Format prices

formatPrice truncates a price to the Hyperliquid tick sizearrow-up-right precision.

import { formatPrice } from "@nktkas/hyperliquid/utils";

formatPrice("97123.456789", 0); // "97123"
formatPrice("1.23456789", 5); // "1.2"
formatPrice("0.0000123456789", 0, "spot"); // "0.00001234"

Format sizes

formatSize truncates a size to the asset lot sizearrow-up-right precision.

import { formatSize } from "@nktkas/hyperliquid/utils";

formatSize("1.23456789", 5); // "1.23456"
formatSize("0.123456789", 2); // "0.12"
formatSize("100", 0); // "100"

Resolve symbols

SymbolConverter maps human-readable symbols to Hyperliquid asset IDsarrow-up-right and formatting metadata. It fetches data from the API on creation.

Asset IDs

getAssetId returns the numeric ID used in order parameters:

Perpetuals use the coin name. Spot markets use "BASE/QUOTE" format. Returns undefined if the symbol is not found.

Size decimals

getSzDecimals returns the lot size precision for an asset:

Spot pair IDs

getSpotPairId returns the identifier used in info requests and subscriptions for spot markets:

Refresh data

Call reload to update the symbol mappings when new assets are listed:

Builder DEX support

Pass dexs to include assets from builder DEXsarrow-up-right:

Builder DEX assets use "DEX:ASSET" format:

Format and place an order

Last updated