Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.circuit.org/llms.txt

Use this file to discover all available pages before exploring further.

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.

Configuration

To define USDC Perps as your agent’s starting asset, use the following network and address in the circuit.toml file.
[startingAsset]
network = "hypercore:perp"
address = "USDC"
minimumAmount = "100000000"  # 1 USDC (8 decimals)
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

Circuit restricts users from running multiple Hyperliquid agents per wallet. This enables your agent to safely manage margin requirements on open perpetual positions without potential interference from other agents. This also introduces a few quirks to be aware of.
  • For Hyperliquid agents, your entire wallet balance is available to the agent when you start a session.
  • The minimumAmount will still ensure that anyone running the agent will at least have that amount.
  • Your agent should use the below methods to pull available balances/positions directly from Hyperliquid, as opposed to the agent.currentPositions property.
    • Balances: agent.platforms.hyperliquid.balances()
    • Positions: agent.platforms.hyperliquid.positions(dex?)
    • IMPORTANT: Be careful with your usage of these methods in loops (avoid entirely if possible), Hyperliquid will rate limit if too many requests are sent.
    • Note: Hyperliquid balances are not yet included in agent.currentPositions. This will be added in a future release once Circuit’s Hyperliquid indexing is complete.

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.
def place_order(request: HyperliquidPlaceOrderRequest | dict) -> HyperliquidPlaceOrderResponse
Request Parameters:
  • symbol (string): Trading pair symbol. 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: "BTC/USDC".
  • side (string): “buy” or “sell”
  • size (number): Order size
  • price (number): Order price. For market orders, acts as slippage limit (maximum acceptable execution price). For limit orders, the limit price.
  • market (string): “perp” or “spot”
  • type (string, optional): “market”, “limit”, “stop”, “take_profit”
  • triggerPrice (number, optional): Trigger price for stop/take-profit orders
  • reduceOnly (boolean, optional): Whether this is a reduce-only order
  • postOnly (boolean, optional): Whether this is a post-only order
  • 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.
  • 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).
Response:
  • success (boolean): Whether the operation succeeded
  • data (object): Order information (on success)
    • orderId (string): Order ID
    • symbol (string): Trading pair symbol
    • 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”
  • error (string | null): Error message (on failure)
Example:
# Perp market order
perp_order = agent.platforms.hyperliquid.place_order({
    "symbol": "BTC",
    "side": "buy",
    "size": 0.0001,
    "price": 110000,  # Acts as slippage limit for market orders
    "market": "perp",
    "type": "market"
})

if perp_order.success and perp_order.data:
    agent.log(f"Perp Order {perp_order.data.orderId}: {perp_order.data.status}")

# Spot market order
spot_order = agent.platforms.hyperliquid.place_order({
    "symbol": "BTC/USDC",
    "side": "buy",
    "size": 0.0001,
    "price": 110000,  # Acts as slippage limit for market orders
    "market": "spot",
    "type": "market"
})

Balances

Get account balances.
def balances() -> HyperliquidBalancesResponse
Response:
  • success (boolean): Whether the operation succeeded
  • data.perp (object): Perp account balance
    • accountValue (string): Total account value
    • totalMarginUsed (string): Total margin used
    • withdrawable (string): Withdrawable amount
  • data.spot (array): Spot token balances
    • coin (string): Token symbol
    • total (string): Total balance
    • hold (string): Amount on hold (in open orders)
  • error (string | null): Error message (on failure)
Example:
balances = agent.platforms.hyperliquid.balances()
if balances.success and balances.data:
    agent.log(f"Account value: {balances.data.perp.accountValue}")
    agent.log(f"Withdrawable: {balances.data.perp.withdrawable}")

    for token in balances.data.spot:
        agent.log(f"{token.coin}: {token.total} (hold: {token.hold})")

Positions

Get open positions. By default this returns positions across Hyperliquid’s main perp venue and any supported builder DEXes. Currently the supported builder DEXes are xyz, cash, and vntl. Pass dex to scope the response to a specific builder DEX.
def positions(dex: str | None = None) -> HyperliquidPositionsResponse
Parameters:
  • dex (string, optional): Builder DEX name to filter positions for a specific venue, such as "xyz", "cash", or "vntl". If omitted, positions are returned across the default venue and supported builder DEXes. Currently that supported builder DEX set is "xyz", "cash", and "vntl", and unsupported builder DEX names are rejected.
Response:
  • success (boolean): Whether the operation succeeded
  • data (array): Array of open positions
    • symbol (string): Trading pair symbol
    • side (string): “long” or “short”
    • size (string): Position size
    • entryPrice (string): Average entry price
    • markPrice (string): Current mark price
    • liquidationPrice (string | null): Liquidation price
    • unrealizedPnl (string): Unrealized profit/loss
    • leverage (string): Current leverage
    • marginUsed (string): Margin allocated to position
  • error (string | null): Error message (on failure)
Example:
positions = agent.platforms.hyperliquid.positions()
xyz_positions = agent.platforms.hyperliquid.positions(dex="xyz")

if positions.success and positions.data:
    for pos in positions.data:
        agent.log(f"{pos.symbol} {pos.side}: {pos.size} @ {pos.entryPrice}")
        agent.log(f"  PnL: {pos.unrealizedPnl}, Leverage: {pos.leverage}x")
        if pos.liquidationPrice:
            agent.log(f"  Liq price: {pos.liquidationPrice}")

