All articles
Hyperliquid·April 9, 2026·5 min read

Building a Hyperliquid Perps Trading Bot From Scratch

A technical walkthrough of the full order lifecycle on Hyperliquid's HyperBFT on-chain CLOB — from feed ingestion to kill-switch — for teams serious about building a perps bot.

Most perpetual futures bots written for CEXes fall apart the moment you point them at Hyperliquid. The execution model is fundamentally different: there is no traditional mempool to monitor, no block builder to bribe with Jito bundles or priority fees, and no relayer sitting between you and the matching engine. Instead, HyperBFT — Hyperliquid's custom consensus layer — runs a fully on-chain central limit order book (CLOB) that clears in roughly 200 ms. Understanding that architecture is the prerequisite to everything else.

How the HyperBFT Order Lifecycle Actually Works

When your bot posts a limit order, it signs and submits a typed transaction directly to a validator endpoint. The validator gossips it across HyperBFT's validator set, the order lands in the CLOB, and a fill (or a resting resting acknowledgement) is returned in the same consensus round — no waiting for a separate settlement layer. This tightness is a feature, but it demands that your bot treat round-trip latency to the validator as a first-class concern. Colocation (or the nearest AWS/GCP region to the validator cluster) and persistent WebSocket connections to the Hyperliquid info and order-book streams are non-negotiable starting points.

The exchange publishes L2 order book snapshots and trade feeds over WebSocket. Your ingestion layer should consume these in a dedicated thread or async task with no blocking I/O on the critical path. A typical setup keeps a local in-memory CLOB mirror — a sorted map of price levels to aggregated sizes — updated on every delta message. Your strategy layer reads from this mirror; it never reaches out to a remote endpoint mid-signal.

Order Types, Funding Rates, and Inventory Skew

Hyperliquid exposes limit, market, and trigger orders, plus reduce-only flags and time-in-force variants (GTC, IOC, ALO). For a market-making bot, the workflow looks like this:

  • Quote generation: compute a theoretical fair value from your mid-price + any short-term alpha signal, then apply a bid-ask spread that covers expected funding costs and desired maker rebate capture.
  • Inventory skew: if your net position drifts long, shade your bid price down and your ask price up to encourage mean-reversion. A simple linear skew factor — spread_adjustment = position_size * skew_coefficient — prevents you from accumulating a runaway directional book.
  • Funding rate awareness: Hyperliquid settles funding every hour. Your bot should read the predicted funding rate from the info endpoint and fold it into fair value continuously. Paying 0.05% per hour on a leveraged position compounds faster than most strategies can offset.
  • Order refresh cadence: stale quotes get picked off. Cancel and requote on every meaningful book update, but throttle refreshes to avoid hitting rate limits — the exchange enforces per-account order submission caps.

For directional bots (momentum, stat-arb, signal-driven), IOC orders are your execution primitive. Quote at or through the best bid/ask, accept partial fills, and size your notional to keep slippage inside the expected edge. Unlike Solana where you compete on Jito bundle ordering, Hyperliquid's fair CLOB queuing means time-priority at a given price level actually matters — get your order in early when you expect a move.

Risk Controls and Kill-Switches

No production hyperliquid perps trading bot ships without hard risk rails:

  • Position limits: maintain a maximum gross notional and maximum net notional in code, checked before every order placement. If either threshold is breached, the bot shifts to reduce-only mode automatically.
  • PnL circuit breaker: track realized + unrealized PnL over a rolling window. A drawdown beyond a configured threshold halts order placement and pages the operator.
  • Kill-switch endpoint: expose an authenticated HTTP endpoint or a monitored flag file. An external watchdog — or a human — can flip it to halt all activity and submit cancel-all orders in a single signed transaction.
  • Simulation / anti-rug checks: before placing any order larger than a defined notional threshold, simulate the resulting position and margin utilization against current mark price. Reject the order if simulated liquidation price is within a buffer of the current price.

We applied a similar layered risk framework in our Hyperliquid market-maker build, where a faulty signal briefly pushed the inventory skew outside acceptable bounds — the kill-switch caught it within one settlement cycle with no material loss.

Connectivity and Operational Stability

Hyperliquid's WebSocket feed drops messages when a validator falls behind. Your reconnect logic must re-subscribe and request a full book snapshot — not just replay the delta buffer — on every reconnect, otherwise your local CLOB mirror drifts silently. Use a sequence number or a server-side heartbeat to detect gaps rather than relying on socket close events alone.

Log every order, fill, and cancel with a monotonic timestamp at the microsecond level. Post-trade analysis on Hyperliquid requires reconstructing your own activity from logs because the on-chain history API has limited lookback for high-frequency actors. Without granular logs, debugging a latency regression or a fill-rate drop becomes guesswork.

For teams exploring multiple venues, the connectivity patterns here overlap meaningfully with what we built for the cross-venue arbitrage strategy, where latency discipline across three feeds was the margin between profitability and noise.

If you want to move from architecture notes to a running system, our trading-bot services cover full-stack builds across Hyperliquid, Solana, and Polymarket — from strategy design through to live deployment.


Ready to build on Hyperliquid? Start a project with TierZero and we will scope your bot from order lifecycle to production deployment.

Need a bot like this built?

We design, build and run trading bots on Solana, Hyperliquid and Polymarket.

Start a project
#hyperliquid#perps#bot