Grid Strategy

Grid Trading API
for AI Agents

Grid trading turns market volatility into profits. Place a ladder of buy and sell orders at fixed intervals, collect the spread every time price bounces between levels, and let the automation run indefinitely. Purple Flea's limit order API makes deploying a full grid trivial.

Get API Key โ†’ Start Building

How Grid Trading Works

A grid trading bot places buy orders below the current price and sell orders above it, at regular intervals. Each time price falls to a buy level, it fills; each time price rises to a sell level, it fills. The profit is the spread between each pair of fills, repeated across many oscillations.

Imagine ETH trading at $2,800. You set up a grid with levels every 1% ($28). Buy orders sit at $2,772, $2,744, $2,716, etc. Sell orders sit at $2,828, $2,856, $2,884, etc. As ETH oscillates between $2,700 and $2,900, the grid collects $28 profit per complete round trip on each level. With 10 levels and ETH bouncing 20 times in a week, that is 100+ individual fills.

The beauty of grid trading is that it is direction-agnostic. It does not matter if ETH goes up or down within the range โ€” volatility is the asset. Your agent profits from movement itself, not from predicting direction. This makes it ideal for periods when the market is consolidating without a clear trend.

Grid Level Visualization

Example: ETH-PERP grid centered at $2,800 with 1% spacing

$2,912SELL 0.018 ETH
$2,884SELL 0.018 ETH
$2,856SELL 0.018 ETH
$2,828SELL 0.018 ETH
$2,800CENTER PRICE
$2,772BUY 0.018 ETH
$2,744BUY 0.018 ETH
$2,716BUY 0.018 ETH
$2,688BUY 0.018 ETH

Each 1% bounce between adjacent levels = ~$0.50 profit per $50 order at 0.02% maker fee

Python: Setting Up a Grid

The following function deploys a symmetric grid of limit orders in a single call. All orders are placed with post_only=True to ensure you always receive the maker fee rebate:

import purpleflea

trader = purpleflea.TradingClient(api_key="YOUR_KEY")

def setup_grid(market, center_price, grid_count=10, grid_spacing_pct=1.0, order_size_usd=50):
    """Set up a symmetric grid of buy/sell limit orders."""
    orders = []
    half = grid_count // 2
    
    for i in range(1, half + 1):
        # Buy orders below center
        buy_price = center_price * (1 - i * grid_spacing_pct / 100)
        orders.append(trader.place_order(
            market=market, side="buy", notional_usd=order_size_usd,
            order_type="limit", price=round(buy_price, 2), post_only=True
        ))
        # Sell orders above center
        sell_price = center_price * (1 + i * grid_spacing_pct / 100)
        orders.append(trader.place_order(
            market=market, side="sell", notional_usd=order_size_usd,
            order_type="limit", price=round(sell_price, 2), post_only=True
        ))
    
    print(f"Grid set: {len(orders)} orders, ${center_price * grid_spacing_pct / 100:.2f} per grid")
    return orders

# Run grid on ETH-PERP with 1% spacing, 10 levels
setup_grid("ETH-PERP", center_price=2800, grid_count=10, grid_spacing_pct=1.0)

Grid Parameters Reference

Choosing the right parameters determines whether your grid profits consistently or generates losses. Here is how each parameter affects performance:

Parameter Tight (Aggressive) Wide (Conservative) Best Use Case
Grid spacing 0.5% 2โ€“3% Tight: low-vol range. Wide: volatile markets
Grid levels 5โ€“8 levels 15โ€“20 levels More levels = wider total range
Order size $25โ€“50 $100โ€“200 Scale with account size: 1โ€“2% per order
Spacing type Equal ($) Geometric (%) Geometric more natural for volatile assets
Center price Current price 20-day VWAP VWAP center reduces directional risk

Calculating Expected Grid Profit

The expected profit per grid level per oscillation can be calculated precisely:

# Expected profit per grid cycle
order_size = 50 # USD per order
spacing_pct = 1.0 # 1% between levels
maker_fee_pct = 0.02 # 0.02% maker fee

gross_profit = order_size * spacing_pct / 100
fee_cost = order_size * maker_fee_pct / 100 * 2 # 2 fills per cycle
net_profit = gross_profit - fee_cost

print(f"Gross per cycle: ${gross_profit:.4f}") # $0.5000
print(f"Fee cost: ${fee_cost:.4f}") # $0.0200
print(f"Net per cycle: ${net_profit:.4f}") # $0.4800

# 10-level grid, 3 oscillations/day = $14.40/day on $1,000 deployed
daily_cycles = 10 * 3 # 10 levels, 3 round trips per level per day
daily_profit = daily_cycles * net_profit
print(f"Daily profit: ${daily_profit:.2f}") # $14.40

Key insight: Purple Flea's 0.02% maker fee is essential for grid profitability. With taker fees (0.05%), the fee cost per cycle quadruples, eating 4x more of your grid profit. Always use post_only=True.

When Grid Trading Works Best

Ideal Conditions

  • Consolidation phases โ€” after a large move, markets often range for days to weeks. Grid captures the oscillation while the market decides direction.
  • Pre-news uncertainty โ€” before major announcements, markets often trade sideways in anticipation. Grid collects the volatility during this wait.
  • High-liquidity markets โ€” BTC, ETH, SOL perpetuals have enough depth that your grid fills consistently without slippage concerns.
  • Moderate daily volatility โ€” markets with 3โ€“8% daily range give enough oscillation to hit multiple grid levels repeatedly.

Poor Conditions

  • Strong trending markets โ€” price moves through your entire grid in one direction, filling all buys but no sells (or vice versa), leaving you with a directional position.
  • Flash crashes โ€” price gaps through your buy orders faster than they fill, then recovers. You may miss entries or get filled at poor prices.
  • Very low volatility โ€” if daily range is less than your grid spacing, orders never fill and capital sits idle.
  • Illiquid markets โ€” your limit orders may not fill reliably in thin order books, creating asymmetric inventory accumulation.
275
Markets available for grid deployment
0.02%
Maker fee โ€” critical for grid profitability
24/7
Markets never sleep โ€” grids run continuously
20
Max grid levels per deployment
20%
Referral commission on trading fees
<50ms
Order placement latency
Ready to Build

Deploy Your First Grid
in Minutes

Get an API key, install the SDK, and have a live grid running in under 30 minutes. New agents receive $1 USDC free from the faucet.

Get API Key โ†’ Read the Deep Dive โ†’

Related Pages

Trading API โ†’ Limit Order API โ†’ Mean Reversion โ†’ Backtesting API โ†’ Grid Trading Blog โ†’