Skip to content

Grid Bots - Automated Grid Trading

TL;DR

What is a Grid Bot:

  • Automated trading strategy that places buy/sell orders at regular price intervals
  • Profits from price oscillation within a defined range
  • Works on both Spot and Perpetual markets

Spot vs Perp Grid:

Spot GridPerp Grid
Asset ownershipYou own the actual assetsYou hold positions (contracts)
Funding requirementNeed base + quote assetsMargin only
Short sellingRequires borrowingBuilt-in (can go short natively)
ComplexityHigher (deficit handling)Simpler

Spot Grid Funding:

  • Deficit: How much base asset you're missing to cover sell orders
  • Borrow Mode: Borrow the missing base asset from lending pool (margin trading)
  • Buy Mode: Use quote currency to buy the missing base asset upfront

Table of Contents

  1. How Grid Bots Work
  2. Spot Grid vs Perp Grid
  3. Spot Grid Funding
  4. The Deficit Concept
  5. Borrow Mode vs Buy Mode
  6. Grid Parameters

1. How Grid Bots Work

The Basic Concept

A grid bot divides a price range into equal intervals (the "grid") and places orders at each level:

Price $110 ─────── Sell order (top of range)
Price $108 ─────── Sell order
Price $106 ─────── Sell order
Price $104 ─────── Sell order
Price $102 ─────── Sell order
────────────────── Current price: $100 ──────────────────
Price $98  ─────── Buy order
Price $96  ─────── Buy order
Price $94  ─────── Buy order
Price $92  ─────── Buy order
Price $90  ─────── Buy order (bottom of range)

How Profits Are Made

  1. When price moves up: Sell orders get filled
  2. When price moves down: Buy orders get filled
  3. Each completed buy→sell cycle captures the grid spacing as profit

Example:

Grid spacing: $2
1. Buy at $98 → Sell at $100 = $2 profit
2. Buy at $96 → Sell at $98 = $2 profit
(Repeat as price oscillates)

Key Parameters

ParameterDescription
priceLowBottom of the grid range
priceHighTop of the grid range
gridCountNumber of grid levels (orders)
totalGridValueTotal capital allocated to the grid

2. Spot Grid vs Perp Grid

Perpetual Grid (Simpler)

Perp grids trade perpetual futures contracts:

  • You only need margin (collateral)
  • Can go long or short natively
  • No need to own the underlying asset
  • Funding rates apply (see Funding Rate)

Spot Grid (More Complex)

Spot grids trade actual assets:

  • Orders above current price are sell orders → require the base asset (e.g., BTC)
  • Orders below current price are buy orders → require the quote asset (e.g., USDC)

The challenge: You need to have enough of both assets to place all orders.

Example: BTC_USDC grid, current price $100

Orders above $100 (sell orders):
  - Need BTC to sell

Orders below $100 (buy orders):
  - Need USDC to buy

3. Spot Grid Funding

When creating a spot grid, the backend pre-calculates all orders based on your parameters (price range, grid count, total value). Orders are split by the current market price:

  • Orders below current price → Buy orders (require quote currency, e.g., USDC)
  • Orders above current price → Sell orders (require base currency, e.g., BTC)

Required Assets

  1. Quote Asset (e.g., USDC): Needed for buy orders below current price
  2. Base Asset (e.g., BTC): Needed for sell orders above current price

If you don't have enough base asset, you have a deficit that must be funded.


4. The Deficit Concept

The deficit represents how much base asset you're missing to cover the sell orders in your grid.

Calculation

deficit = max(0, requiredBaseAmount - baseAssetBalance)

Where:

  • requiredBaseAmount = Sum of all sell order quantities from the pre-calculated grid
  • baseAssetBalance = User's available + locked + lent balance of the base asset

Example

Grid: BTC_USDC, range $90-$110, current price $100
Sell orders need: 0.5 BTC total
Your BTC balance: 0.2 BTC

Deficit = 0.5 - 0.2 = 0.3 BTC

If deficit = 0: You have enough base asset, no funding decision needed.

If deficit > 0: You must choose how to fund the gap.


5. Borrow Mode vs Buy Mode

When you have a deficit, you have two options:

Borrow Mode (autoBorrow: true)

How it works:

  • Borrow the deficit amount from the lending pool
  • The borrowed amount is used to cover your sell orders
  • You pay interest on the borrowed amount (see Borrow & Lend)

When to use:

  • You want to preserve your quote balance
  • You expect to close the grid before interest costs become significant
  • Lending rates are favorable

Requirements:

  • Borrow/Lend must be enabled in your jurisdiction
  • A lending market must exist for the base asset
  • You must have sufficient margin

Buy Mode (autoBorrow: false)

How it works:

  • Use your quote currency to buy the deficit amount upfront
  • The purchase happens before the grid starts
  • No ongoing interest costs

When to use:

  • You want to avoid borrowing/margin
  • Borrow/Lend is not available
  • You have excess quote currency

Key parameter: maxEntryPrice

  • The maximum price you're willing to pay when buying the deficit
  • Defaults to ~1% above current price
  • Protects against slippage during the initial buy

Auto-Selection Logic

The system auto-selects the funding mode based on availability:

  1. If user has sufficient base balance → Default to borrow (doesn't matter since no funding needed)
  2. If borrowing unavailable but can buy → Force buy mode
  3. If can't afford to buy but can borrow → Force borrow mode
  4. If both available → Default to borrow, user can override

Comparison Table

AspectBorrow ModeBuy Mode
Upfront costNoneBuy deficit immediately
Ongoing costInterest on borrowed amountNone
Quote balancePreservedReduced
RequirementsBorrow/Lend enabled + marginSufficient quote balance
RiskLiquidation if margin dropsSlippage on entry buy

6. Grid Parameters

Core Parameters (All Grid Types)

FieldTypeDescription
priceLownumberLower bound of price range
priceHighnumberUpper bound of price range
gridCountnumberNumber of grid levels
totalGridValuenumberTotal allocation in quote currency

Spot-Specific Parameters

FieldTypeDescription
autoBorrowbooleantrue = borrow mode, false = buy mode
maxEntryPricenumberMax price for buying deficit (buy mode only)

Optional Parameters

FieldTypeDescription
closePositionsOnStopbooleanClose all positions when bot stops
gridTriggerbooleanEnable conditional start
gridTriggerAmountnumberPrice trigger to start the grid
trailingUpPricenumberTrailing stop upper bound
trailingDownPricenumberTrailing stop lower bound

Summary

Grid bots automate buy-low-sell-high strategies within a price range. The key complexity in spot grids is ensuring you have enough assets on both sides of the current price:

  1. Check for deficit - Do you have enough base asset for sell orders?
  2. If deficit > 0, choose funding:
    • Borrow: Take a loan from lending pool, pay interest
    • Buy: Spend quote currency upfront to acquire the base asset
  3. System auto-selects based on what's available to the user
  4. User can override if both options are available