A Backpack exchange grid trading bot that supports SOL/USDC trading pair.
https://backpack.exchange/refer/b
I recommend getting Blue Chip NFT Madlads before you trade to get VIP1 tier fees discount.
- Automatically create buy and sell grids within the set price range.
- Dynamically detect account balance to ensure safe trading.
- Automatically execute grid trading strategy.
- Support Telegram notifications (optional).
- Real-time order status monitoring.
- Automatic order exception handling.
- Node.js 16.x or higher version.
- Yarn package manager.
- Backpack exchange account.
- Sufficient trading funds.
-
Clone repository:
git clone [repository-url] cd backpack-grid-bot -
Install dependencies:
yarn install
-
Configure environment variables:
- Copy
.env.copyto.env. - Fill in configuration items as instructed.
- Copy
Configure the following parameters in .env file:
BACKPACK_API_KEY: Backpack API Key.BACKPACK_API_SECRET: Backpack API Secret.SYMBOL: Trading pair name, currently "SOL_USDC".
LOWER_PRICE: Grid lowest price, in USDC (e.g., 200).UPPER_PRICE: Grid highest price, in USDC (e.g., 2000).PRICE_DECIMAL: Price precision, recommended to set as 2.NUMBER_OF_GRIDS: Number of grids, recommended between 100-500.QUANTITY_PER_GRID: Quantity per grid, in SOL (e.g., 0.03).
TELEGRAM_BOT_API_TOKEN: Telegram bot API Token.TELEGRAM_TARGET_CHAT_ID: Telegram target chat ID.
Before starting the bot, please ensure sufficient funds in your account:
- SOL requirement: NUMBER_OF_GRIDS × QUANTITY_PER_GRID.
- USDC requirement: NUMBER_OF_GRIDS × QUANTITY_PER_GRID × UPPER_PRICE.
For example, using default configuration:
- SOL requirement: 360 × 0.03 = 10.8 SOL.
- USDC requirement: 360 × 0.03 × 2000 = 21,600 USDC.
yarn start- Please carefully check configuration parameters before first run.
- Ensure sufficient funds in account, otherwise the bot will wait until funds are sufficient.
- Recommend testing strategy with small funds first.
- Monitor bot running status through Telegram (if configured).
- Grid trading strategy is suitable for oscillating markets, not for trending markets.
- Please set appropriate parameters according to your risk tolerance.
- Recommend testing strategy with small funds first.
- Market involves risks, invest with caution.
MIT Source: https://github.com/pordria/backpack-grid-bot
Source: https://github.com/backpack-exchange/bpx-openapi
The Backpack Exchange API is designed for programmatic trade execution. All endpoints requiring state mutation need requests to be signed with an ED25519 keypair for authentication.
- REST API Base URL:
https://api.backpack.exchange/ - WebSocket API URL:
wss://ws.backpack.exchange/
Signed requests require the following headers:
X-Timestamp: Unix time in milliseconds.X-Window: Time window in milliseconds (default: 5000, max: 60000).X-API-Key: Base64 encoded verifying key of the ED25519 keypair.X-Signature: Base64 encoded signature.
-
Market Data
- Get Ticker:
GET /api/v1/ticker. - Get Mark Price:
GET /api/v1/markPrice. - Get Open Interest:
GET /api/v1/openInterest.
- Get Ticker:
-
Assets & Markets
- Get Assets:
GET /api/v1/assets. - Get Markets:
GET /api/v1/markets. - Get Collateral:
GET /api/v1/collateral.
- Get Assets:
-
Borrow/Lend Markets
- Get Markets:
GET /api/v1/borrowLend/markets.
- Get Markets:
-
Account Management
- Get Account:
GET /api/v1/account. - Get Position:
GET /api/v1/position. - Get Collateral:
GET /api/v1/capital/collateral.
- Get Account:
-
Order Management
- Place Order:
POST /api/v1/order. - Get Open Orders:
GET /api/v1/orders. - Cancel Order:
DELETE /api/v1/order. - Cancel All Orders:
DELETE /api/v1/orders.
- Place Order:
-
History
- Order History:
GET /wapi/v1/history/orders. - Fill History:
GET /wapi/v1/history/fills. - PnL History:
GET /wapi/v1/history/pnl. - Funding History:
GET /wapi/v1/history/funding. - Borrow History:
GET /wapi/v1/history/borrowLend. - Interest History:
GET /wapi/v1/history/interest.
- Order History:
-
Capital Management
- Get Deposit Address:
GET /wapi/v1/capital/deposit/address. - Get Deposits:
GET /wapi/v1/capital/deposits. - Get Withdrawals:
GET /wapi/v1/capital/withdrawals. - Request Withdrawal:
POST /wapi/v1/capital/withdrawals.
- Get Deposit Address:
Connect to wss://ws.backpack.exchange to access real-time data streams.
- Trade Stream:
trades.<symbol>. - Ticker Stream:
ticker.<symbol>. - Depth Stream:
depth.<symbol>. - Kline Stream:
kline.<interval>.<symbol>. - Mark Price Stream:
markPrice.<symbol>.
- Order Updates:
account.orderUpdate. - Position Updates:
account.positionUpdate. - Balance Updates:
account.balanceUpdate.
- Added order expiry reason to order update stream.
- Added
cumulativeInterestto borrow lend position. - Added borrow lend history per position endpoint.
- Added
timestampfield to depth endpoint. - Converted all error responses to JSON with error codes.