Skip to content

Welcome to the Ultimate Crypto Trading Bot! This bot is designed to automate cryptocurrency trading using a hybrid strategy that combines XGBoost (machine learning) and PPO (reinforcement learning). It supports live trading, backtesting, and periodic retraining of models.

License

Notifications You must be signed in to change notification settings

jay37749/Ultimate-Crypto-Trading-Bot

Repository files navigation

image alt

Hi 👋, I'm jay37749

I'm a professional Frontend Developer from Kenya.

jay37749

jay37749

  • 🔭 I’m currently working on Ultimate Crypto Trading Bot

  • 👯 I’m looking to collaborate on Ulitimate Crypto Trading Bot

  • 🤝 I’m looking for help with Ulitimate Crypto Trading Bot

  • 📫 How to reach me jay37749@gmail.com

  • Welcome to the Ultimate Crypto Trading Bot! This bot is designed to automate cryptocurrency trading using a hybrid strategy that combines XGBoost (machine learning) and PPO (reinforcement learning). It supports live trading, backtesting, and periodic retraining of models. Below, you'll find everything you need to set up, configure, and run the bot.

Table of Contents

Overview

Prerequisites

Installation

Configuration

Running the Bot

Live Trading Mode

Backtesting Mode

Retrain XGBoost Model

Live RL Learning Mode

Risk Management

Troubleshooting

Contributing

License

Overview

The bot is built to trade on Binance Futures and uses the following key components:

#XGBoost Model#: A machine learning model trained to predict buy/sell signals.

PPO Model: A reinforcement learning model that adapts to market conditions.

Hybrid Strategy: Combines signals from both XGBoost and PPO for decision-making.

Risk Management: Implements stop-loss, take-profit, and position sizing.

Backtesting: Evaluates the strategy on historical data.

Real-Time Trading: Executes trades in real-time using WebSocket.

Prerequisites

Before running the bot, ensure you have the following installed:

Python 3.8 or higher

Binance API Key and Secret: Obtain these from your Binance account.

Required Python Libraries:

pandas

numpy

binance

xgboost

stable-baselines3

scikit-learn

matplotlib

vaderSentiment

You can install the required libraries using the following command:

Copy

pip install pandas numpy binance xgboost stable-baselines3 scikit-learn matplotlib vaderSentiment

Installation

Clone the Repository:

Copy

git clone https://github.com/your-repo/ultimate-crypto-trading-bot.git

Set Up Configuration:

Open the config.json file and replace the api_key and api_secret with your Binance API credentials.

Configure the trading pairs, leverage, risk settings, and other parameters as needed.

Download Pre-Trained Models:

Ensure the trained_xgboost_model.pkl and trained_rl_model.zip files are in the project directory. These are the pre-trained models for XGBoost and PPO, respectively.

Configuration

The bot's configuration is stored in config.json. Below are the key parameters:

API Credentials:

Copy

"api_key": "your_api_key",

"api_secret": "your_api_secret"

Trading Pairs:

Copy

"trading_pairs": ["BTCUSDT", "ETHUSDT"]

Leverage and Risk Settings:

Copy

"default_leverage": 20,

"default_risk": 0.01,

"default_risk_percentage": 0.01,

"default_risk_factor": 2,

"default_reward_factor": 6,

"min_risk_to_reward": 3

Model Settings:

Copy

"hybrid_settings": { "enable_hybrid_mode": true, "xgboost_weight": 0.6, "rl_weight": 0.4 }

Running the Bot

The bot can be run in several modes. Use the following commands to start the bot:

Live Trading Mode

To run the bot in live trading mode:

Copy

python run_bot.py --mode=live

This mode connects to Binance via WebSocket and executes trades in real-time.

Ensure your API credentials are correctly configured in config.json.

Backtesting Mode

To run the bot in backtesting mode:

Copy

python run_bot.py --mode=backtest

This mode evaluates the strategy on historical data and generates performance metrics (e.g., Sharpe ratio, max drawdown).

Backtesting results are logged and visualized using an equity curve.

image alt

Retrain XGBoost Model

To retrain the XGBoost model with the latest data:

Copy

python run_bot.py --mode=retrain_xgboost

This mode fetches recent historical data and retrains the XGBoost model.

The retrained model is saved as trained_xgboost_model.pkl.

Live RL Learning Mode

To enable live reinforcement learning:

Copy

python run_bot.py --mode=train_rl

This mode allows the PPO model to learn from real-time market data.

The updated model is saved as trained_rl_model.zip.

Risk Management

The bot includes robust risk management features:

Position Sizing: Calculates the position size based on risk percentage and ATR (Average True Range).

Stop-Loss and Take-Profit: Automatically sets stop-loss and take-profit levels based on risk and reward factors.

Risk-to-Reward Ratio: Skips trades that do not meet the minimum risk-to-reward ratio (configurable in config.json).

image alt

Troubleshooting

Common Issues

API Errors:

Ensure your Binance API key and secret are correct.

Check if your IP is whitelisted on Binance.

Data Fetching Errors:

Ensure you have a stable internet connection.

If historical data fetching fails, try reducing the lookback period.

Model Loading Errors:

Ensure the pre-trained models (trained_xgboost_model.pkl and trained_rl_model.zip) are in the correct directory.

Error Logs

Errors are logged in error_log.txt for debugging.

Contributing

Contributions are welcome! If you'd like to improve the bot, please follow these steps:

Fork the repository.

Create a new branch for your feature or bugfix.

Submit a pull request with a detailed description of your changes.

License

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

Support

For any questions or issues, please open an issue on the GitHub repository or contact the maintainers.

Happy trading! 🚀

Connect with me:

Languages and Tools:

aws blender c cplusplus csharp css3 docker dotnet figma git html5 illustrator java javascript linux nodejs photoshop php python react ruby

 jay37749

About

Welcome to the Ultimate Crypto Trading Bot! This bot is designed to automate cryptocurrency trading using a hybrid strategy that combines XGBoost (machine learning) and PPO (reinforcement learning). It supports live trading, backtesting, and periodic retraining of models.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published