Build a Hyperliquid trading agent in TypeScript
Updated by the Circuit team
What you write
A Circuit agent is a TypeScript run function. Circuit calls it on a schedule from the triggers in circuit.toml or runs it continuously. Your code requests typed actions through the agent object. Signing happens outside the agent's sandbox under the user's passkey-signed permit. Your code never handles private keys. See the execution model.
Set up
Install the CLI with Bun: bun install -g @circuitorg/agent-cli. Then circuit new --name my-agent creates index.ts, circuit.toml and DESCRIPTION.md. Edit the three together: the code, its triggers and settings, and the description users read. The quickstart walks through it.
Place a Hyperliquid order
agent.hyperliquid.orders.create takes an order proposal. { kind: "perpOpen", asset: "BTC", side: "long", amount: { valueUsdc: "100" } } opens a $100 BTC long with a market order within 1% of the mid. Pass execution to change that: { kind: "limit", price, timeInForce: "ioc" | "gtc" | "alo" } for limits. Pass takeProfit and stopLoss triggers on perpOpen and perpReduce. perpReduce, spotBuy and spotSell complete the set. "max" sizes a reduce to the session's own position. Full details are in the Hyperliquid SDK reference. The trading side is covered in Hyperliquid trading agents.
Read state the right way
Size every order from agent.allocation. It is the session's own holdings and excludes the rest of the account. A reduce is capped at what the session holds. Your agent never touches positions the user opened elsewhere. Log your reasoning with agent.log so users see why each trade happened.
Test, backtest, ship
circuit check --json verifies the project. circuit backtest --from <ISO> --to <ISO> --usd 1000 --json replays it against recorded Hyperliquid, Lighter or Lighter Robinhood markets without a wallet or network writes. circuit run --paper simulates funds on live markets. circuit auth login and circuit upload publish it when it is ready. Users start it from the Circuit app.
Docs for AI coding tools
The docs publish llms.txt and llms-full.txt for language models. They also publish an MCP server you can add to Claude Code with claude mcp add circuit --transport http https://docs.circuit.org/mcp. Your coding assistant then writes against the current SDK. More in trade with Claude.
Keys and permits
Agents run on a wallet you create in Circuit or import by private key. Circuit keeps the signing key in a hardware enclave. Agents never see it. An agent requests typed actions through Circuit's SDK. Nothing is signed without the permit you sign with your passkey when you start the agent.
You can export the private key from Settings at any time. You can pause, resume or stop an agent at any time. Stopping leaves your positions and resting orders in your account. You ask Circuit to close them.
Build it on Circuit
Circuit writes the agent and backtests it. Paper trade it before you fund it.
Build your agent