Skip to main content
Scaffold this example locally and test it with the CLI:

circuit.toml

circuit.toml

Example

Sample Output

How It Works

  1. Check balance: Reads withdrawable USDC from the perp account
  2. Log positions: Shows any existing open positions with PnL
  3. Place order: Buys a small ETH perp position with a market order
  4. Track state: Uses memory to count total buy orders across cycles
  5. Unwind: Closes all open positions with reduce-only market orders

Notes

  • The price field on market orders acts as a slippage limit - set it above current market for buys, below for sells.
  • reduceOnly: true ensures the close order can only reduce an existing position, not open a new one.
  • Hyperliquid amounts are formatted values (e.g., 0.01 ETH), not raw units like EVM chains.
  • See Hyperliquid tick and lot sizes for minimum order sizes per symbol.