Skip to content

Perpetuals Agent

The Perpetuals Agent opens, manages and closes leveraged perpetual positions on decentralised orderbooks. V1 ships with Hyperliquid; the venue abstraction is ready for dYdX v4, GMX and Vertex as future implementations.

Architecturally separate from the Trading Agent because the risk model is different: positions persist between runs, leverage multiplies losses, liquidation can wipe collateral, and funding rates accumulate while open. Treasury (Bit2Me CEX), Trading (spot DEX), and Perpetuals (perp DEX) are the three orthogonal money-moving templates.

Setup

  1. Wallet — the agent’s bound Sigil wallet IS the Hyperliquid account. Address-based auth, no API key to create.
  2. Operator funds the account — send USDC on Arbitrum to Hyperliquid’s bridge (0x2Df1c51E09aECF9cacB7bc98cB1742757f163dF7). Funds appear in the wallet’s Hyperliquid balance after Arbitrum confirmation. Minimum ~5 USDC. Sigil does not auto-deposit in V1; the agent operates inside whatever margin you put there.
  3. TEE mode required — the agent signs Hyperliquid action payloads with the TEE-held private key. Org signing_mode must be tee. The TEE service learns no Hyperliquid specifics — the agentrun computes the EIP-712 digest and the TEE signs it as a plain raw_digest.

Configuration

FieldTypeNotes
allowed_marketsstring[]["BTC-USD", "ETH-USD", ...]. Hyperliquid’s universe is ~100 perp markets; whitelist what the agent may trade.
allowed_sidesstring[]["long"], ["short"], or both. Long-only is safer to reason about.
max_leverageint 1-50Hard cap. Recommend 3-5x for production agents.
max_position_size_usdstringNotional cap per single open.
max_total_exposure_usdstringSum of notional across all open positions on the venue.
max_open_volume_per_day_usdstringRolling-24h cap on new opens. Closes don’t count.
require_stop_lossboolWhen true (recommended), opens without SL are refused.
min_distance_to_liquidation_pctnumberRefuse to open if liquidation price would land within X% of current. 0 disables.
max_funding_rate_bps_againstnumberRefuse to open when funding rate against your side exceeds this in bps/hr.
builder_code{ address, fee_tenths_bp }Customer’s builder code (see below). Empty = Sigil platform default.

Tools

Read (always available, no policy gate):

ToolReturns
perps_get_market(market)Mid + mark + hourly funding rate (bps) + open interest + venue max leverage.
perps_get_position(market?)Open positions with size, entry, PnL, margin used, leverage, liquidation price.
perps_get_account()Total equity, available margin, total exposure.
perps_get_funding_history(market, hours)Recent hourly funding rates (1-168h lookback).

Write (policy-gated server-side):

ToolAction
perps_open_position(market, side, size_usd, leverage, stop_loss_price?, take_profit_price?, reason)Opens via Ioc market-like order with optional SL/TP trigger orders attached.
perps_close_position(market, size_usd?, reason)Reduce-only Ioc. Omit size_usd to fully close.
perps_adjust_stop_loss(market, new_stop_loss_price)Tighten the SL (move closer to current price). Loosening refused.
perps_cancel_stop_loss(market)Refused when require_stop_loss=true.

A refusal by policy returns ErrToolNotInvocable with the reason — the LLM sees the error and adapts; it cannot bypass.

Workflow the agent follows

The system prompt requires this discipline before every open:

  1. perps_get_market(market) → current funding + mid price.
  2. perps_get_position(market) → check existing exposure (no hedge mode in V1; close first if already long/short the opposite way).
  3. perps_get_account() → confirm available_margin_usd covers it.
  4. Compute the liquidation price; reduce leverage if too close.
  5. Verify funding rate against your side is within max_funding_rate_bps_against.
  6. perps_open_position with explicit stop_loss_price when require_stop_loss=true.

Builder code

Hyperliquid forwards a configurable fee per trade to a builder address. By default the agent uses Sigil’s platform builder code. Set builder_code.address + builder_code.fee_tenths_bp in the agent config to redirect that revenue to your own address — you keep 100% of the builder fees your agent generates.

Sigil’s default rate is competitive with industry frontends; you can match or undercut. Fee is in tenths of a basis point: 5 means 0.05% on each trade in addition to Hyperliquid’s protocol fees.

Audit trail

Every open / close / SL adjust writes a row to agent_perps_position_events. The portal’s Positions tab on the agent detail renders the timeline newest-first. Live state (PnL, liquidation price, margin) always comes from Hyperliquid in real time — Sigil never caches venue state.