---
title: "Hyperliquid REST Rounding JavaScript SDK Example | Siebly"
description: "Hyperliquid REST rounding JavaScript example for the Siebly Hyperliquid SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs."
canonical: "https://siebly.io/examples/Hyperliquid/Rest/rest-rounding"
robots: "index,follow"
---

# Hyperliquid REST Rounding JavaScript SDK Example

Hyperliquid REST rounding JavaScript example for the Siebly Hyperliquid SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

**Path:** [Home](/) / [Examples](/examples) / [Hyperliquid](/examples/Hyperliquid) / [Rest](/examples/Hyperliquid/Rest) / [rest-rounding.ts](/examples/Hyperliquid/Rest/rest-rounding)

[View source on GitHub](https://github.com/sieblyio/hyperliquid-api/blob/main/examples/Rest/rest-rounding.ts)

[Open the Hyperliquid JavaScript SDK guide](/sdk/hyperliquid/javascript)

## rest-rounding.ts

```typescript
import { RestClient } from '@siebly/hyperliquid-api';

// or
// import { RestClient } from '@siebly/hyperliquid-api';

/**
 * Hyperliquid tick/lot rules, for when you send raw submitOrder() wires.
 *
 * submitMarketOrder() already rounds size down and builds the IOC protection
 * price. Use this example when you need the same rules for a manual wire.
 *
 * Prices: 5 significant figures, at most 6 (perp) or 8 (spot) minus szDecimals.
 * Integer prices are always allowed.
 *
 * npx tsx examples/Rest/rest-rounding.ts
 */
const client = new RestClient({ testnet: true });

function roundPrice(
  px: number,
  szDecimals: number,
  maxDecimals: number,
): number {
  if (px > 100_000) {
    return Math.round(px);
  }
  const decimals = maxDecimals - szDecimals;
  return Number(Number(px.toPrecision(5)).toFixed(decimals));
}

async function main() {
  try {
    const meta = await client.getPerpMetadata();
    const szDecimals = Object.fromEntries(
      meta.universe.map((asset) => [asset.name, asset.szDecimals]),
    );
    console.log('sample szDecimals', {
      BTC: szDecimals.BTC,
      ETH: szDecimals.ETH,
      OP: szDecimals.OP,
    });

    const coin = 'OP';
    const maxDecimals = 6;
    const px = roundPrice(
      1.2345678,
      Number(szDecimals[coin] ?? 0),
      maxDecimals,
    );
    const sz = Number((12.345678).toFixed(Number(szDecimals[coin] ?? 0)));
    console.log('rounded px/sz for', coin, px, sz);

    const asset = await client.resolveAsset(coin);
    console.log('resolved asset:', asset);
  } catch (e) {
    console.error('request failed: ', e);
  }
}

main();
```
