Hyperliquid
Trade perpetual futures and spot markets on Hyperliquid DEX.
Configuration
To define USDC Perps as your agent's required asset, use the following network and address in the .circuit.toml file.
[[requiredAssets]]
network = "hypercore:perp"
address = ""
minimumAmount = "1000000" // 6 decimals
devRunAmount = "1000000" // See note below regarding allocation Asset Allocation Notes
Circuit restricts users from deploying 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.
The
devRunAmountin the.circuit.tomlfile is not relevant for Hyperliquid agents, as your entire balance will be available to the agent when you start a sessionThe
minimumAmountwill still ensure that anyone deploying the agent will at least have that amount.Your agent should use the below methods to pull available balances/positions directly from Hyperliquid, opposed to the
agent.currentPositionsproperty.Balances:
agent.platforms.hyperliquid.balances()Positions:
agent.platforms.hyperliquid.positions()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: This is temporary while Circuit enhances the indexing of Hyperliquid activity, which will allow us to include the balances natively in the agent's currentPositions property.
Units
When querying via Hyperliquid's api (via agent.platforms.hyperliquid), all values will be returned in their formatted value, opposed to the rest of Circuit which returns values in their raw units (wei/lamports)
Place Order
If you are un-familar with placing orders via Hyperliquid's API, please see these docs for information regarding tick/lot sizes, as well as decimals.
Request Parameters:
symbol(string): Trading pair symbol. For perps:"BTC". For spot:"BTC-USDC".side(string): "buy" or "sell"size(number): Order sizeprice(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 ordersreduceOnly(boolean, optional): Whether this is a reduce-only orderpostOnly(boolean, optional): Whether this is a post-only order
Response:
success(boolean): Whether the operation succeededdata(object): Order information (on success)orderId(string): Order IDsymbol(string): Trading pair symbolside(string): "buy" or "sell"price(number): Order pricesize(number): Order sizefilled(number): Filled amountstatus(string): Order statusmarket(string): "perp" or "spot"
error(string | null): Error message (on failure)
Example:
Balances
Get account balances.
Response:
success(boolean): Whether the operation succeededdata.perp(object): Perp account balanceaccountValue(string): Total account valuetotalMarginUsed(string): Total margin usedwithdrawable(string): Withdrawable amount
data.spot(array): Spot token balancescoin(string): Token symboltotal(string): Total balancehold(string): Amount on hold
error(string | null): Error message (on failure)
Positions
Get open positions.
Response:
success(boolean): Whether the operation succeededdata(array): Array of open positionssymbol(string): Trading pair symbolside(string): "long" or "short"size(string): Position sizeentryPrice(string): Average entry pricemarkPrice(string): Current mark priceliquidationPrice(string | null): Liquidation priceunrealizedPnl(string): Unrealized profit/lossleverage(string): Current leveragemarginUsed(string): Margin allocated to position
error(string | null): Error message (on failure)
Order
Get order information by order ID.
Delete Order
Cancel an order.
Open Orders
Get all open orders.
Orders
Get historical orders.
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 timestampstatusTimestamp: Status update timestamp
Order Fills
Get order fill history.
Response includes:
price(string): Fill pricesize(string): Fill sizefee(string): Trading fee paidisMaker(boolean): True if maker, false if taker
Transfer
Transfer between spot and perp accounts.
Request Parameters:
amount(number): Amount to transfertoPerp(boolean):trueto transfer to perp account,falseto transfer to spot
Example:
Liquidations
Get liquidation events.
Parameters:
startTime(number, optional): Unix timestamp in milliseconds to filter liquidations from
Response includes:
timestamp(number): Liquidation timestampliquidatedPositions(array): Liquidated positionstotalNotional(string): Total notional value liquidatedaccountValue(string): Account value at liquidationleverageType(string): "Cross" or "Isolated"txHash(string): Transaction hash
Common Errors
Errors are returned in the error field of the response. Common errors include:
"Unknown perp asset: {asset}. Available assets: ..."
Invalid perp symbol (e.g., "BTC" for perps)
Use valid perp asset symbol like "BTC", "ETH"
"Unknown spot pair: {pair}. Available pairs: ..."
Invalid spot symbol (e.g., "BTC-USDC" for spot)
Use valid spot pair format like "BTC-USDC", "ETH-USDC"
"Invalid coin format: {coin}"
Invalid symbol format
Ensure symbol matches expected format (perps: "BTC", spot: "BTC-USDC")
"{order.type} order requires triggerPrice"
Stop or take_profit order missing triggerPrice
Provide triggerPrice parameter for stop/take_profit orders
"Order not found"
Order ID doesn't exist
Verify order ID is correct
"Failed to place order"
Order submission failed
Check 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
priceas a slippage limit (maximum acceptable execution price).Transfer operations return void responses (no
dataonsuccess=True).
Last updated