Skip to main content
Use the Hyperliquid integration to build agents that trade perpetual futures and spot markets. Common strategies include market making, momentum trading, and delta-neutral farming.

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 market field 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 following network 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 minimumAmount still ensures anyone running the agent allocates at least that amount.
  • This session’s invocation-start deployable perp collateral is the agent.allocation.balances entry carrying hyperliquidMetadata.collateral, and its open perps are in agent.allocation.positions (with hyperliquidMetadata - 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’s hyperliquidMetadata.marginUsed.

Units

When querying via Hyperliquid’s API (via agent.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 **10minimumnotional(size×price)oneveryorderopensandreduceonlyclosesalike.Circuitchecksthisbeforesubmitting,indryrunsandlive:asub10 minimum notional** (size × price) on every order - opens and reduce-only closes alike. Circuit checks this before submitting, in dry runs and live: a sub-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 with reduceOnly: true (the size can’t round up) - detect the case and skip.
Request Parameters:
  • coin (string): Asset identifier. For perps: "BTC". For builder DEX perps: "xyz:GOLD", "cash:GOLD", or "vntl:MAG7" (currently xyz, cash, and vntl are supported; unsupported builder DEX prefixes are rejected). For spot: the live spot listing name, e.g. "UBTC/USDC" - bridged majors are Unit assets with a U prefix (UBTC, UETH, USOL), while Hyperliquid-native tokens use their plain ticker ("HYPE/USDC", "PURR/USDC"). "BTC/USDC" does not exist and is rejected with Unknown spot pair.
  • side (string): “buy” or “sell”
  • size (number): Order size
  • price (number): Slippage limit for the immediate market order
  • market (string): “perp” or “spot”
  • type (string): Must be "market". Omitting type or using a resting/triggered type is rejected.
  • reduceOnly (boolean, optional): Whether this is a reduce-only order
  • leverage (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 with reduceOnly (a close opens nothing to lever). Omit to trade at the account’s current per-asset setting.
  • postOnly (boolean, optional): Must be omitted or false
  • message (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 each run start).
Auto-mode orders are idempotent by 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 succeeded
  • data (object): Order information (on success)
    • orderId (string): Order ID
    • coin (string): Asset identifier
    • side (string): “buy” or “sell”
    • price (number): Order price
    • size (number): Order size
    • filled (number): Filled amount
    • status (string): Order status
    • market (string): “perp” or “spot”
    • clientOrderId (string, optional): Client order ID (hex), when present
  • error (string | null): Error message (on failure)
In manual mode, the same 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 in agent.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 in agent.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.
Filter to HL perps with 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.
In manual mode the cancel is captured as a suggestion for the user to approve; 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’s allMids feed at call time.
Parameters:
  • 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 to hypercore:<dex>.
Response includes:
  • coin (string): The coin ticker that was matched.
  • network (string): Full market identifier - always hypercore:<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.
When 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 the error 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 price as a slippage limit (maximum acceptable execution price).
  • Spot coins use the live spot listing pair name - bridged majors are Unit assets with a U prefix ("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 midpointPrice in tight loops - fetch a coin’s mid once per cycle and reuse it.

See Also