A high-performance bracket/grid trading bot for Backpack Exchange written in Go. It features a real-time web dashboard, trend filtering, and automatic rebalancing.
- Bracket/Grid Strategy: Simultaneously manages long and short legs with multiple grid levels.
- Trend Filter: Uses EMA-based filtering to block counter-trend entries.
- Direction Exclusivity: Optional mode to prevent simultaneous drawdowns in both directions.
- Real-time Dashboard: Built-in web UI for monitoring PnL, positions, and live event logs.
- WebSocket Integration: Low-latency market data and order update handling.
- Safety Tools: Panic Sell for immediate market exit and Seed Balance for 50/50 portfolio rebalancing.
The bot implements a sophisticated bracket strategy:
- Entries: Places a long entry at
mid × (1 − spread)and a short entry atmid × (1 + spread). - Grid Levels: Supports multiple entry levels to average into positions.
- Exits: Closes a leg once the unrealized profit reaches the
minProfitRateor hits thestopLossRate. - Trend Filter: Blocks entries that deviate too far from the EMA (Exponential Moving Average) to avoid catching falling knives or fading strong trends.
- Direction Exclusivity: If enabled, only one side (long or short) can have active grid levels at a time.
- Go 1.21+
- Backpack API Key and Secret
# Download dependencies
go mod download
# Build the binary
go build -o backpack .# Copy the example environment file
cp .env.example .env
# Edit .env with your credentials and parameters
nano .env
# Run the bot
./backpackThe dashboard will be available at http://127.0.0.1:8080 by default.
All options can be set via CLI flags or BP_* environment variables.
| Flag | Env Var | Default | Description |
|---|---|---|---|
--api-key |
BP_API_KEY |
— | Backpack API key |
--secret-key |
BP_SECRET_KEY |
— | Backpack secret key |
--symbol |
BP_SYMBOL |
SOL_USDC |
Trading pair |
--spread |
BP_SPREAD |
0.002 |
Entry offset from mid (e.g. 0.002 = 0.2%) |
--size |
BP_ORDER_SIZE |
0.1 |
Order quantity in base asset (supports units or e.g. 10%) |
--levels |
BP_GRID_LEVELS |
3 |
Number of grid levels |
--min-profit |
BP_MIN_PROFIT |
0.002 |
Min profit fraction to close (e.g. 0.002 = 0.2%) |
--stop-loss |
BP_STOP_LOSS |
0.02 |
Stop loss fraction to close (e.g. 0.02 = 2%) |
--trend-filter |
BP_TREND_FILTER |
0.005 |
Block entries if dev from EMA > this |
--exclusive |
BP_EXCLUSIVE |
false |
Only one direction can be in drawdown |
--interval |
BP_REFRESH_INTERVAL |
10s |
Polling interval (only used if WS is down) |
--addr |
BP_ADDR |
127.0.0.1:8080 |
Dashboard listen address |
--debug |
— | false |
Enable SDK debug logging |
| Method | Path | Description |
|---|---|---|
GET |
/ |
Web dashboard |
GET |
/api/state |
Live bot state, positions, and logs |
GET/POST |
/api/config |
Read or update active configuration |
POST |
/api/start |
Start the trading engine |
POST |
/api/stop |
Stop trading and cancel open orders |
POST |
/api/panic |
Cancel all orders and market sell all base assets |
POST |
/api/seed |
Perform a 50/50 balance rebalance |
GET |
/api/balances |
Current account balances |
GET |
/api/fills |
Recent execution history |
The web dashboard is embedded in the binary using go:embed. If you modify the files in the web/ directory, you'll need to rebuild the project.
Disclaimer: Trading involves significant risk. This bot is for educational purposes. Use at your own risk.