Account Model
Every Circuit Hyperliquid account runs in Hyperliquid’s unified account mode: one USDC balance collateralizes spot trading, perp positions, and builder-DEX markets alike. Circuit enforces this automatically - the platform enables unified mode the first time it operates an account, so you never manage it. Practical consequences:- There are no separate “spot” and “perp” balances and no transfer between them. Deposited USDC is immediately usable as perp margin and for spot orders - just place orders.
- “Spot” vs “perp” still matters for markets (the
marketfield on orders and the coin format:"BTC"for perps,"HYPE/USDC"for spot pairs), not for where your cash lives. - Balance reads report the one pooled USDC collateral. Free cash for leaving the venue / funding is egress free (after margin locks), not the full pool; size sends and Max from the sendable figure (egress free after a small reserve), not from total collateral.
Configuration
To define USDC Perps as your agent’s starting asset, use the followingnetwork and address in the circuit.toml file.
minimumAmount for hypercore:perp / USDC is in Circuit raw units with 8 decimal places, matching Hyperliquid’s weiDecimals for USDC in spot metadata (not EVM USDC’s 6 decimals).
Asset Allocation Notes
A Hyperliquid session is allocated a slice of the wallet’s USDC collateral, just like a spot agent is allocated a slice of a token. Multiple Hyperliquid agents can run on one wallet, each drawing from the unallocated remainder. Because the account nets all positions, agents on the same wallet share liquidation risk - size and monitor positions accordingly. A few quirks to be aware of:- You allocate a portion of the wallet’s available Hyperliquid USDC to the session (not the whole wallet). The
minimumAmountstill ensures anyone running the agent allocates at least that amount. - This session’s invocation-start deployable perp collateral is the
agent.allocation.balancesentry carryinghyperliquidMetadata.collateral, and its open perps are inagent.allocation.positions(withhyperliquidMetadata- leverage / liquidation price / margin used). Size from this session slice - never a whole-wallet read, which on a shared wallet would overspend the other sessions sharing it. - The collateral amount is total collateral - it includes margin already locked in open positions and excludes unrealized PnL. For session collateral (kill-switch / drawdown math), add each open position’s
unrealizedPnlUsd- a losing book’s negative PnL must pull session collateral down, or the rail fires late. For free margin to size new orders, additionally subtract each position’shyperliquidMetadata.marginUsed.
Units
When querying via Hyperliquid’s API (viaagent.platforms.hyperliquid), all values will be returned in their formatted value, as opposed to the rest of Circuit which returns values in their raw units (wei/lamports)
Place Order
If you are unfamiliar with placing orders via Hyperliquid’s API, please see these docs for information regarding tick/lot sizes, as well as decimals. Hyperliquid enforces a **10 order fails immediately with a descriptive error instead of a live venue rejection. A position whose value has decayed below $10 cannot be closed withreduceOnly: true (the size can’t round up) - detect the case and skip.
coin(string): Asset identifier. For perps:"BTC". For builder DEX perps:"xyz:GOLD","cash:GOLD", or"vntl:MAG7"(currentlyxyz,cash, andvntlare supported; unsupported builder DEX prefixes are rejected). For spot: the live spot listing name, e.g."UBTC/USDC"- bridged majors are Unit assets with aUprefix (UBTC,UETH,USOL), while Hyperliquid-native tokens use their plain ticker ("HYPE/USDC","PURR/USDC")."BTC/USDC"does not exist and is rejected withUnknown spot pair.side(string): “buy” or “sell”size(number): Order sizeprice(number): Slippage limit for the immediate market ordermarket(string): “perp” or “spot”type(string): Must be"market". Omittingtypeor using a resting/triggered type is rejected.reduceOnly(boolean, optional): Whether this is a reduce-only orderleverage(integer, optional, perp only, fresh positions only): Set the account’s cross leverage for this coin (1 up to the asset’s max) before the order places. The dial is per coin per wallet, so leverage can only be set when OPENING a fresh position — the order is refused when the wallet already has an open position on the coin (omit leverage to trade at the position’s current leverage, or use a wallet without one). Also refused above the asset’s max and withreduceOnly(a close opens nothing to lever). Omit to trade at the account’s current per-asset setting.postOnly(boolean, optional): Must be omitted orfalsemessage(string, optional): Short human-readable message for this order, max 250 characters. Stored verbatim and rendered as the Activity-feed caption for this trade. When omitted, the caption is synthesized from recent agent logs.idempotencyKey(string, optional): Durable retry key for auto-mode orders. SDKs generate one automatically; provide a stable key only when retrying the same logical order after a process restart.expiresAt(string | null, optional): ISO 8601 timestamp. In manual mode, the suggestion expires at this time. If omitted, no time-based expiry is set (suggestions are auto-cleared at eachrunstart).
idempotencyKey within the current agent run. Duplicate active or already-submitted attempts are rejected; only failures before any external side effect can retry under the same key.
Circuit supports immediate non-post-only Hyperliquid market orders only, including approved manual-mode suggestions and direct wallet-owner operations.
Response:
success(boolean): Whether the operation succeededdata(object): Order information (on success)orderId(string): Order IDcoin(string): Asset identifierside(string): “buy” or “sell”price(number): Order pricesize(number): Order sizefilled(number): Filled amountstatus(string): Order statusmarket(string): “perp” or “spot”clientOrderId(string, optional): Client order ID (hex), when present
error(string | null): Error message (on failure)
HyperliquidPlaceOrderResponse is returned and data is a suggestion envelope ({ suggested: true, suggestionId }) instead of order information. See Manual vs Auto Mode.
Example:
Reading balances
This session’s deployable perp cash at invocation start is inagent.allocation.balances. A whole-wallet read would return every session’s share, so agents size from this scoped allocation instead. The perp-margin USDC balance is the one entry carrying hyperliquidMetadata.collateral (spot / staking balances carry no metadata - read network). amountRaw is in raw base units; divide by 10 ** decimals for the human amount. The amount includes locked margin and excludes unrealized PnL - see Asset Allocation Notes for the session-collateral and free-margin formulas.
Reading positions
Open perps at invocation start are inagent.allocation.positions. A whole-wallet read would return every session’s netted perp, so agents use their own scoped share instead. Each Hyperliquid perp position carries:
coin(string),size(string, signed - long > 0, short < 0),averageEntryPrice(string | null),markPriceUsd(string | null),unrealizedPnlUsd(string | null)hyperliquidMetadata(object | undefined) - HL perp detail:leverage(string),liquidationPrice(string | null),marginUsed(string). Wallet-level (shared across sessions on the same wallet). Best-effort: absent if the live enrichment read failed.
network === "hypercore:perp" (the array also holds Polymarket positions). For a current price, fetch a live mid (midpointPrice).
Delete Order
Cancel an order.idempotencyKey(string, optional): Durable retry key for auto-mode cancels. SDKs generate one automatically; provide a stable key only when retrying the same logical cancel after a process restart.
data is then a suggestion envelope ({ suggested: true, suggestionId }). See Manual vs Auto Mode.
Example:
Midpoint Price
Get the current midpoint price for one or more Hyperliquid coins. The return shape mirrors the input shape: pass a single coin to get a single object, or pass an array to get an array (one entry per coin that has data). Prices are read live from Hyperliquid’sallMids feed at call time.
coin(string | string[]): Coin ticker(s), e.g."BTC"or["BTC", "ETH"]. For spot pairs use the"BASE/QUOTE"format (e.g."HYPE/USDC"). For builder-DEX coins, pass just the base ticker (e.g."GOLD").dex(string, optional): Hyperliquid market suffix. Defaults to"perp"(main perp DEX). Use"spot"for spot or a builder-DEX name like"xyz","cash", or"vntl". Internally translated tohypercore:<dex>.
coin(string): The coin ticker that was matched.network(string): Full market identifier - alwayshypercore:<dex>(e.g."hypercore:perp").priceUsd(string): Midpoint price in USD as a decimal string (preserve precision).timestamp(string): ISO 8601 timestamp of the live read.
coin is a single string and no row exists for the requested (coin, dex), success is false and error describes the miss. When coin is an array, missing coins are silently omitted from the response array.
Example:
Common Errors
Errors are returned in theerror field of the response. Common errors include:
Note: Additional error messages may be returned by Hyperliquid’s API. Check the
error field in the response for specific details.
Notes
- All balance and position amounts are strings to preserve precision.
- Market orders use
priceas a slippage limit (maximum acceptable execution price). - Spot coins use the live spot listing pair name - bridged majors are Unit assets with a
Uprefix ("UBTC/USDC","UETH/USDC","USOL/USDC"), Hyperliquid-native tokens their plain ticker ("HYPE/USDC","PURR/USDC") - while perp coins use just the base asset like"BTC". - Hyperliquid rate-limits aggressively. Avoid calling
midpointPricein tight loops - fetch a coin’s mid once per cycle and reuse it.
See Also
- Hyperliquid Agent Example - Full working trading agent
- Wallets & Asset Allocation - How Hyperliquid collateral is allocated per session
- Suggestions - Control suggestion expiry for manual-mode order suggestions