Before continuing with this guide, make sure you have initialized your Hyperliquid client as shown
in the Getting Started guide. This guide assumes you have
client
and other basic setup completed.Overview
This guide covers essential trading patterns and techniques for building robust trading applications on Hyperliquid using Privy’s secure wallet infrastructure.Getting Market Data
Before placing trades, you’ll need to fetch asset metadata and current market conditions:Understanding Tick Size and Lot Size
Before placing orders, it’s critical to understand how Hyperliquid formats prices and sizes. Using incorrect precision will cause your orders to be rejected. Price Precision (Tick Size): Prices can have up to 5 significant figures, but no more thanMAX_DECIMALS - szDecimals decimal places:
- Perpetuals:
MAX_DECIMALS = 6 - Spot:
MAX_DECIMALS = 8
- ✅
1234.5is valid - ❌
1234.56is not valid (too many significant figures) - ✅
0.001234is valid - ❌
0.0012345is not valid (more than 6 decimal places)
szDecimals = 1:
- ✅
0.01234is valid - ❌
0.012345is not valid (more than6 - 1 = 5decimal places)
szDecimals of that asset. For example:
- If
szDecimals = 3, then1.001is valid but1.0001is not - If
szDecimals = 2, then10.25is valid but10.251is not
szDecimals for each asset in the meta response:
Important: When implementing signing, trailing zeroes should be removed from prices and sizes.
See the Hyperliquid tick and lot size
documentation
for more details.
Order Types
Market Orders
Hyperliquid doesn’t have traditional market orders, but you can achieve market-like execution by placing a limit order withtif: "Ioc" (Immediate-Or-Cancel) and a price that guarantees immediate execution:
- For buys: Set limit price ≥ current best ask
- For sells: Set limit price ≤ current best bid
Limit Orders
Place an order at a specific price. Limit orders let you control the exact price at which you’re willing to buy or sell.a(asset): The asset index frommeta.universe. For example,0is typically BTC.b(buy/sell):truefor buy orders,falsefor sell orders.p(price): Limit price as a string. Must follow tick size rules (see above).s(size): Order size as a string. Must follow lot size rules based onszDecimals.r(reduce-only): Iftrue, order can only reduce existing position, not open new positions.t(order type): Object specifying order type and parameters.grouping: Order grouping strategy, typically"na"for standard orders.
tif parameter in limit orders controls how long the order remains active:
Gtc (Good-'Til-Canceled)
Gtc (Good-'Til-Canceled)
Fills what it can immediately; any remainder stays on the order book until filled or manually canceled. This is the most common option for limit orders.
Ioc (Immediate-Or-Cancel)
Ioc (Immediate-Or-Cancel)
Fills immediately up to your limit price; any unfilled remainder is automatically canceled. The order never rests on the book. Useful for ensuring immediate execution without leaving open orders.
Alo (Add-Liquidity-Only / Post-Only)
Alo (Add-Liquidity-Only / Post-Only)
Must add liquidity to the order book. If the order would cross the spread and immediately match (take liquidity), it’s rejected/canceled instead. This guarantees you receive maker fees rather than paying taker fees.
Stop Loss and Take Profit Orders
You can create linked TP/SL (Take Profit/Stop Loss) orders that trigger when price reaches specific levels. Usegrouping: "normalTpsl" to link the entry order with its stop-loss and take-profit exit orders.
triggerPx and p (limit price) serve different purposes in TP/SL orders:
triggerPx: The price level that activates the orderp(limit price): The worst price you’re willing to accept once triggered
p) below the trigger to allow for slippage during fast price movements. In the example above, the stop-loss triggers at $95,000 but will execute at $94,000 or better.
For take-profit orders, you can set a more conservative limit price to ensure execution. The take-profit triggers at $105,000 but will accept $101,200 or better.
This approach ensures your orders execute even in volatile conditions while still providing some price protection.
When one of the TP/SL orders executes (either stop-loss or take-profit), the other is
automatically canceled. The
r: true (reduce-only) flag ensures these orders can only close
positions, not open new ones.TWAP Orders
TWAP (Time-Weighted Average Price) orders split large orders into smaller chunks executed over time to minimize market impact and reduce slippage.a(asset): The asset index frommeta.universeb(buy/sell):truefor buy orders,falsefor sell orderss(size): Total size to execute across all chunksr(reduce-only): Iftrue, order can only reduce existing positionsm(minutes): Duration over which to execute the order (e.g., 30 = 30 minutes)t(randomize): Iftrue, randomizes timing between chunks to make execution less predictable; iffalse, chunks are evenly spaced
TWAP orders are ideal for executing large orders without significantly moving the market. The
order is automatically split into smaller chunks and executed at regular (or randomized) intervals
over the specified duration.
Risk Management
Hyperliquid supports two margin modes: cross margin and isolated margin.- Cross Margin: Uses your total perps balance as collateral across all positions. If one position loses money, other positions can help cover the loss.
- Isolated Margin: Margin is isolated to each individual position. If a position is liquidated, it won’t affect your other positions.
Monitoring and Analytics
Get comprehensive information about your account balance, open positions, and risk metrics:Best Practices
Always validate prices
Always validate prices
Before placing orders, verify that prices are within expected ranges to avoid fat-finger errors.
Use reduce-only orders for exits
Use reduce-only orders for exits
When closing positions, use reduce-only orders to prevent accidentally opening new positions.
Monitor funding rates
Monitor funding rates
Keep track of funding rates, especially for large positions, as they can significantly impact
profitability.
Implement circuit breakers
Implement circuit breakers
Add safeguards to stop trading if certain thresholds are hit (e.g., max daily loss, max position
size).

