Skip to content

mgarriga/test-tradebot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trading Bot - Cryptocurrency Algorithmic Trading System

A modular trading bot for cryptocurrency trading using Python, CCXT for exchange connectivity, and comprehensive backtesting capabilities.

Features

  • Modular Architecture: Separate components for Strategy, Exchange Interface, and Risk Management
  • Robust Backtesting Engine: Simulate trades with historical data, commission fees, and slippage
  • Multiple Strategies: EMA Crossover (with more to come)
  • Performance Metrics: Sharpe Ratio, Max Drawdown, Win Rate, Profit Factor
  • Risk Management: Hard-coded Stop Loss and Take Profit with position sizing
  • CLI Dashboard: Real-time terminal output and trade logging
  • TDD Approach: Test-driven development with comprehensive test suite

Tech Stack

  • Language: Python 3.10+
  • Libraries:
    • ccxt - Exchange connectivity
    • pandas & pandas_ta - Data analysis and indicators
    • numpy - Numerical computations
    • tabulate - CLI formatting
    • pytest - Testing framework
  • Database: SQLite (for trade logging)

Project Structure

test-tradebot/
├── src/
│   ├── config.py              # Global configuration
│   ├── data/
│   │   └── ccxt_loader.py    # OHLCV data fetching
│   ├── indicators/
│   │   └── ema_calculator.py # EMA calculations
│   ├── strategy/
│   │   └── ema_crossover.py  # EMA crossover strategy
│   ├── backtesting/
│   │   ├── backtest_engine.py      # Backtesting engine
│   │   └── performance_metrics.py  # Metrics calculation
│   ├── risk/                  # Risk management (coming soon)
│   └── database/              # Database operations (coming soon)
├── tests/
│   ├── test_indicators.py
│   ├── test_data_loader.py
│   ├── test_strategy.py
│   └── test_backtester.py
├── backtest_runner.py         # Main backtest script
├── requirements.txt
└── README.md

Installation

  1. Clone the repository:
git clone <repository-url>
cd test-tradebot
  1. Create a virtual environment:
python -m venv venv
source venv/Scripts/activate  # On Windows
  1. Install dependencies:
pip install -r requirements.txt

Configuration

Edit src/config.py to customize:

  • Trading Pair: Symbol (e.g., "ETH/USDT")
  • Timeframe: Candle size (e.g., "4h")
  • Backtesting Period: Number of days of historical data
  • Risk Parameters: Stop Loss, Take Profit, Max Position Size
  • Strategy Parameters: EMA periods (fast/slow)
  • Commission & Slippage: Exchange-specific fees

Running Tests

Run the complete test suite:

pytest

Run specific test file:

pytest tests/test_backtester.py -v

Run with coverage:

pytest --cov=src tests/

Running Backtest

Run the backtester with the configured strategy:

python backtest_runner.py

This will:

  1. Fetch historical OHLCV data from Binance via CCXT
  2. Calculate technical indicators (EMA)
  3. Generate trading signals based on strategy
  4. Simulate trade execution with realistic commission/slippage
  5. Calculate performance metrics
  6. Display results in a formatted table

Example Output

================================================================================
TRADING BOT - BACKTESTING ENGINE
================================================================================

Configuration:
  Symbol: ETH/USDT
  Timeframe: 4h
  Backtest Period: 90 days
  Initial Capital: $1,000.00
  Strategy: EMA Crossover (9/21)
  Stop Loss: 3%
  Take Profit: 8%

[1] Loading data from binance...
    Loaded 540 candles
    Date range: 2025-11-03 to 2026-03-01

[2] Generating trading signals...
    Buy signals: 8
    Sell signals: 7

[3] Running backtest...

================================================================================
BACKTEST RESULTS
================================================================================

Performance Summary:
┌──────────────────┬─────────────────┐
│ Metric           │ Value           │
├──────────────────┼─────────────────┤
│ Initial Capital  │ $1,000.00       │
│ Final Value      │ $1,245.32       │
│ Total Return     │ $245.32         │
│ Return %         │ 24.53%          │
│ Total Trades     │ 7               │
│ Winning Trades   │ 5               │
│ Losing Trades    │ 2               │
│ Win Rate         │ 71.43%          │
│ Max Drawdown     │ -8.32%          │
│ Sharpe Ratio     │ 1.85            │
└──────────────────┴─────────────────┘

Strategy Guide

EMA Crossover Strategy

  • Signal: When the fast EMA (9) crosses above the slow EMA (21), a BUY signal is generated
  • Exit: When the fast EMA crosses below the slow EMA, a SELL signal is generated
  • Risk Management: Every position has a hard stop loss (3%) and take profit (8%)

Next Steps

  • Implement Paper Trading Mode (real-time with virtual balance)
  • Add Live Trading Mode with API key support
  • Implement additional strategies (RSI, Bollinger Bands, etc.)
  • Add CLI dashboard for real-time monitoring
  • Database logging for all trades
  • Multi-symbol backtesting
  • Walk-forward analysis
  • Monte Carlo analysis

Risk Disclaimer

This trading bot is provided for educational purposes only. Cryptocurrency trading carries significant risk. Always:

  • Use small amounts when testing with live trading
  • Thoroughly backtest any strategy before live deployment
  • Implement proper risk management
  • Never trade capital you cannot afford to lose

Contributing

Pull requests are welcome. For major changes, please open an issue first.

License

MIT License - See LICENSE file for details

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages