← All articles

Hyperliquid tick size and szDecimals in Node.js: valid prices, sizes and “Price must be divisible by tick size”

Hyperliquid prices must satisfy the significant-figure limit and the decimal-place limit for the asset. Order sizes must fit szDecimals. A mid price calculated from valid bids and asks can still fail price validation.

The Hyperliquid tick size rules

Hyperliquid’s tick and lot size page sets out the rules:

  • Prices can have up to 5 significant figures, and no more than MAX_DECIMALS - szDecimals decimal places, where MAX_DECIMALS is 6 for perps and 8 for spot.
  • Whole-number prices are always allowed, however many digits they have. 123456 is valid even though 12345.6 isn’t.
  • Sizes can have at most szDecimals decimal places. With szDecimals = 3, 1.001 is valid and 1.0001 isn’t.

So the effective tick depends on both the asset and the price level. A few examples from the docs:

Market szDecimals Valid Not valid Why
Perp any 1234.5 1234.56 Six significant figures
Perp 0 0.001234 0.0012345 More than 6 decimal places
Perp 1 0.01234 0.012345 More than 6 – 1 = 5 decimal places
Spot 2 0.000123 0.0001234 More than 8 – 2 = 6 decimal places

Hyperliquid’s error responses page lists the per-order message as Price must be divisible by tick size. It also notes that some forms of tick size validation happen earlier, in pre-validation, in which case a single error comes back for the whole payload rather than one per order. Handle both.

Reading szDecimals with the SDK

Install the SDK with npm install @siebly/hyperliquid-api. Public metadata needs no key.

The quickest route is resolveAsset(), which takes the name you’d use in an order and returns the asset ID, its canonical name, the market kind and szDecimals:

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

const client = new RestClient();

console.log(await client.resolveAsset('BTC'));
// { assetId: 0, canonicalName: 'BTC', kind: 'perp', szDecimals: 5 }

console.log(await client.resolveAsset('HYPE/USDC'));
// { assetId: 10107, canonicalName: '@107', kind: 'spot', szDecimals: 2 }

If you want every perp at once, getPerpMetadata() returns the full universe, and each entry carries its szDecimals:

const meta = await client.getPerpMetadata();
const btc = meta.universe.find((asset) => asset.name === 'BTC');
console.log(btc.szDecimals); // 5

For spot pairs, getSpotMetadata() returns the token and pair lists; resolveAsset() saves you mapping a name like HYPE/USDC to its @107 index yourself. Here is what a few markets look like on mainnet, and what that means for prices:

Symbol Kind szDecimals Max price decimals Example valid price (2% below the mid)
BTC perp 5 1 58599 (5 integer digits, so whole numbers only)
ETH perp 4 2 1647.6 (5 significant figures wins)
SOL perp 2 4 68.332
HYPE perp 2 4 59.32
kPEPE perp 0 6 0.003339
HYPE/USDC (@107) spot 2 6 59.314

szDecimals can change when a market is updated, so read it from metadata at start-up (and refresh it now and then) rather than hard-coding it.

Why the mid price is often not a valid price

getAllMids() returns the midpoint between the best bid and ask. A midpoint can carry one more digit than either side of the book. On 25 November the BTC mid came back as 59795.5, ETH as 1681.25 and HYPE as 60.5315. Each of those has six significant figures, so none of them is a valid order price on its own. If your bot sets price = mids.BTC, or adds a percentage to the mid without rounding, it will be rejected intermittently: only when the mid happens to land on a half tick. That makes it a frustrating bug to reproduce.

The fix is to round every computed price before you send it, and to round in the direction that keeps the order on the side you meant: down for buys, up for sells.

A price and size helper for Node.js

These two functions apply the documented rules. They are plain JavaScript with no dependencies:

// Round a price to what Hyperliquid accepts for this asset.
// kind is 'perp', 'spot' or 'hip3', as returned by client.resolveAsset().
function toHyperliquidPrice(raw, szDecimals, kind, direction) {
  const maxDecimals = (kind === 'spot' ? 8 : 6) - szDecimals;
  // Position of the first significant digit: 4 for 1234.5, 0 for 0.5, -2 for 0.0012
  const intDigits = Math.floor(Math.log10(Math.abs(raw))) + 1;
  // 5 significant figures, but never more than maxDecimals decimal places.
  // Prices with 5 or more integer digits become whole numbers, which are always valid.
  const decimals = Math.max(0, Math.min(maxDecimals, 5 - intDigits));
  const factor = 10 ** decimals;
  const scaled = raw * factor;
  const rounded =
    direction === 'down' ? Math.floor(scaled + 1e-9) : Math.ceil(scaled - 1e-9);
  return String(Number((rounded / factor).toFixed(decimals)));
}

// Truncate a size to szDecimals. Never round a size up.
function toHyperliquidSize(raw, szDecimals) {
  const [int, frac = ''] = String(raw).split('.');
  const cut = frac.slice(0, szDecimals).replace(/0+$/, '');
  return cut ? `${int}.${cut}` : int;
}

