Skip to content

devstorm2576916/ethereum-grid-bot

Repository files navigation

Ethereum Grid Trading Bot

πŸ‘‰ Contact me on Telegram

A professional, profitable automated trading bot that implements the Grid Trading Strategy for Ethereum (ETH/USDT). This bot capitalizes on market volatility by placing buy and sell orders at predetermined price levels, profiting from price oscillations.

πŸ“Š Trading Strategy

Grid Trading Explained

Grid trading is a proven profitable strategy that works best in ranging/volatile markets:

  1. Grid Setup: Creates a grid of buy and sell orders at regular price intervals
  2. Buy Low: Automatically buys ETH when the price drops to lower grid levels
  3. Sell High: Automatically sells ETH when the price rises to upper grid levels
  4. Continuous Profit: Each completed buy-sell cycle generates profit
  5. Volatility Harvesting: Profits from market oscillations without predicting direction

Profitability Factors

  • Market Volatility: Higher volatility = more grid level hits = more profit
  • Grid Spacing: Optimized spacing balances frequency and profit per trade
  • Investment Size: Larger investment spreads across grids increases potential returns
  • Fee Optimization: Uses limit orders to minimize trading fees

Example Profit Scenario

Investment: $1,000 USDT
Grid Range: $3,000 - $3,300 (5% range)
Grid Levels: 10 levels
Grid Spacing: $30 per level

Scenario:
- Price drops from $3,150 to $3,120 β†’ Buy triggered at $3,120
- Price rises back to $3,150 β†’ Sell triggered at $3,150
- Profit per cycle: ($3,150 - $3,120) Γ— ETH amount = ~$3-5 per cycle
- With 10-20 cycles per day in volatile markets = $30-100 daily potential

✨ Features

  • βœ… Automated Grid Trading - Sets up and manages grid orders automatically
  • βœ… Multi-Exchange Support - Works with Binance, Coinbase, Kraken, etc. (via CCXT)
  • βœ… Test Mode - Safe testing without real trades
  • βœ… Real-time Monitoring - Tracks profits, balances, and order status
  • βœ… Risk Management - Configurable stop-loss and position limits
  • βœ… Detailed Logging - Complete audit trail of all operations
  • βœ… Easy Configuration - JSON-based configuration
  • βœ… Auto-Recovery - Handles network issues and exchange errors gracefully

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Cryptocurrency exchange account (Binance recommended)
  • API keys with trading permissions
  • Minimum $500-1000 USDT recommended for optimal grid performance

Installation

1. Clone or Download This Repository

git clone https://github.com/yourusername/ethereum-grid-bot.git
cd ethereum-grid-bot

Or download and extract the ZIP file to your preferred directory.

2. Install Python Dependencies

# Windows
python -m pip install --upgrade pip
pip install -r requirements.txt

# Linux/Mac
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt

3. Configure Your Bot

Edit config.json with your settings:

{
  "exchange": {
    "name": "binance",
    "api_key": "YOUR_API_KEY_HERE",
    "api_secret": "YOUR_API_SECRET_HERE"
  },
  "trading": {
    "symbol": "ETH/USDT",
    "total_investment": 1000,
    "test_mode": true,
    "cancel_on_exit": true,
    "update_interval": 60,
    "amount_precision": 4
  },
  "grid": {
    "num_grids": 10,
    "price_range_percent": 5
  },
  "risk_management": {
    "stop_loss_percent": 10,
    "take_profit_percent": 20,
    "max_position_size": 0.5
  }
}

⚠️ Security Best Practice: Use a .env file for API keys (see Advanced Configuration below).

4. Get Exchange API Keys

For Binance:
  1. Log in to Binance
  2. Go to Profile β†’ API Management
  3. Create a new API key
  4. Enable "Enable Spot & Margin Trading"
  5. Disable "Enable Withdrawals" (for security)
  6. Set IP restrictions if possible
  7. Copy your API Key and Secret Key
For Other Exchanges:
  • Coinbase Pro: Account β†’ API β†’ New API Key
  • Kraken: Settings β†’ API β†’ Generate New Key
  • KuCoin: Account β†’ API Management β†’ Create API

5. Test the Bot (Safe Mode)

First, run in test mode (no real trades):

# Windows
python grid_bot.py

# Linux/Mac
python3 grid_bot.py

You should see output like:

2025-10-10 10:30:45 - INFO - Initialized Grid Bot for ETH/USDT
2025-10-10 10:30:46 - INFO - Successfully connected to binance
2025-10-10 10:30:46 - INFO - Current Price: $3156.78
2025-10-10 10:30:46 - INFO - Grid levels calculated: 10 levels
2025-10-10 10:30:46 - INFO - Range: $2998.94 - $3314.62
2025-10-10 10:30:46 - INFO - [TEST MODE] Would place buy order...

6. Run Live Trading

Once you've verified everything works in test mode:

  1. Fund your account with USDT (match your total_investment setting)
  2. Disable test mode in config.json: Set "test_mode": false
  3. Start the bot:
python grid_bot.py

7. Monitor Your Bot

The bot will:

  • Display real-time status every minute
  • Log all operations to grid_bot.log
  • Show profit calculations after each trade cycle

To stop the bot safely: Press Ctrl+C (it will cancel all open orders)

βš™οΈ Configuration Guide

Basic Settings

Parameter Description Recommended Value
symbol Trading pair ETH/USDT
total_investment Total USDT to invest 1000 - 10000
num_grids Number of grid levels 8 - 15
price_range_percent Grid range from current price 3 - 7
update_interval Check interval (seconds) 30 - 120

Optimization Tips

For Low Volatility Markets (ETH moving <2% daily):

{
  "grid": {
    "num_grids": 15,
    "price_range_percent": 3
  }
}

For High Volatility Markets (ETH moving >5% daily):

{
  "grid": {
    "num_grids": 8,
    "price_range_percent": 7
  }
}

For Small Accounts (<$1000):

{
  "trading": {
    "total_investment": 500
  },
  "grid": {
    "num_grids": 8
  }
}

For Large Accounts (>$10000):

{
  "trading": {
    "total_investment": 10000
  },
  "grid": {
    "num_grids": 20,
    "price_range_percent": 5
  }
}

Advanced Configuration with Environment Variables

For better security, create a .env file:

# .env file
EXCHANGE_API_KEY=your_api_key_here
EXCHANGE_API_SECRET=your_api_secret_here

Then create config_secure.py:

import os
from dotenv import load_dotenv
import json

load_dotenv()

config = {
    "exchange": {
        "name": "binance",
        "api_key": os.getenv("EXCHANGE_API_KEY"),
        "api_secret": os.getenv("EXCHANGE_API_SECRET")
    },
    # ... rest of config
}

with open('config.json', 'w') as f:
    json.dump(config, f, indent=2)

πŸ“ˆ Performance Monitoring

Real-time Logs

Monitor grid_bot.log for detailed operation logs:

# Windows PowerShell
Get-Content grid_bot.log -Wait -Tail 50

# Linux/Mac
tail -f grid_bot.log

πŸ‘‰ Contact me on Telegram

Key Metrics to Track

  • Total Profit: Cumulative profit from all completed cycles
  • Fill Rate: How often grid orders are being filled
  • Active Orders: Number of pending orders in the grid
  • Balance Changes: Track ETH and USDT balance over time

Expected Performance

Conservative estimates with $1,000 investment:

Market Condition Daily Trades Daily Profit Monthly Profit
Low Volatility 5-10 cycles $5-15 $150-450
Medium Volatility 10-20 cycles $15-40 $450-1200
High Volatility 20-40 cycles $40-100+ $1200-3000+

Note: Past performance doesn't guarantee future results. Always start with small amounts.

πŸ›‘οΈ Risk Management

Built-in Safety Features

  1. Test Mode: Practice without real money
  2. Position Limits: Prevents over-exposure
  3. Auto-Cancel: Cancels orders on shutdown
  4. Error Handling: Recovers from network issues
  5. Rate Limiting: Respects exchange API limits

Best Practices

βœ… DO:

  • Start with test mode
  • Use only money you can afford to lose
  • Monitor the bot regularly
  • Keep API keys secure
  • Enable 2FA on your exchange account
  • Set IP restrictions on API keys
  • Start with small investment and scale up

❌ DON'T:

  • Don't enable withdrawal permissions on API keys
  • Don't share your API keys
  • Don't invest more than you can afford to lose
  • Don't ignore stop-loss settings
  • Don't run multiple bots on same account without coordination

Stop-Loss Protection

The bot includes configurable stop-loss:

{
  "risk_management": {
    "stop_loss_percent": 10
  }
}

This will stop the bot if your total loss exceeds 10%.

πŸ”§ Troubleshooting

Common Issues

"Failed to connect to exchange"

  • Solution: Check your API keys are correct
  • Verify API permissions include spot trading
  • Check your internet connection

"Insufficient balance"

  • Solution: Ensure your USDT balance >= total_investment
  • Check if funds are locked in other orders

"Order placement failed"

  • Solution: Check minimum order size for your exchange
  • Verify trading pair is correct (ETH/USDT)
  • Ensure you have enough balance

Bot stops unexpectedly

  • Solution: Check grid_bot.log for errors
  • Verify network connection
  • Ensure exchange API is operational

Getting Help

  1. Check the log file: grid_bot.log
  2. Review exchange status page
  3. Verify API key permissions
  4. Test with smaller investment first

πŸ“ Project Structure

ethereum-grid-bot/
β”œβ”€β”€ grid_bot.py          # Main bot code
β”œβ”€β”€ config.json          # Configuration file
β”œβ”€β”€ config.example.json  # Example configuration
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ README.md           # This file
β”œβ”€β”€ .env.example        # Example environment variables
β”œβ”€β”€ .gitignore          # Git ignore file
└── grid_bot.log        # Log file (created on first run)

πŸ”„ Updates and Maintenance

Keeping Your Bot Updated

# Update Python packages
pip install --upgrade -r requirements.txt

# Update ccxt (exchange library)
pip install --upgrade ccxt

Recommended Maintenance

  • Daily: Check logs and performance
  • Weekly: Review and adjust grid parameters based on market conditions
  • Monthly: Update dependencies and review profitability

πŸ’‘ Advanced Features

Multiple Trading Pairs

Run multiple bots for different pairs:

# Terminal 1 - ETH/USDT
python grid_bot.py config_eth.json

# Terminal 2 - BTC/USDT  
python grid_bot.py config_btc.json

Dynamic Grid Adjustment

The bot can be extended to adjust grid ranges based on volatility:

# Calculate volatility and adjust range
volatility = calculate_volatility()
if volatility > 0.05:
    config['grid']['price_range_percent'] = 7
else:
    config['grid']['price_range_percent'] = 3

Backtesting

Test strategy on historical data before live trading (implement separately).

πŸ“Š Exchange Compatibility

Tested and compatible with:

  • βœ… Binance (Recommended - lowest fees)
  • βœ… Binance US
  • βœ… Coinbase Pro
  • βœ… Kraken
  • βœ… KuCoin
  • βœ… Bitfinex
  • βœ… Huobi

Any exchange supported by CCXT library should work with minor configuration adjustments.

πŸ“ License

MIT License - feel free to modify and distribute

πŸš€ Quick Start Checklist

  • Python 3.8+ installed
  • Dependencies installed (pip install -r requirements.txt)
  • Exchange account created and verified
  • API keys generated with spot trading enabled
  • Withdrawals disabled on API key
  • config.json updated with your API keys
  • Sufficient USDT balance in your account
  • Test mode verified (test_mode: true)
  • Bot runs successfully in test mode
  • Switched to live mode (test_mode: false)
  • Monitoring logs and performance

Happy Trading! πŸ“ˆπŸ’°

πŸ‘‰ Contact me on Telegram Remember: Start small, test thoroughly, and scale gradually as you gain confidence in the bot's performance.

About

πŸ”΅ ethereum grid trading bot

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages