A Django-based cryptocurrency algorithmic trading application for backtesting technical analysis strategies.
Crypto Trader is a comprehensive trading platform built with Django that enables cryptocurrency traders to fetch market data, implement technical analysis indicators, create trading strategies, and backtest them against historical data. The application focuses on providing a robust foundation for strategy development and backtesting, with a clean and intuitive interface.
- Data Management: Fetch and store cryptocurrency price data from Binance
- Technical Analysis: Calculate and visualize indicators like SMA, RSI, etc.
- Strategy Development: Implement and test trading strategies
- Backtesting: Evaluate strategy performance against historical data
- Performance Metrics: Track key metrics like win rate, profit/loss, etc.
- Web Interface: Visualize data, strategies, and backtest results
- Backend: Django, Python
- Data Processing: Pandas, NumPy
- Charting: Matplotlib
- API Integration: CCXT (CryptoCurrency eXchange Trading Library)
- Database: SQLite (default), extensible to PostgreSQL
# Clone the repository
git clone https://github.com/github_username/crypto-trader.git
cd crypto-trader
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install required packages
pip install -r requirements.txt
# Run migrations
python manage.py migrate
# Create a superuser
python manage.py createsuperuser
# Start the development server
python manage.py runserverCurrently, data fetching is limited to command-line operations:
# Fetch 1000 hourly candles for BTC/USDT
python manage.py fetch_crypto_data BTC/USDT --timeframe 1h --limit 1000Limitations:
- Only one fetching option is available using the
limitparameter - Historical data fetching by date range will be added in future versions
- All data-fetching operations will eventually be available through the GUI
# Calculate SMA and RSI for BTCUSDT
python manage.py calculate_indicators BTCUSDT --timeframe 1h# Run a backtest for a specific date range
python manage.py run_backtest BTCUSDT --timeframe 1h --start-date 2025-04-01 --end-date 2025-04-25The app currently has one strategy implemented: SMA Crossover, which buys when a short-term SMA crosses above a long-term SMA and sells when it crosses below.
The application is designed to be scalable:
- New indicators can be created under the
analysisapp - New strategies can be added under the
strategiesapp using the base strategy class for consistency - Each backtest is initiated via a dedicated script under the
backtestingapp, with each run having a unique name for traceability
While buy/sell signals are defined within each strategy, the exit conditions are handled in backtesting/backtest_engine.py. This exit logic can be extended to accommodate various exit conditions for different strategies.
- Only spot market buy positions are currently implemented
- Paper trading mode (simulated trading with no real money)
- Futures trading support will be added
- Real-time trading implementation with user authentication
- Support for more advanced order types (limit, stop-loss, etc.)
- Trade Model: Currently unused, reserved for future real-time trading implementation with user logins
- Strategy Model: Includes an
is_activefield (currently unused) that will help manage which strategies are active during backtesting - BacktestRun Model: Stores the results of backtest runs for comparison and analysis
The following diagram illustrates the database schema and relationships between models in the Crypto Trader application:
When adding new strategies:
- Create a new strategy class in the
strategiesapp that inherits fromBaseStrategy - Implement the required
generate_signalsmethod - Update views in
backtesting/views.pyto import and integrate the new strategy
- Trading exit conditions can be modified in
backtesting/backtest_engine.py - Indicators can be added or modified in
analysis/indicators.py - New data sources can be integrated by extending the data service in
data/services.py
- Historical data fetching by date range
- GUI for data fetching operations
- Additional technical indicators (MACD, Bollinger Bands, etc.)
- More trading strategies
- Strategy combination capabilities
- Position sizing options
- Real-time trading implementation
- User authentication and profiles
- Futures trading support
- Email/mobile notifications for trading signals
- Performance optimization for large datasets
- Strategy optimization using machine learning
- CCXT for cryptocurrency exchange API integration
- Django for the web framework
- Pandas for data analysis
- Matplotlib for data visualization
This project is for educational and portfolio purposes. Trading cryptocurrencies involves significant risk. Use this software at your own risk.
