Skip to content

Strategizm/lean-trading-bot-stack

 
 

Repository files navigation

🚀 LEAN Trading Bot Stack

Professional Algorithmic Trading Platform powered by QuantConnect LEAN Engine with integrated Smart Money Trading (SMT) concepts, AI/ML models, and comprehensive web dashboard.

LEAN Trading Bot Stack Production Ready Docker Security

🎯 Key Features

  • 🔧 Official QuantConnect LEAN Engine - Local execution, no API dependency
  • 🤖 AI/ML Integration - Import/Export models (ONNX, TensorFlow, PyTorch, Scikit-learn)
  • 📊 Smart Money Trading (SMT) - Order Blocks, Fair Value Gaps, Break of Structure
  • 🌐 Web Dashboard - Complete broker management, portfolio analytics
  • 🔗 Multi-Broker Support - Binance, Interactive Brokers, Paper Trading
  • 🎛️ Advanced Risk Management - Position sizing, drawdown protection
  • 📈 Real-time Monitoring - Live trading dashboard with P&L tracking
  • 🔒 Security First - Encrypted credentials, rate limiting, SSL/TLS support
  • ⚡ High Performance - Optimized Docker containers, caching, load balancing
  • 🔄 CI/CD Ready - Automated testing, security scanning, deployment

🏗️ Architecture

graph TB
    A[Nginx Proxy] --> B[React Frontend]
    A --> C[Flask Backend]
    A --> D[Jupyter Research]
    A --> E[SMT Integration]
    
    C --> F[LEAN Engine]
    C --> G[PostgreSQL]
    C --> H[Redis]
    
    E --> I[ML Models]
    E --> J[SMT Indicators]
    
    F --> K[Algorithms]
    F --> L[Data]
    F --> M[Results]
    
    style A fill:#3b82f6
    style F fill:#10b981
    style G fill:#8b5cf6
    style H fill:#ef4444
Loading

🔧 Tech Stack

Component Technology Purpose
LEAN Engine QuantConnect LEAN Core trading engine
Frontend React 18, TailwindCSS Interactive dashboard
Backend Flask, Python 3.11 REST API server
Database PostgreSQL 15 Data persistence
Cache Redis 7 Real-time data cache
ML/AI TensorFlow, PyTorch, ONNX Model management
Proxy Nginx Load balancing, SSL
Research Jupyter Lab Algorithm development
Containers Docker, Docker Compose Orchestration

⚡ Quick Start

1. Prerequisites

  • Docker and Docker Compose installed
  • Git for repository cloning
  • 4GB+ RAM recommended
  • 10GB+ disk space for data and models

2. Installation

# Clone repository
git clone https://github.com/szarastrefa/lean-trading-bot-stack.git
cd lean-trading-bot-stack

# Make installer executable
chmod +x install.sh

# Run automated installation
./install.sh

3. Access Dashboard

After installation completes:

  • 🌐 Dashboard: Your tunnel URL (displayed after install)
  • 🔬 Research: Your_URL/research (Jupyter Lab)
  • 🔗 API: Your_URL/api
  • 📊 SMT API: Your_URL/smt

4. Default Credentials

  • 👤 Username: admin
  • 🔑 Password: (randomly generated during install - displayed in terminal)
  • 💾 Backup: Credentials saved to ~/.lean-bot-credentials-TIMESTAMP

📚 Documentation

🚀 Quick Commands

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Restart single service
docker-compose restart webui-backend

# Update images
docker-compose pull && docker-compose up -d

🔧 Development Setup

# Development mode with hot reload
docker-compose -f docker-compose.yml up -d

# Build specific service
docker-compose build webui-backend

# Run tests
docker-compose run --rm webui-backend python -m pytest

📊 Adding Custom Algorithms

  1. Place Python files in algorithms/ directory
  2. Follow LEAN algorithm structure:
from AlgorithmImports import *