toHyperliquidPrice(1234.56, 0, 'perp', 'down');    // '1234.5'
toHyperliquidPrice(0.0012345, 0, 'perp', 'down');  // '0.001234'
toHyperliquidPrice(0.0001234, 2, 'spot', 'down');  // '0.000123'
toHyperliquidPrice(123456.7, 0, 'perp', 'down');   // '123456'
toHyperliquidSize('1.0001', 3);                    // '1'

The small 1e-9 nudge stops floating-point noise (in JavaScript 4.35 * 100 is 434.99999999999994) from knocking a valid price down a tick. The helper returns strings, because the SDK’s order methods take price and size as decimal strings, and it never emits trailing zeros. Hyperliquid’s docs point out that trailing zeros must be removed if you implement signing yourself; the SDK canonicalises the strings it signs, but clean inputs make logs easier to compare.

HIP-3 markets resolve with kind: 'hip3'. They are perps, and the helper (like the SDK’s own market order code) applies the perp limit of 6 to them.

Placing a limit order with a valid price

Put it together: resolve the asset, round the price and size, check the $10 minimum, then place the order and check both levels of failure. Use a testnet API wallet while you try this out.

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

const client = new RestClient({
  privateKey: process.env.HYPERLIQUID_API_WALLET_KEY,
  accountAddress: process.env.HYPERLIQUID_ACCOUNT_ADDRESS,
  testnet: true,
});

const asset = await client.resolveAsset('ETH');
const mids = await client.getAllMids();
const szDecimals = asset.szDecimals ?? 0;

// A post-only bid 3% below the mid, rounded down
const price = toHyperliquidPrice(
  Number(mids[asset.canonicalName]) * 0.97,
  szDecimals,
  asset.kind,
  'down',
);
const size = toHyperliquidSize('0.0123456', szDecimals);

if (Number(price) * Number(size) < 10) {
  throw new Error(`Order value is below Hyperliquid's $10 minimum`);
}

try {
  const result = await client.submitLimitOrder({
    symbol: 'ETH',
    side: 'buy',
    price,
    size,
    postOnly: true,
  });

  if (result.status === 'ok') {
    const [status] = result.response.data.statuses;
    if ('error' in status) {
      console.error('Order rejected:', status.error);
    } else if ('resting' in status) {
      console.log('Resting, oid', status.resting.oid);
    } else {
      console.log('Filled', status.filled.totalSz, '@', status.filled.avgPx);
    }
  }
} catch (e) {
  if (e instanceof HyperliquidApiError) {
    // The whole action was refused (pre-validation, signature, unknown wallet...)
    console.error('Request rejected:', e.message);
  } else {
    throw e;
  }
}

The minimum order value comes from the same error table: Order must have minimum value of $10. for perps, and 10 units of the quote token for spot. Checking it locally saves a round trip and a confusing log line.

submitMarketOrder rounds for you, submitLimitOrder doesn’t

The SDK’s helpers behave differently here, and it’s worth knowing which one you’re calling.

  • submitMarketOrder() sends an IOC order around the current mid. In version 1.0.5 it works out the limit price from the mid and maxSlippage (a fraction, 0.05 by default), rounds that price to 5 significant figures and the allowed decimal places for the asset, and truncates your size to szDecimals. So size: '0.0123456' on ETH goes out as 0.0123.
  • submitLimitOrder() sends exactly the price and size you pass (it only checks that they are positive decimals). Rounding is your job, which is what the helper above is for. The same goes for the lower-level submitOrder() and for modifyOrder().
// Price and size are rounded inside the SDK
await client.submitMarketOrder({
  symbol: 'ETH',
  side: 'buy',
  size: '0.0123456', // sent as 0.0123
  maxSlippage: 0.01,
});

If you pass a size that truncates to zero (say 0.000001 BTC with szDecimals = 5), submitMarketOrder() throws a RangeError before anything is signed, so check your sizing maths rather than catching that in production.

Check the signer before testing a price

Hyperliquid can reject an unknown signer before it validates the price. Use an approved API wallet on a funded testnet account to exercise exchange-side price validation. The rounding helper can be tested locally against public market metadata.

Checklist

  • Load szDecimals for each symbol from metadata at start-up, and refresh it periodically.
  • Never send getAllMids() values, or percentages of them, without rounding.
  • Round buy prices down and sell prices up; truncate sizes.
  • Use 6 as MAX_DECIMALS for perps (including HIP-3) and 8 for spot.
  • Remember that whole-number prices are always valid, which is why BTC prices are whole dollars at today’s levels.
  • Check price × size against the $10 minimum before sending.
  • Handle both a thrown HyperliquidApiError and a per-order { error } status.

Further reading

The Hyperliquid JavaScript tutorial covers API wallet setup, account state, orders and WebSockets end to end, and the Hyperliquid SDK docs list every REST and WebSocket method. To make retries safe once your prices are right, see Hyperliquid cloid and scheduleCancel in Node.js. The SDK is open source under the MIT licence, from the same maintainers as the binance, bybit-api and okx-api packages, with over 4.5 million npm downloads across 10+ SDKs.