A paper trading bot implementing martingale grid strategy across three cryptocurrency pairs simultaneously.
This bot trades BTC/USDT, ETH/USDT, and XRP/USDT using a sophisticated martingale grid strategy with:
- Grid-based entry: Buys on dips at calculated intervals
- Scaling positions: Increases position size using martingale principles
- Take Profit: Automatic exits at configured profit targets
- Stop Loss: Risk management with configurable stop losses
- Paper Trading: 100% simulated - no real money at risk
- Multi-Pair Trading: Simultaneously manages 3 different pairs
- Dual Price Feeds: Kraken API primary, CoinGecko fallback
- Smart Scaling: Dynamic position sizing with volume and step scaling
- Per-Pair Configuration: Individual settings for each trading pair
- Mobile-First: Designed to run on Pydroid3 (Android)
- Lightweight: No dependencies on heavy libraries
- Real-Time Monitoring: Live logging of all trading decisions
- Initial Entry: Opens position with initial order size
- Grid Buys: Places buy orders at configured intervals below entry
- Position Scaling: Each safety order is larger than the previous
- Take Profit: Closes entire position when profit target is reached
- Stop Loss: Exits position if loss exceeds threshold
BTC/USDT (Conservative):
- Total Investment: 90 USDT
- Initial Order: 10 USDT
- Grid Spacing: 0.5%
- Take Profit: 0.8%
- Safety Orders: 8
- Stop Loss: 9%
ETH/USDT (Balanced):
- Total Investment: 90 USDT
- Initial Order: 10 USDT
- Grid Spacing: 0.7%
- Take Profit: 1.2%
- Safety Orders: 8
- Stop Loss: 9%
XRP/USDT (Aggressive):
- Total Investment: 90 USDT
- Initial Order: 10 USDT
- Grid Spacing: 1.0%
- Take Profit: 1.5%
- Safety Orders: 8
- Stop Loss: 10%
- Python 3.9+
- requests library
Windows:
pip install requestsLinux/macOS:
pip3 install requests- Install Pydroid3 from Google Play
- Install requests: Menu → Pip → Install "requests"
- Copy script to Pydroid3
- Run!
Windows:
python tri_martingale_bot.pyLinux/macOS:
python3 tri_martingale_bot.pyThe bot will:
- Start monitoring all 3 pairs
- Fetch prices every 10 seconds
- Execute paper trades based on grid strategy
- Log all decisions to console
Edit the configuration section in the script:
# Polling interval
POLL_SECONDS = 10
# Logging verbosity
LOG_LEVEL = "INFO" # or "DEBUG"
# Price feed fallback
USD_EQUIV_OK = True # Allow CoinGecko if Kraken fails
# Per-pair settings
PAIR_CONFIGS = {
"BTC/USDT": {
"total_invest": 90.0, # Total budget for this pair
"initial_order": 10.0, # First order size
"price_scale": 0.005, # Grid spacing (0.5%)
"take_profit": 0.008, # TP threshold (0.8%)
"safety_orders": 8, # Number of grid levels
"vol_scale": 1.25, # Volume multiplier
"step_scale": 1.15, # Step size multiplier
"stop_loss_pct": 0.09 # SL threshold (9%)
},
# ... ETH and XRP configs
}- Primary: Kraken public API
- Fallback: CoinGecko API (if enabled)
- Error Handling: Graceful degradation on API failures
- Entry Detection: Monitors for favorable entry points
- Grid Calculation: Computes grid levels based on configuration
- Position Tracking: Maintains average entry price
- Profit/Loss Monitoring: Continuously checks against TP/SL
- Volume Scale: 1.25x multiplier per level
- Step Scale: 1.15x increasing grid spacing
- Safety Orders: Up to 8 additional entries per pair
12:34:56 | INFO | [BTC/USDT] Price: 42,150.00 | Position: 0.0237 BTC | Avg: 41,890.00 | P/L: +0.62%
12:35:06 | INFO | [ETH/USDT] Grid Buy Triggered | Size: 0.0085 ETH @ 2,245.00
12:35:16 | INFO | [XRP/USDT] Take Profit Hit! | Closing 1,250 XRP | Profit: +1.52%
Enable detailed logging:
LOG_LEVEL = "DEBUG"Shows:
- API responses
- Grid calculations
- Decision logic
- Position updates
- Paper Trading Only: No real orders executed
- Stop Loss Protection: Configurable per pair
- Budget Caps: Total investment limits
- API Fallback: Redundant price sources
- Error Recovery: Continues running on failures
- Threading: Non-blocking multi-pair monitoring
Note: Results in paper trading may differ from live trading due to:
- Simulated fills
- No slippage
- No fee modeling
- Perfect execution
- Reduce
take_profitpercentage - Increase
price_scale(wider grids) - Reduce
total_invest - Lower
vol_scale
- Increase
take_profitpercentage - Decrease
price_scale(tighter grids) - Increase
safety_orders - Higher
vol_scale
Add new pairs to PAIR_CONFIGS with appropriate settings for that asset's volatility.
- Paper Trading Only: Not connected to real exchange
- Simplified Fills: Assumes instant execution
- No Fee Modeling: Actual profits would be lower
- Basic Risk Management: Consider adding position correlation checks
- Manual Restart: No state persistence across restarts
Designed for Pydroid3 with:
- No numpy/pandas dependencies
- Lightweight HTTP requests
- Efficient threading
- Console-based output
API Errors:
- Enable
USD_EQUIV_OKfor CoinGecko fallback - Check internet connection
- Verify API endpoints are accessible
No Trades Executing:
- Check if grids are configured correctly
- Verify price movements are sufficient
- Review
price_scalesettings
High Memory Usage:
- Restart periodically on mobile
- Reduce
POLL_SECONDSto lighten load
This is a paper trading bot for educational purposes only. Martingale strategies can lead to significant losses in live trading. Never use martingale strategies with money you can't afford to lose.
Potential improvements:
- Live trading integration (CAREFUL!)
- State persistence
- Web dashboard
- Fee modeling
- Correlation analysis
- Dynamic grid adjustment
Provided as-is for personal use and learning.
Built for mobile trading on Pydroid3