A comprehensive and efficient cryptocurrency trading bot built in Python with multiple trading strategies, risk management, and a web dashboard.
- 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
- Python 3.8+
- pip (Python package installer)
-
Clone the repository:
git clone <repository-url> cd CryptoTradingBot
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp env_example.txt .env # Edit .env file with your configuration -
Configure your exchange API keys (optional for live trading):
- Get API keys from your preferred exchange (Binance, Coinbase Pro, etc.)
- Add them to the
.envfile
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=falseThe bot supports various command line options for quick configuration:
python main.py --strategy RSI_STRATEGY --symbol BTC/USDT --timeframe 1h --amount 0.001-
Start the trading bot:
python main.py
-
Run with specific strategy:
python main.py --strategy SMA_CROSSOVER --symbol ETH/USDT
-
Enable live trading (use with caution):
python main.py --live --strategy RSI_STRATEGY
-
Run web dashboard only:
python main.py --dashboard
-
Save configuration to file:
python main.py --save-config my_config.json
-
Load configuration from file:
python main.py --config my_config.json
-
Run backtest:
python main.py --backtest 30
-
Show bot status:
python main.py --status
- 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
- 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
- Description: Uses Bollinger Bands to identify price extremes
- Parameters: BB period, standard deviation
- Usage:
--strategy BOLLINGER_BANDS --bb-period 20 --bb-std 2.0
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
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
Set up Telegram notifications:
- Create a Telegram bot via @BotFather
- Get your chat ID
- Add to
.env:ENABLE_NOTIFICATIONS=true TELEGRAM_BOT_TOKEN=your_bot_token TELEGRAM_CHAT_ID=your_chat_id
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
-
Paper Trading by Default: The bot runs in paper trading mode by default. Enable live trading only after thorough testing.
-
API Keys: Never share your API keys. Use environment variables or secure configuration files.
-
Risk Warning: Cryptocurrency trading involves significant risk. Only trade with money you can afford to lose.
-
Testing: Always test strategies thoroughly before using real money.
-
Monitoring: Regularly monitor the bot's performance and adjust parameters as needed.
-
Exchange Connection Error:
- Check your internet connection
- Verify API keys are correct
- Ensure the exchange is available
-
Strategy Not Working:
- Check strategy parameters
- Verify market data is being fetched
- Review logs for errors
-
Dashboard Not Loading:
- Check if port 8050 is available
- Verify all dependencies are installed
- Check browser console for errors
Logs are saved to:
trading_bot_YYYYMMDD.log- Daily log filestrading_bot.log- Current session log
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
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.
For support and questions:
- Check the logs for error messages
- Review the configuration
- Open an issue on GitHub
Happy Trading! 🚀