Skip to content

QuantProcessing/grid-trader

Repository files navigation

Grid Trader

English | 中文

A quantitative grid trading bot built on exchanges — the unified Go exchange SDK.

Grid trading places buy and sell orders at preset price intervals within a range. When price oscillates, orders fill in alternation, capturing profit on each cycle.

How It Works

SELL ── $70,000 ─── Grid Level 5
SELL ── $68,000 ─── Grid Level 4
       $66,500 ─── (current price)
BUY  ── $66,000 ─── Grid Level 3
BUY  ── $64,000 ─── Grid Level 2
BUY  ── $62,000 ─── Grid Level 1
BUY  ── $60,000 ─── Grid Level 0
  1. Define a price range (upper/lower bounds) and grid count
  2. Below current price → BUY orders, above → SELL orders
  3. BUY fills → place SELL one level above (flip)
  4. SELL fills → place BUY one level below (flip)
  5. Each BUY→SELL cycle earns one grid's profit

Quick Start

Prerequisites

  • Go 1.26+
  • An exchange account with API keys

Install

go install github.com/QuantProcessing/grid-trader@latest

Or build from source:

git clone https://github.com/QuantProcessing/grid-trader.git
cd grid-trader
go build -o grid-trader .

Configure

Copy the environment template and add your exchange credentials:

cp .env.example .env
vim .env
# Edit .env with your API keys

Run

./grid-trader \
  --exchange BINANCE \
  --symbol BTC-USDT \
  --upper-price 70000 \
  --lower-price 60000 \
  --grid-count 20 \
  --quantity 0.001 \
  --grid-type geometric

Parameters

Flag Description Default
--exchange Exchange name BINANCE
--symbol Trading pair BTC-USDT
--upper-price Grid upper bound (required)
--lower-price Grid lower bound (required)
--grid-count Number of grid levels 10
--quantity Quantity per grid (base currency) 0.001
--grid-type arithmetic or geometric geometric
--stop-loss Stop loss price (-1 = disabled) -1
--take-profit Take profit price (-1 = disabled) -1
--use-post-only Use POST-ONLY for maker rebate false

Grid Types

  • Geometric (recommended): Equal percentage spacing between levels. Better for wide price ranges.
  • Arithmetic: Equal absolute price spacing. Better for narrow ranges.

Supported Exchanges

Any exchange supported by exchanges:

Exchange Auth Type Default Quote
Binance API Key + Secret USDT
OKX API Key + Secret + Passphrase USDT
Aster API Key + Secret USDC
Nado Private Key USDT
Lighter Private Key + Account/Key Index USDC
Hyperliquid Private Key + Account Address USDC
StandX Private Key DUSD

To override the default quote currency, set the environment variable:

EXCHANGES_BINANCE_QUOTE_CURRENCY=USDC

Architecture

main.go       Entry point — signal handling, adapter factory, lifecycle
config.go     CLI flags + validation
engine.go     Grid trading engine — order placement, fill handling, flip logic
grid.go       Grid price calculation (arithmetic & geometric)

The engine subscribes to two WebSocket streams:

  • OrderBook — maintains local BBO for grid initialization and stop-loss/take-profit monitoring
  • Orders — receives fill/cancel events, triggers grid flip logic

Build with Version

go build -ldflags "-X main.Version=v1.0.0" -o grid-trader .

Risk Warning

⚠️ Important:

  • One-directional trends will fill all orders on one side, accumulating position risk
  • Price breaking below the lower bound results in maximum long exposure
  • Always set --stop-loss to limit downside
  • Best suited for range-bound markets, not strong trends
  • Profit calculations are approximate — actual P&L depends on fill prices and fees

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages