Skip to content

Multi-pair martingale grid strategy for BTC/ETH/XRP - paper trading mode, mobile-first (Pydroid3)

License

Notifications You must be signed in to change notification settings

Rors78/tri-martingale-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tri-Pair Martingale Bot

A paper trading bot implementing martingale grid strategy across three cryptocurrency pairs simultaneously.

Overview

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

Features

  • 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

Trading Strategy

Martingale Grid System

  1. Initial Entry: Opens position with initial order size
  2. Grid Buys: Places buy orders at configured intervals below entry
  3. Position Scaling: Each safety order is larger than the previous
  4. Take Profit: Closes entire position when profit target is reached
  5. Stop Loss: Exits position if loss exceeds threshold

Per-Pair Configuration

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%

Installation

Requirements

  • Python 3.9+
  • requests library

Windows:

pip install requests

Linux/macOS:

pip3 install requests

Mobile (Pydroid3)

  1. Install Pydroid3 from Google Play
  2. Install requests: Menu → Pip → Install "requests"
  3. Copy script to Pydroid3
  4. Run!

Usage

Basic Run

Windows:

python tri_martingale_bot.py

Linux/macOS:

python3 tri_martingale_bot.py

The bot will:

  1. Start monitoring all 3 pairs
  2. Fetch prices every 10 seconds
  3. Execute paper trades based on grid strategy
  4. Log all decisions to console

Configuration

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
}

How It Works

Price Fetching

  1. Primary: Kraken public API
  2. Fallback: CoinGecko API (if enabled)
  3. Error Handling: Graceful degradation on API failures

Order Logic

  1. Entry Detection: Monitors for favorable entry points
  2. Grid Calculation: Computes grid levels based on configuration
  3. Position Tracking: Maintains average entry price
  4. Profit/Loss Monitoring: Continuously checks against TP/SL

Scaling Algorithm

  • Volume Scale: 1.25x multiplier per level
  • Step Scale: 1.15x increasing grid spacing
  • Safety Orders: Up to 8 additional entries per pair

Monitoring

Console Output

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%

Debug Mode

Enable detailed logging:

LOG_LEVEL = "DEBUG"

Shows:

  • API responses
  • Grid calculations
  • Decision logic
  • Position updates

Safety Features

  • 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

Performance Expectations

Note: Results in paper trading may differ from live trading due to:

  • Simulated fills
  • No slippage
  • No fee modeling
  • Perfect execution

Customization Tips

More Conservative

  • Reduce take_profit percentage
  • Increase price_scale (wider grids)
  • Reduce total_invest
  • Lower vol_scale

More Aggressive

  • Increase take_profit percentage
  • Decrease price_scale (tighter grids)
  • Increase safety_orders
  • Higher vol_scale

Different Pairs

Add new pairs to PAIR_CONFIGS with appropriate settings for that asset's volatility.

Known Limitations

  • 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

Mobile Optimization

Designed for Pydroid3 with:

  • No numpy/pandas dependencies
  • Lightweight HTTP requests
  • Efficient threading
  • Console-based output

Troubleshooting

API Errors:

  • Enable USD_EQUIV_OK for 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_scale settings

High Memory Usage:

  • Restart periodically on mobile
  • Reduce POLL_SECONDS to lighten load

⚠️ Risk Disclaimer

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.

Future Enhancements

Potential improvements:

  • Live trading integration (CAREFUL!)
  • State persistence
  • Web dashboard
  • Fee modeling
  • Correlation analysis
  • Dynamic grid adjustment

License

Provided as-is for personal use and learning.


Built for mobile trading on Pydroid3

About

Multi-pair martingale grid strategy for BTC/ETH/XRP - paper trading mode, mobile-first (Pydroid3)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages