A comprehensive trading system that integrates Databento market data, Qlib analysis, machine learning models, and advanced backtesting capabilities through a modern web interface.
- π Data Management: Fetch and manage market data from Databento
- π Advanced Analysis: Qlib-powered analysis and ML predictions
- π Backtesting Engine: Comprehensive backtesting with performance metrics
- π― Trading Strategies: Momentum and mean reversion strategies
- π± Modern UI: Intuitive Gradio-based web interface
- βοΈ Configurable: YAML-based configuration system
- π§ͺ Testable: Comprehensive test suite
- π Multiple Startup Options: Choose the best interface for your needs
qlibtrader/
βββ π working_trading_app.py # Main working application (RECOMMENDED)
βββ π§ start_simple_trading.py # Simplified interface launcher
βββ π§ͺ minimal_working_app.py # Basic test interface
βββ π diagnose_gradio.py # Diagnostic tool
βββ π οΈ setup.sh # Setup script
βββ ui/ # Web interfaces
β βββ simple_gradio_app.py # Simplified Gradio app
β βββ __init__.py
βββ utils/ # Utilities
β βββ config.py # Configuration management
β βββ logger.py # Logging utilities
β βββ validators.py # Data validation
β βββ __init__.py
βββ configs/ # Configuration files
βββ data/ # Data storage
βββ logs/ # Log files
- Python 3.8+
- Databento API key
-
Clone the repository
git clone <repository-url> cd qlibtrader
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp env_template .env # Edit .env and add your DATABENTO_API_KEY -
Run the application
π Recommended: Working Trading System (Stable)
python working_trading_app.py
- Access at:
http://127.0.0.1:7860 - Full functionality with stable interface
π§ Alternative: Simplified Trading System
python start_simple_trading.py
- Access at:
http://0.0.0.0:7860 - Simplified interface for development
π§ͺ Testing: Minimal Interface
python minimal_working_app.py
- Access at:
http://127.0.0.1:7860 - Basic functionality test
π Production: FastAPI Server
python start_simple_trading.py --mode server
- Access at:
http://0.0.0.0:8000 - Production-ready FastAPI server
- Access at:
-
Open your browser
- Working/Simplified:
http://127.0.0.1:7860 - Production:
http://0.0.0.0:8000
- Working/Simplified:
- Enter symbols (e.g., AAPL, MSFT, GOOGL)
- Set date range and data schema
- Fetch and cache market data
- Choose analysis type (Qlib, ML, or Strategy)
- Configure parameters
- Generate trading signals
- Set backtest parameters (capital, commission, etc.)
- Run backtests on historical data
- Analyze performance metrics
- View comprehensive reports
- Export results in various formats
- Monitor performance metrics
The system uses YAML configuration files:
configs/data_config.yaml- Data source settingsconfigs/strategy_config.yaml- Strategy parametersconfigs/model_config.yaml- ML model settings
Create a .env file with:
DATABENTO_API_KEY=your_api_key_here
LOG_LEVEL=INFORun the test suite:
pytest tests/Run specific test files:
pytest tests/test_data_fetcher.py
pytest tests/test_analyzer.py
pytest tests/test_backtester.pyRun Gradio diagnostic tool:
python diagnose_gradio.py1. Gradio Interface Disconnects
- Use the working trading app:
python working_trading_app.py - Check Gradio version:
pip show gradio - Run diagnostics:
python diagnose_gradio.py
2. Missing Dependencies
pip install -r requirements.txt
# Or install specific packages:
pip install plotly scikit-learn pyyaml gradio3. Port Already in Use
# Use a different port:
python working_trading_app.py --port 8080
# Or kill existing processes:
pkill -f "python.*trading"4. API Key Issues
- Create
.envfile:cp env_template .env - Add your Databento API key to
.env - Restart the application
| Script | Purpose | Stability | Features |
|---|---|---|---|
working_trading_app.py |
Recommended | β High | Full functionality |
start_simple_trading.py |
Development | β High | Simplified UI |
minimal_working_app.py |
Testing | β High | Basic features |
- Identifies trending price movements
- Uses RSI, MACD, and volume confirmation
- Configurable lookback periods and thresholds
- Detects overbought/oversold conditions
- Uses Bollinger Bands and Z-score
- Volume confirmation for signal validation
Build and run with Docker:
# Build the image
docker build -t trading-system .
# Run with environment variables
docker run -p 8000:8000 \
-e DATABENTO_API_KEY=your_key_here \
trading-systemUsing Docker Compose:
# Create .env file with your API key
echo "DATABENTO_API_KEY=your_key_here" > .env
# Start the application
docker-compose up -d
# With reverse proxy
docker-compose --profile proxy up -dUsing Gunicorn with Uvicorn workers:
pip install gunicorn
gunicorn server:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000Environment Variables for Production:
export HOST=0.0.0.0
export PORT=8000
export WORKERS=4
export LOG_LEVEL=warning
export ACCESS_LOG=trueDevelopment Mode:
python start_server.py --reload --log-level debugProduction Mode:
python start_server.py --production --workers 4- Create a new strategy class inheriting from
BaseStrategy - Implement
generate_signals()method - Add strategy to the UI configuration
- Extend the
QlibAnalyzerorMLAnalyzerclasses - Implement analysis methods
- Update the UI to include new options
- Modify panel components in
ui/components/ - Add new tabs or features to
ui/gradio_app.py - Update styling in the CSS sections
The backtesting engine calculates:
- Total Return and Annualized Return
- Sharpe Ratio and Sortino Ratio
- Maximum Drawdown
- Win Rate and Trade Statistics
- Risk-adjusted metrics
- API keys stored in environment variables
- Input validation for all user inputs
- Secure data caching and storage
- Error handling and logging
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Databento for market data
- Qlib for quantitative analysis
- Gradio for the web interface
- Backtrader for backtesting
For questions and support:
- Create an issue on GitHub
- Check the documentation
- Review the test examples
- Initial release
- Basic data fetching and analysis
- Momentum and mean reversion strategies
- Gradio web interface
- Comprehensive backtesting engine