This project provides a framework for creating and simulating crypto trading bots using the Binance API. It allows for the evaluation and comparison of different bot strategies under simulated scenarios (e.g., 100 USDT invested, 1-minute intervals). This is purely for simulation purposes; no real trading is involved.
pyproject.toml: Project metadata and dependencies.evaluate.py: Script to run simulations and evaluate bot performance.generate_dataset.py: Script to generate datasets for model training.train.py: Script for training models.config/:config.py: Configuration script storing hyperparameters.
data/: Contains data files (ignored).klines/: Storage of klines data by symbol and interval.outputs/: Storage of evaluation plots and other visual data.weights/: Storage of model weights.
src/: Contains core application logic.bot/: Defines baseBotclass and various bot implementations (e.g.,RandomBot,ProfitBot,RNNBot,RLBot).models/: Core architecture of ML and DL models.simulation/: Trading simulation logic.training/: Training and testing implementation for models.dataset.py: Handles data loading and processing for models.utils.py: Utility functions and enums (e.g.,Action).visualization.py: Functions for plotting trade history.
-
Install dependencies: This project uses
uvfor dependency management. Ensure you haveuvinstalled.uv pip install --with-sources .Alternatively, you can use:
uv pip install --sync . -
Binance API Credentials: Update
API_KEYandAPI_SECRETin.envwith your Binance API credentials.
Download historical kline data from Binance.
python generate_dataset.py --symbol BTCUSDT --interval 1h --start "2 Jan 2024" --end "1 Jan 2025"Arguments:
--symbol: Trading pair symbol (default:BTCUSDT).--interval: Kline interval (e.g.,1m,1h,1d).--start: Start date (default:"1 Jan 2024").--end: End date (default:"1 Jan 2025").--dummy: Generate a dummy dataset with a predictable pattern.
Train the RNN or RL models.
uv run train.py --model_type rnnAvailable model types are rnn and rl. The training process uses the parameters defined in config/config.py. Trained model weights will be saved in the data/weights/ directory.
Evaluate the performance of the bots using historical data.
python evaluate.pyBy default, this script evaluates RandomBot, ProfitBot, and RNNBot. You can configure which bots to run by editing the bots list in evaluate.py. The evaluation results and plots will be saved in the plots/ directory.
The config/config.py file contains the main configuration for the simulation, training, and model parameters.
| Parameter | Description |
|---|---|
INITIAL_BALANCE |
Starting balance in USDT for the simulation. |
N_KLINES |
Number of klines to consider for each bot action. |
N_EVALUATE |
Number of klines to evaluate over. |
COMMISSION_RATE |
Trading commission rate. |
INTERVAL |
Default kline interval for simulation. |
DATA_PATH |
Path to the training dataset. |
EPOCHS |
Number of training epochs. |
BATCH_SIZE |
Batch size for training. |
LEARNING_RATE |
Learning rate for the optimizer. |
RNN_MODEL_PATH |
Path to the pretrained RNN model weights. |
- RandomBot: Makes random buy/sell/wait decisions.
- ProfitBot: Implements a rule-based strategy with target profit, stop loss, and missed profit logic.
- RNNBot: Uses a Recurrent Neural Network to predict trading decision.
- RLBot: Uses a Reinforcement Learning agent to predict trading decision.
Contributions are welcome! Please feel free to submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.