A sophisticated, enterprise-grade cryptocurrency trading bot built with Python that provides real-time trade execution, position management, and automated trading strategies across multiple exchanges. The system features a microservices architecture with comprehensive monitoring, automated maintenance, and advanced trading capabilities.
- Binance Futures: Full futures trading with position management and risk controls
- KuCoin Futures: Advanced order types and automated position sizing
- Real-time Execution: WebSocket-based real-time price feeds and order execution
- Position Management: Automated entry, exit, stop-loss, and take-profit management
- Discord Signal Processing: Real-time trade signal processing from Discord channels
- AI-Powered Parsing: Intelligent signal parsing with structured trade data extraction
- Risk Management: Automated position sizing, stop-loss placement, and risk controls
- Multi-Strategy Support: Support for various trading strategies and signal types
- Real-time Monitoring: Continuous monitoring of active futures positions
- Automatic Closure: Immediate position closure when futures indicate closure
- Smart Matching: Advanced algorithm matching active futures to local trades
- Confidence Scoring: Multi-factor matching with confidence thresholds
- Microservices Architecture: Modular design with separate services for different functions
- Database Integration: Supabase-based data persistence with real-time subscriptions
- Docker Deployment: Containerized deployment with Docker Compose
- API Endpoints: RESTful APIs for external integrations and monitoring
- Comprehensive Logging: Structured logging with multiple log levels and formats
- Transaction History: Automated filling of historical transaction data
- PnL Backfilling: Automated profit/loss calculation and backfilling
- Price Synchronization: Real-time and historical price data synchronization
- Orphaned Orders Cleanup: Automated detection and cleanup of orphaned orders
- Balance Synchronization: Real-time balance tracking across exchanges
- Stop-Loss Auditing: Automated auditing of stop-loss orders for compliance
- Python 3.8 or higher (3.9+ recommended for optimal performance)
- Docker & Docker Compose (for containerized deployment)
- Git (for version control)
- Linux/macOS/Windows (Linux recommended for production)
- Discord Bot Token (for signal processing)
- Binance API Credentials:
- API Key with futures trading permissions
- API Secret
- Enable futures trading permissions
- KuCoin API Credentials:
- API Key with futures trading permissions
- API Secret
- API Passphrase
- Supabase Credentials:
- Project URL
- Service Role Key (for database operations)
- Redis (for enhanced caching and session management)
- PostgreSQL (alternative to Supabase for self-hosted deployments)
- Nginx (for reverse proxy and load balancing)
# Clone the repository
git clone <repository-url>
cd rubicon-trading-bot
# Copy environment configuration
cp example.env .env
# Edit .env with your credentials
nano .env # or your preferred editor
# Start all services
docker-compose up -d
# Check service status
docker-compose ps
# View logs
docker-compose logs -f discord-bot# Clone the repository
git clone <repository-url>
cd rubicon-trading-bot
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
.\venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp example.env .env
# Edit .env with your credentials
# Run the Discord bot service
python -m discord_bot.main# Build and deploy with Docker
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Or use the deployment script
./deploy.sh# Discord Bot Configuration
DISCORD_BOT_TOKEN=your_discord_bot_token
DISCORD_GUILD_ID=your_guild_id
# Binance Exchange
BINANCE_API_KEY=your_binance_api_key
BINANCE_API_SECRET=your_binance_api_secret
BINANCE_TESTNET=false
# KuCoin Exchange
KUCOIN_API_KEY=your_kucoin_api_key
KUCOIN_API_SECRET=your_kucoin_api_secret
KUCOIN_API_PASSPHRASE=your_kucoin_passphrase
# Database (Supabase)
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
# Trading Configuration
TARGET_TRADERS=@Trader1,@Trader2
RISK_PERCENTAGE=2.0
MAX_POSITION_SIZE=1000.0
# Logging
LOG_LEVEL=INFO
LOG_FILE_PATH=/var/log/rubicon
# Scheduler Intervals (seconds)
DAILY_SYNC_INTERVAL=86400
ACTIVE_FUTURES_SYNC_INTERVAL=300- Create API key at Binance API Management
- Enable "Enable Futures" permission
- Set IP restrictions if needed for security
- Create API key at KuCoin API Management
- Enable "Futures Trading" permission
- Generate and securely store API passphrase
- Create Discord application at Discord Developer Portal
- Generate bot token and copy to
.env - Invite bot to your server with appropriate permissions
The Rubicon Trading Bot follows a modular microservices design:
rubicon-trading-bot/
├── 📁 src/ # Core business logic
│ ├── 📁 bot/ # Trading engines
│ │ ├── 📁 binance_trading_engine.py
│ │ ├── 📁 kucoin_trading_engine.py
│ │ └── 📁 trading_engine.py
│ ├── 📁 core/ # Core services
│ │ ├── 📁 position_manager.py
│ │ └── 📁 risk_manager.py
│ ├── 📁 database/ # Data layer
│ │ ├── 📁 core/
│ │ ├── 📁 models/
│ │ ├── 📁 repositories/
│ │ └── 📁 migrations/
│ ├── 📁 exchange/ # Exchange integrations
│ │ ├── 📁 binance/
│ │ └── 📁 kucoin/
│ ├── 📁 services/ # Business services
│ │ ├── 📁 active_futures_sync_service.py
│ │ ├── 📁 position_close_service.py
│ │ └── 📁 trade_service.py
│ └── 📁 utils/ # Utilities
│
├── 📁 discord_bot/ # Discord integration service
│ ├── 📁 endpoints/ # API endpoints
│ ├── 📁 utils/ # Discord utilities
│ └── 📁 main.py
│
├── 📁 scripts/ # Maintenance scripts
│ ├── 📁 maintenance/ # Automated maintenance
│ ├── 📁 account_management/ # Account management
│ └── 📁 testing/ # Test utilities
│
├── 📁 tests/ # Test suite
├── 📁 config/ # Configuration files
├── 📁 logs/ # Log files
├── 📁 docs/ # Documentation
├── 📁 docker-compose.yml # Docker orchestration
├── 📁 Dockerfile # Container definition
├── 📁 requirements.txt # Python dependencies
├── 📁 nginx.conf # Reverse proxy config
└── 📁 main.py # Main entry point
- Discord Bot Service: Handles real-time signal processing and API endpoints
- Active Futures Sync: Monitors and synchronizes futures positions
- Trading Engines: Execute trades across multiple exchanges
- Database Layer: Manages data persistence and real-time subscriptions
- Maintenance Services: Automated cleanup and synchronization tasks
- Signal Reception: Discord signals received via webhooks
- Signal Processing: AI-powered parsing and validation
- Trade Execution: Position opening via exchange APIs
- Position Monitoring: Real-time tracking and risk management
- Active Futures Sync: Continuous monitoring of futures positions
- Automated Closure: Immediate closure when futures indicate exit
GET /- Service health checkGET /health- Detailed health statusGET /websocket/status- WebSocket connection statusPOST /api/v1/discord/signal- Receive trade signalsPOST /api/v1/discord/signal/update- Update existing tradesPOST /scheduler/*- Manual maintenance triggers
POST /scheduler/test-transaction-history- Manual transaction syncPOST /scheduler/test-daily-sync- Manual daily synchronizationPOST /scheduler/test-orphaned-orders-cleanup- Manual cleanupGET /scheduler/status- Scheduler status and intervals
- Unit Tests: Individual component testing
- Integration Tests: Service interaction testing
- End-to-End Tests: Complete workflow testing
- Performance Tests: Load and stress testing
# Run all tests
pytest tests/
# Run specific test category
pytest tests/test_active_futures_sync.py
# Run with coverage
pytest --cov=src tests/
# Run integration tests
pytest tests/test_integration.py -v# Development environment
docker-compose up -d
# Production environment
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Scale services
docker-compose up -d --scale discord-bot=2- Load Balancing: Nginx reverse proxy configuration
- Monitoring: Health checks and metrics collection
- Security: API key rotation and access controls
- Backup: Database backup strategies
- Logging: Centralized log aggregation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with proper tests
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Type Hints: All functions should have proper type annotations
- Documentation: Comprehensive docstrings for all public methods
- Testing: Test coverage > 90% for new features
- Error Handling: Proper exception handling with logging
- Code Style: Follow PEP 8 and use black for formatting
# Install development dependencies
pip install -r requirements-dev.txt
# Set up pre-commit hooks
pre-commit install
# Run linting
flake8 src/ discord_bot/
# Format code
black src/ discord_bot/
# Sort imports
isort src/ discord_bot/- Active Futures Sync: Every 5 minutes
- Daily Sync: Every 24 hours
- Transaction History: Every 1 hour
- PnL Backfill: Every 1 hour
- Stop-Loss Audit: Every 30 minutes
- Orphaned Orders Cleanup: Every 2 hours
- Balance Sync: Every 5 minutes
- Service Status: Real-time health checks
- Database Connectivity: Connection pool monitoring
- Exchange API Status: API rate limit tracking
- Performance Metrics: Response times and throughput
- Error Rates: Exception tracking and alerting
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Documentation: Check the
/docsfolder - Issues: Use GitHub Issues for bug reports
- Discussions: Use GitHub Discussions for questions
- Logs: Check application logs for troubleshooting