DEV Community

TateLyman
TateLyman

Posted on

Python Async Grid Trading Bot for Solana — Architecture and Backtest Results

I built a grid trading bot in Python that trades SOL on Jupiter DEX. 576-config backtest → best returned +11.7% while SOL crashed 37%.

Architecture

main.py               Async orchestrator
bot/grid_engine.py    Core grid logic + DGT repositioning
bot/paper_trader.py   Simulated trading
bot/order_router.py   Jupiter swap execution
bot/risk_manager.py   Kill switches
feeds/price_feed.py   Pyth oracle + Jupiter fallback
backtest/sweep.py     576-config parallel parameter sweep
Enter fullscreen mode Exit fullscreen mode

How Grid Trading Works

Place buy orders below current price, sell orders above. Each completed buy→sell cycle is profit.

Dynamic Grid Threshold (DGT)

If price breaks out of grid range, the bot sells everything, recalculates, and rebuilds the grid at the new center. This prevents the grid from being stranded during strong trends.

Backtest: 576 Configurations

Sweep parameters:

  • Levels: [6, 8, 10, 12]
  • Spacing: [1.0%, 1.5%, 2.0%, 2.5%, 3.0%, 3.5%]
  • Reserve: [0%, 5%, 10%, 15%]
  • DGT: [on, off]
  • Rebalance: [0.8, 0.9, 1.0]

Winner: 10 levels, 2.0% geometric spacing, 5% reserve, DGT enabled = +11.7% return.

Key Insight

Grid trading profits from volatility, not direction. A crashing market with lots of oscillation generates more grid fills than a smooth uptrend.

Get the grid bot — 0.5 SOL

Also: Telegram trading bot (free) | Bot source code (2 SOL)

Top comments (0)