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.
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
- Define a price range (upper/lower bounds) and grid count
- Below current price → BUY orders, above → SELL orders
- BUY fills → place SELL one level above (flip)
- SELL fills → place BUY one level below (flip)
- Each BUY→SELL cycle earns one grid's profit
- Go 1.26+
- An exchange account with API keys
go install github.com/QuantProcessing/grid-trader@latestOr build from source:
git clone https://github.com/QuantProcessing/grid-trader.git
cd grid-trader
go build -o grid-trader .Copy the environment template and add your exchange credentials:
cp .env.example .env
vim .env
# Edit .env with your API keys./grid-trader \
--exchange BINANCE \
--symbol BTC-USDT \
--upper-price 70000 \
--lower-price 60000 \
--grid-count 20 \
--quantity 0.001 \
--grid-type geometric| 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 |
- Geometric (recommended): Equal percentage spacing between levels. Better for wide price ranges.
- Arithmetic: Equal absolute price spacing. Better for narrow ranges.
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=USDCmain.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
go build -ldflags "-X main.Version=v1.0.0" -o grid-trader .- 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-lossto limit downside - Best suited for range-bound markets, not strong trends
- Profit calculations are approximate — actual P&L depends on fill prices and fees