Order

Get order information by order ID.
def order(order_id: str) -> HyperliquidOrderResponse
Response:
  • success (boolean): Whether the operation succeeded
  • data (object): Order information (same shape as placeOrder response)
    • orderId (string): Order ID
    • symbol (string): Trading pair symbol
    • 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”
  • error (string | null): Error message (on failure)

Delete Order

Cancel an order.
def delete_order(order_id: str, symbol: str) -> HyperliquidDeleteOrderResponse
Example:
result = agent.platforms.hyperliquid.delete_order("1234567890", "BTC")
if result.success:
    agent.log("Order cancelled")
else:
    agent.log(result.error or "Failed to cancel order", error=True)

Open Orders

Get all open orders.
def open_orders() -> HyperliquidOpenOrdersResponse
Response:
  • success (boolean): Whether the operation succeeded
  • data (array): Array of open orders (same shape as placeOrder response — orderId, symbol, side, price, size, filled, status, market)
  • error (string | null): Error message (on failure)

Orders

Get historical orders.
def orders() -> HyperliquidHistoricalOrdersResponse
Response includes:
  • status: “open”, “filled”, “canceled”, “triggered”, “rejected”, “marginCanceled”, “liquidatedCanceled”
  • orderType: “Market”, “Limit”, “Stop Market”, “Stop Limit”, “Take Profit Market”, “Take Profit Limit”
  • timestamp: Order creation timestamp
  • statusTimestamp: Status update timestamp

Order Fills

Get order fill history.
def order_fills() -> HyperliquidOrderFillsResponse
Response includes:
  • price (string): Fill price
  • size (string): Fill size
  • fee (string): Trading fee paid

Transfer

Transfer between spot and perp accounts.
def transfer(request: HyperliquidTransferRequest | dict) -> HyperliquidTransferResponse
Request Parameters:
  • amount (number): Amount to transfer
  • toPerp (boolean): true to transfer to perp account, false to transfer to spot
  • expiresAt (string | null, optional): ISO 8601 timestamp for suggestion expiry in manual mode.
Example:
# Transfer USDC from spot to perp account
transfer = agent.platforms.hyperliquid.transfer({
    "amount": 1000.0,
    "toPerp": True
})

if transfer.success:
    agent.log("Transfer completed")

Liquidations

Get liquidation events.
def liquidations(start_time: int | None = None) -> HyperliquidLiquidationsResponse
Parameters:
  • startTime (number, optional): Unix timestamp in milliseconds to filter liquidations from
Response includes:
  • timestamp (number): Liquidation timestamp
  • liquidatedPositions (array): Liquidated positions
  • totalNotional (string): Total notional value liquidated
  • accountValue (string): Account value at liquidation
  • leverageType (string): “Cross” or “Isolated”
  • txHash (string): Transaction hash

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 streamed from Hyperliquid’s allMids feed and written at most once per second per coin. The response includes an isStale flag that is true when the most recent tick is older than ~90 seconds.
def midpoint_price(coin: str | list[str], dex: str | None = None) -> HyperliquidMidpointPriceResponse
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 most recent midpoint tick.
  • isStale (boolean): true when the latest tick is older than ~90 seconds.
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:
# Defaults to perps
btc = agent.platforms.hyperliquid.midpoint_price("BTC")
if btc.success and btc.data and not isinstance(btc.data, list):
    agent.log(f"BTC perp mid: {btc.data.price_usd} @ {btc.data.timestamp}")

# Spot pair
agent.platforms.hyperliquid.midpoint_price("HYPE/USDC", "spot")

# Multiple coins on a builder DEX
many = agent.platforms.hyperliquid.midpoint_price(["GOLD", "MAG7"], "xyz")
if many.success and isinstance(many.data, list):
    for row in many.data:
        agent.log(f"{row.coin}: {row.price_usd}")

Common Errors

Errors are returned in the error field of the response. Common errors include:
ErrorCauseSolution
”Unsupported builder DEX: . Supported builder DEXes: xyz, cash, vntl”Builder DEX prefix is not in the supported setUse a supported builder DEX prefix (currently xyz, cash, or vntl)
“Unknown perp asset: . Available assets: …”Symbol not found in available perpsUse a valid perp symbol like "BTC", "ETH"
”Unknown spot pair: . Available pairs: …”Symbol not found in available spot pairsUse a valid spot pair like "BTC/USDC", "ETH/USDC"
”Invalid coin format: Invalid symbol formatEnsure symbol matches expected format (perps: “BTC”, spot: “BTC/USDC”)
order requires triggerPrice”Stop or take_profit order missing triggerPriceProvide triggerPrice parameter for stop/take_profit orders
”Order not found”Order ID doesn’t existVerify order ID is correct
”Failed to place order”Order submission failedCheck order parameters and account balance
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).
  • Transfer operations return void responses (no data on success).
  • Spot symbols use the format "BTC/USDC", while perp symbols use just the base asset like "BTC".
  • Hyperliquid rate-limits aggressively. Avoid calling balances() or positions() in loops.

See Also