Skip to content

whos-muturi/cryptoBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Crypto Trading Bot

A comprehensive and efficient cryptocurrency trading bot built in Python with multiple trading strategies, risk management, and a web dashboard.

🚀 Features

  • Multiple Trading Strategies: RSI, SMA Crossover, and Bollinger Bands
  • Risk Management: Stop-loss, take-profit, and position sizing
  • Paper Trading: Test strategies without real money
  • Live Trading: Connect to real exchanges for live trading
  • Web Dashboard: Real-time monitoring and performance tracking
  • Database Storage: Persistent storage of trades and performance data
  • Telegram Notifications: Get alerts for trades and important events
  • Configurable: Easy configuration via environment variables or command line
  • Logging: Comprehensive logging for debugging and monitoring

📋 Requirements

  • Python 3.8+
  • pip (Python package installer)

🛠️ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd CryptoTradingBot
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables:

    cp env_example.txt .env
    # Edit .env file with your configuration
  4. Configure your exchange API keys (optional for live trading):

    • Get API keys from your preferred exchange (Binance, Coinbase Pro, etc.)
    • Add them to the .env file

⚙️ Configuration

Environment Variables

Copy env_example.txt to .env and configure the following variables:

# Exchange Configuration
EXCHANGE_ID=binance
API_KEY=your_api_key_here
SECRET_KEY=your_secret_key_here

# Trading Configuration
SYMBOL=BTC/USDT
TRADE_AMOUNT=0.001
TIMEFRAME=1h

# Strategy Configuration
STRATEGY_TYPE=RSI_STRATEGY
RSI_PERIOD=14
RSI_OVERBOUGHT=70
RSI_OVERSOLD=30

# Risk Management
STOP_LOSS_PERCENTAGE=5.0
TAKE_PROFIT_PERCENTAGE=10.0
ENABLE_LIVE_TRADING=false

Command Line Options

The bot supports various command line options for quick configuration:

python main.py --strategy RSI_STRATEGY --symbol BTC/USDT --timeframe 1h --amount 0.001

🎯 Usage

Basic Usage

  1. Start the trading bot:

    python main.py
  2. Run with specific strategy:

    python main.py --strategy SMA_CROSSOVER --symbol ETH/USDT
  3. Enable live trading (use with caution):

    python main.py --live --strategy RSI_STRATEGY

Advanced Usage

  1. Run web dashboard only:

    python main.py --dashboard
  2. Save configuration to file:

    python main.py --save-config my_config.json
  3. Load configuration from file:

    python main.py --config my_config.json
  4. Run backtest:

    python main.py --backtest 30
  5. Show bot status:

    python main.py --status

📊 Trading Strategies

1. RSI Strategy

  • Description: Uses Relative Strength Index to identify overbought/oversold conditions
  • Parameters: RSI period, overbought level, oversold level
  • Usage: --strategy RSI_STRATEGY --rsi-period 14 --rsi-overbought 70 --rsi-oversold 30

2. SMA Crossover Strategy

  • Description: Uses Simple Moving Average crossovers to identify trend changes
  • Parameters: Short SMA period, long SMA period
  • Usage: --strategy SMA_CROSSOVER --sma-short 20 --sma-long 50

3. Bollinger Bands Strategy

  • Description: Uses Bollinger Bands to identify price extremes
  • Parameters: BB period, standard deviation
  • Usage: --strategy BOLLINGER_BANDS --bb-period 20 --bb-std 2.0

🛡️ Risk Management

The bot includes several risk management features:

  • Stop Loss: Automatically sell when loss reaches specified percentage
  • Take Profit: Automatically sell when profit reaches specified percentage
  • Position Sizing: Limit maximum position size
  • Paper Trading: Test strategies without real money

📈 Web Dashboard

The web dashboard provides real-time monitoring:

  • Bot Status: Current bot state and position
  • Performance Metrics: Total P&L, win rate, trade statistics
  • Charts: P&L over time, trade distribution, market data
  • Recent Trades: Detailed trade history

Access the dashboard at: http://localhost:8050

🔔 Notifications

Set up Telegram notifications:

  1. Create a Telegram bot via @BotFather
  2. Get your chat ID
  3. Add to .env:
    ENABLE_NOTIFICATIONS=true
    TELEGRAM_BOT_TOKEN=your_bot_token
    TELEGRAM_CHAT_ID=your_chat_id

📁 Project Structure

CryptoTradingBot/
├── main.py              # Main entry point
├── config.py            # Configuration management
├── trading_bot.py       # Main trading bot class
├── strategies.py        # Trading strategies
├── risk_manager.py      # Risk management
├── database.py          # Database operations
├── notifications.py     # Notification system
├── dashboard.py         # Web dashboard
├── requirements.txt     # Python dependencies
├── env_example.txt      # Environment variables example
└── README.md           # This file

⚠️ Important Notes

  1. Paper Trading by Default: The bot runs in paper trading mode by default. Enable live trading only after thorough testing.

  2. API Keys: Never share your API keys. Use environment variables or secure configuration files.

  3. Risk Warning: Cryptocurrency trading involves significant risk. Only trade with money you can afford to lose.

  4. Testing: Always test strategies thoroughly before using real money.

  5. Monitoring: Regularly monitor the bot's performance and adjust parameters as needed.

🔧 Troubleshooting

Common Issues

  1. Exchange Connection Error:

    • Check your internet connection
    • Verify API keys are correct
    • Ensure the exchange is available
  2. Strategy Not Working:

    • Check strategy parameters
    • Verify market data is being fetched
    • Review logs for errors
  3. Dashboard Not Loading:

    • Check if port 8050 is available
    • Verify all dependencies are installed
    • Check browser console for errors

Logs

Logs are saved to:

  • trading_bot_YYYYMMDD.log - Daily log files
  • trading_bot.log - Current session log

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

⚖️ Disclaimer

This software is for educational purposes only. Use at your own risk. The authors are not responsible for any financial losses incurred through the use of this software.

🆘 Support

For support and questions:

  • Check the logs for error messages
  • Review the configuration
  • Open an issue on GitHub

Happy Trading! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages