@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
37 lines • 1.52 kB
TypeScript
/**
* Format price according to Hyperliquid [rules](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size):
* - Maximum 5 significant figures
* - Maximum 6 (for perp) or 8 (for spot) - `szDecimals` decimal places
* - Integer prices are always allowed regardless of significant figures
*
* @param price - The price to format (as string or number).
* @param szDecimals - The size decimals of the asset.
* @param type - The market type: "perp" for perpetuals or "spot" for spot markets. Default is "perp".
*
* @throws {RangeError} If the formatted price is 0
*
* @example
* ```ts
* import { formatPrice } from "@nktkas/hyperliquid/utils";
* const price = formatPrice("0.0000123456789", 0, "spot"); // → "0.00001234"
* ```
*/
export declare function formatPrice(price: string | number, szDecimals: number, type?: "perp" | "spot"): string;
/**
* Format size according to Hyperliquid [rules](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size):
* - Truncate decimal places to `szDecimals`
*
* @param size - The size to format (as string or number).
* @param szDecimals - The size decimals of the asset.
*
* @throws {RangeError} If the formatted size is 0
*
* @example
* ```ts
* import { formatSize } from "@nktkas/hyperliquid/utils";
*
* const size = formatSize("1.23456789", 5); // → "1.23456"
* ```
*/
export declare function formatSize(size: string | number, szDecimals: number): string;
//# sourceMappingURL=format.d.ts.map