placeOrder reports validation and exchange rejections in its result instead of throwing, so you can branch on result.success.
Place a limit order
1
Initialize authentication
Generate or load an agent key and pass it to
initAuth. The agent key signs orders silently on behalf of the user’s wallet.The agent must be approved on-chain before trading. See the
auth-eoa.ts example in the SDK repository for the full approval flow using getAgentApprovalTypedData and submitAgentApproval.2
Fetch the market and side
Retrieve the market you want to trade. The
sides array on each market object carries the pre-computed coin identifier you pass to placeOrder.3
Place the limit order
Call
hip4.trading.placeOrder with the market ID, the side coin, and your price and amount. Pass markPx to enable pre-submission min-shares validation.4
Check the result
Inspect When Hyperliquid rejects the whole request,
result.success before reading other fields. The status field tells you whether the order filled immediately or is resting on the book.result.error is Exchange returned non-ok status. From 1.3.0, result.raw carries Hyperliquid’s own message, for example User or API Wallet 0x... does not exist. when the agent isn’t approved.Place a market order
For a market order, settype: "market" and omit price. The SDK uses the FrontendMarket time-in-force with extreme prices (0.99999 for buys, 0.00001 for sells) so the exchange handles best-execution.
Cancel an order
Pass an array of cancel targets tohip4.trading.cancelOrder. Each target requires the marketId and orderId. Pass the outcome coin too, so the SDK resolves the correct side. Without it, the SDK cancels on side 0.
cancelOrder throws when you aren’t authenticated, when you pass an empty array, or when the request itself fails (for example a network or HTTP error). Exchange-level rejections don’t throw: they come back in the returned Hyperliquid response, as status: "err" or as an { error } entry in response.data.statuses.Order params reference
Pricing rules
Tick-aligned prices: the SDK rounds limit prices to the outcome price tick before signing: at most 5 significant figures and at most 5 decimals (a tick of0.00001). "0.550012" becomes "0.55001" and "0.0123456" becomes "0.01235", so a price below 0.1 is never sent with 6 or more decimals. placeOrder and placeOrders both do this. To show or store the price the SDK will send, use the exported formatOutcomePrice:
MIN_NOTIONAL) before signing or sending them. To use a stricter floor, pass minOrderNotional to createHIP4Adapter. Without markPx, the SDK measures notional as price × amount. With markPx, it uses the cheaper side’s price, amount × max(0.01, min(markPx, 1 - markPx)), and also checks that amount is at least getMinShares(markPx). Set skipMinNotionalCheck: true to skip both checks.
Time-in-force options
Market orders always use
FrontendMarket regardless of the timeInForce field.
Builder fees
Builder fees let you attach a builder address and collect a fee on orders placed through your integration. SetbuilderFee in tenths of basis points (100 = 0.1%, maximum 1000) and provide builderAddress. A builder address without builderFee attaches the builder with a fee of 0. A builderFee is ignored when no builder address is set, either on the order or on the adapter.
builderAddress and builderFee once on createHIP4Adapter. Per-order values override them in placeOrder, while placeOrders always uses the adapter-level values. The user must first approve your builder’s maximum fee. See builder fee approval.