Skip to content

SamPujade/TradeBotLab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binance Trading Bot Simulator

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.

Project Structure

  • 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 base Bot class 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.

Setup

  1. Install dependencies: This project uses uv for dependency management. Ensure you have uv installed.

    uv pip install --with-sources .

    Alternatively, you can use:

    uv pip install --sync .
  2. Binance API Credentials: Update API_KEY and API_SECRET in .env with your Binance API credentials.

Usage

1. Generate Dataset

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.

2. Train Models

Train the RNN or RL models.

uv run train.py --model_type rnn

Available 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.

3. Run Evaluation

Evaluate the performance of the bots using historical data.

python evaluate.py

By 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.

Configuration

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.

Bots Implemented

  • 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.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

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

About

Framework to write and evaluate your very own AI (or not) crypto trading bot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages