All Tools & Strategies

Hyperliquid Grid Trading Bot

An open-source grid trading bot for Hyperliquid. Places layered buy and sell limit orders at regular intervals to profit from range-bound price action on the fastest on-chain perpetuals exchange.

Market MakingRange Trading

What Is Grid Trading?

Grid trading is a strategy that places a series of buy and sell limit orders at predetermined price levels, creating a "grid" of orders above and below the current market price. When price falls to a buy level, the bot buys. When price rises to a sell level, the bot sells. Each completed buy-sell cycle captures a small profit equal to the grid spacing minus fees.

The strategy is designed for range-bound markets where price oscillates within a predictable band. Rather than predicting direction, grid trading profits from volatility itself. The more the price moves back and forth within the grid range, the more cycles complete and the more profit accumulates.

On Hyperliquid, grid trading benefits from the exchange's low fees, fast execution, and on-chain order book. Limit orders on Hyperliquid pay no taker fees (maker rebates may apply), which is a significant advantage for a strategy that places exclusively limit orders.

How the Algorithm Works

The bot calculates a set of price levels based on the configured grid parameters: the upper and lower bounds of the range, the number of grid levels, and the order size at each level. It then places buy limit orders at every level below the current price and sell limit orders at every level above the current price.

When a buy order fills, the bot immediately places a corresponding sell order one grid level above. When a sell order fills, it places a buy order one grid level below. This creates a self-sustaining cycle where each fill generates a new order on the opposite side.

The bot monitors order status through the Hyperliquid API and manages the full lifecycle of each order. If the price drifts outside the grid range, the bot can optionally cancel all orders and re-center the grid around the new price, or it can wait for price to return to the range.

Grid Parameters and Tuning

The most important parameters are the grid range (upper and lower bounds), the number of levels, and the order size. The range should encompass the expected price oscillation zone. Too narrow a range means the price frequently breaks out and the bot sits idle. Too wide a range means the grid levels are far apart and each cycle takes longer to complete.

More grid levels within a fixed range means tighter spacing and more frequent fills, but each fill captures less profit. Fewer levels mean larger profit per cycle but less frequent trading. The optimal balance depends on the asset's typical intraday range and the fee structure.

Order size should be calibrated so that the total capital required for all grid orders does not exceed the available margin. The bot will place orders at every level simultaneously, so the worst case is all buy orders filling (price drops to the lower bound) with full margin utilization.

When It Works — and When It Doesn't

Grid trading thrives in sideways markets with consistent volatility. Assets that trade in a well-defined range for weeks or months are ideal candidates. The strategy accumulates steady returns as long as price keeps bouncing within the grid.

The strategy fails in strong trending markets. If price breaks above the grid, all sell orders fill and the bot is left fully in cash with no further upside exposure — it misses the rest of the move. If price breaks below the grid, all buy orders fill and the bot is left holding a full position at an average price above the current market — an unrealized loss.

The worst scenario is a one-way move that takes price far beyond the grid. For this reason, it is important to set the grid range around support and resistance levels, and to use stop-loss mechanisms or position size limits to cap downside exposure.

Command-Line Arguments

FlagDescriptionDefault
--symbolTrading pair symbolBTC
--upperUpper price bound of the grid
--lowerLower price bound of the grid
--levelsNumber of grid levels10
--sizeOrder size in USD per level50
--recenterAuto-recenter grid when price exits rangefalse

Risk Warnings

  • Breakout risk — a strong directional move beyond the grid range can result in holding a losing position at a poor average price.
  • Capital lock-up — all grid orders tie up margin simultaneously. Ensure sufficient capital for the worst-case scenario.
  • No inherent stop-loss. If price trends strongly against the grid, losses compound with each filled level.
  • Grid spacing that is too tight relative to fees will result in unprofitable cycles.

Get Started

Deploy this strategy in under five minutes.

Setup
bash

1. Clone the repo

$ git clone https://github.com/atlasdetitan/hyperliquid-trading-bots.git

2. Install dependencies

$ cd strategies/grid_bot

$ pip install -r requirements.txt

3. Configure your agent wallet

$ cp .env.example .env

Paste your agent wallet private key from app.hyperliquid.xyz/API

4. Run the bot

$ python main.py

DEPLOY ON HYPERLIQUID

Run this bot on the fastest on-chain perpetuals exchange