class MyStrategy(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetCash(100000)
        self.AddEquity("SPY", Resolution.Hour)
        
    def OnData(self, data):
        if not self.Portfolio.Invested:
            self.SetHoldings("SPY", 1)

🤖 ML Model Integration

  1. Upload models via SMT API:
curl -X POST "http://localhost:8000/models/upload" \
  -F "file=@model.pkl" \
  -F 'metadata={"type":"classification","accuracy":0.85}'
  1. Use in algorithms:
# In your LEAN algorithm
model_predictions = self.smt_api.predict("my_model", features)

🛠️ Configuration

🔒 Environment Variables

Key configuration options in .env:

# Core Settings
ENVIRONMENT=production
LEAN_MODE=BACKTESTING

# Security
ADMIN_PASSWORD=your_secure_password
FLASK_SECRET_KEY=your_secret_key

# Database
POSTGRES_PASSWORD=secure_db_password
REDIS_PASSWORD=secure_cache_password

# ML/AI
PERPLEXITY_API_KEY=your_ai_api_key
SMT_ENABLED=true

# Tunneling
TUNNEL_TYPE=localtunnel
TUNNEL_SUBDOMAIN=your-custom-name

🔄 Broker Configuration

# Interactive Brokers
IB_ACCOUNT=your_ib_account
IB_USERNAME=your_username
IB_PASSWORD=your_password
IB_TRADING_MODE=paper

# Binance
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_secret
BINANCE_TESTNET=true

🔧 Advanced Usage

📈 Smart Money Trading Features

  • Order Blocks: Institutional demand/supply zones
  • Fair Value Gaps: Price imbalances for entries
  • Break of Structure: Trend change identification
  • Liquidity Zones: High-volume reversal areas

🧠 AI/ML Capabilities

  • Model Formats: ONNX, TensorFlow, PyTorch, Scikit-learn
  • Real-time Predictions: Live trading integration
  • Model Management: Upload, versioning, metadata
  • Performance Tracking: Accuracy, confidence scores

📊 Dashboard Features

  • Portfolio Analytics: Real-time P&L, drawdown
  • Algorithm Management: Start, stop, configure strategies
  • Broker Integration: Multi-broker account management
  • Risk Controls: Position sizing, stop losses
  • Performance Reports: Backtests, live results

🔒 Security Features

  • 🔐 Encrypted Credentials: All secrets encrypted at rest
  • 🛡️ Rate Limiting: API abuse prevention
  • 🔍 Security Scanning: Automated vulnerability checks
  • 🚦 Access Control: Role-based permissions
  • 📝 Audit Logging: Complete action history
  • 🔒 SSL/TLS: End-to-end encryption

🚀 Production Deployment

☁️ Cloud Setup

  1. AWS/GCP/Azure: Use provided Terraform scripts
  2. DigitalOcean: One-click deployment available
  3. VPS: Manual Docker installation

🔄 CI/CD Pipeline

  • ✅ Automated Testing: Unit, integration, E2E tests
  • 🔍 Security Scanning: Vulnerability assessments
  • 📦 Docker Builds: Multi-arch container images
  • 🚀 Auto Deployment: Zero-downtime updates

📈 Performance

  • ⚡ Response Time: < 100ms API responses
  • 📊 Throughput: 1000+ requests/second
  • 💾 Memory Usage: < 2GB typical operation
  • 🔄 Uptime: 99.9% availability target

🆘 Troubleshooting

Common Issues:

Port Conflicts:

# Check port usage
sudo netstat -tulpn | grep :5000

# Stop conflicting services
sudo systemctl stop apache2

Docker Issues:

# Reset Docker
docker system prune -a
docker volume prune

# Restart services
docker-compose down && docker-compose up -d

Permission Errors:

# Fix permissions
sudo chown -R $USER:$USER .
chmod +x install.sh

🤝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push branch: git push origin feature/amazing-feature
  5. Open Pull Request

📄 License

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

🙏 Acknowledgments

📞 Support


⭐ If this project helped you, please give it a star!

🚀 Happy Trading! 📈

About

Kompletny trading bot oparty na QuantConnect LEAN z Web UI, integracją ML/AI, obsługą wielu brokerów i instalatorem tunelowania

Resources

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages