Skip to content
elyrail

Hyperliquid trading

Elyrail trades on Hyperliquid perpetuals through an agent (API) wallet. Hyperliquid lets agent wallets place, modify and cancel orders and change leverage. It does not let them withdraw or transfer funds; that is enforced by Hyperliquid, not by Elyrail. Elyrail exposes no withdrawal or transfer tool either.

Set up#

  1. Create the agent key.

    bash
    elyrail keystore create --out hl-agent.keystore.json
  2. Approve the agent address on Hyperliquid from the account that holds the funds (the master account), in Hyperliquid's API settings. Elyrail never handles the master key.

  3. Add the agent to elyrail.json.

    json
    { "hyperliquid": { "network": "testnet", "user": "0xMasterAccount", "agent": { "keystoreFile": "./hl-agent.keystore.json", "passwordFile": "./hl-agent.password" } } }
  4. Add a trading rule to the policy.

    json
    { "trading": { "hyperliquid": { "network": "testnet", "markets": ["BTC", "ETH"], "maxLeverage": 3, "maxOrderNotionalUsd": "100", "maxPositionNotionalUsd": "300", "maxPriceDeviationBps": 200 } } }

What happens on each order#

  1. Elyrail reads the market, the mid price, the account's position and its current leverage from Hyperliquid's info API.
  2. It checks the order against the policy:
    • market allowlist and leverage;
    • order notional (size × mid);
    • the position after a full fill;
    • distance from mid;
    • rate limit, time window and kill switch.
  3. If the policy requires it, a person approves the exact action hash.
  4. Only then does the agent key sign. The signature uses Hyperliquid's L1 action format, ported from the official Python SDK and checked against its published test vectors.

Use clientOrderId to make an order safe to retry: Hyperliquid refuses a second order with the same id.

Limits#

  • Prices come from Hyperliquid at request time. A fast market can move before the fill; the limit price bounds that.
  • One process per agent key, because Hyperliquid tracks nonces per signer.
  • The kill switch blocks cancels too. Cancel from Hyperliquid directly while it is engaged.
  • Market and leverage indexes differ between mainnet and testnet. Elyrail reads them per network.