24/7 Session-Driven Execution Engine
A production trading bot with session-aware strategy rotation, comprehensive risk management, and multi-broker support. Designed for continuous operation across Tokyo, London, and New York trading sessions.
UnifiedTradingBot
├── bot_core.py # Main 24/7 execution engine
├── api_server.py # FastAPI REST + WebSocket server
├── mt5_connector.py # MetaTrader 5 connection + reconnection
├── market_data.py # OHLCV data engine
├── risk_manager.py # Risk calculations + limits
├── session_router.py # Tokyo/London/NY session detection (SAST)
├── strategies/
│ ├── base.py # BaseStrategy abstract class
│ ├── tokyo_sweep.py # Asian session sweep strategy
│ ├── london_open_fade.py # London open fade strategy
│ ├── london_close_reversal.py # London close reversal strategy
│ └── strategy_plugin.py # Plugin discovery system
├── risk/
│ ├── margin_guard.py # Margin level monitoring
│ ├── portfolio_heat.py # Portfolio heat calculation
│ └── correlation_matrix.py # Position correlation analysis
├── execution/
│ ├── execution_quality.py # Slippage + fill rate tracking
│ ├── partial_close.py # Partial close system
│ └── strategy_rotation.py # Auto strategy rotation
├── intelligence/
│ ├── ml_validator.py # ML signal validation
│ ├── volatility_regime.py # Volatility regime detection
│ └── confluence_filters.py # POI (Point of Interest) tracker
├── integration/
│ ├── news_filter.py # High-impact news filtering
│ ├── notifier.py # Telegram + email alerts
│ ├── sentiment_connector.py # News sentiment analysis
│ └── heartbeat_server.py # Health monitoring endpoint
├── persistence/
│ ├── state_persistence.py # Crash recovery + state save
│ └── trade_journal.py # Trade recording + reporting
├── compliance/
│ └── compliance_reporter.py # Tax + regulatory reporting
├── marketplace/
│ └── strategy_marketplace.py # Strategy marketplace system
└── signal_bus.py # Inter-module signal distribution
Automatically detects and adapts to Tokyo, London, and New York trading sessions using SAST timezone handling:
class SessionRouter:
def get_current_session(self) -> Session:
sast_now = datetime.now(timezone.utc).astimezone(SAST)
# Returns: TOKYO, LONDON, NY, or OVERLAPStrategies are discoverable at runtime via plugin architecture:
# Auto-discover all strategy classes
strategies = discover_strategy_classes()
for strategy_cls in strategies:
strategy = strategy_cls(config)
# Register with rotation system| Module | Purpose |
|---|---|
margin_guard.py |
Monitors margin level, prevents margin calls |
portfolio_heat.py |
Calculates total portfolio exposure |
correlation_matrix.py |
Tracks position correlations |
partial_close.py |
Tiered partial close system |
execution_quality.py |
Tracks slippage, fill rates, rejections |
Machine learning layer validates signals before execution:
- Feature extraction from market data
- Historical win rate analysis
- Confidence scoring
- Saves bot state every 30 seconds to
bot_state.json - On restart, recovers positions and partial close tiers
- Merges persisted metadata with broker truth
- Python 3.12+
- MetaTrader 5 terminal
- MT5 algo trading enabled
git clone https://github.com/JayV42069/UnifiedTradingBot.git
cd UnifiedTradingBot
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txtcp config.example.json config.json
# Edit config.json with your MT5 credentials and strategy settingspython -m pytest unified_engine_test.py -v# Normal mode
python bot_core.py --no-info
# Verbose mode
python bot_core.py --verboseuvicorn api_server:app --host 0.0.0.0 --port 8081| Strategy | Session | Logic |
|---|---|---|
| Tokyo Sweep | Tokyo (00:00-09:00 SAST) | Detects Asian liquidity sweeps |
| London Open Fade | London (09:00-12:00 SAST) | Fades London opening volatility |
| London Close Reversal | London Close (16:00-18:00 SAST) | Identifies end-of-day reversals |
| Post-News Breakout | Any (news-driven) | Post-news breakout on consolidation |
| Regime Adaptive | Any | BTC regime-adaptive with CVD/absorption |
Python 3.12 · MetaTrader5 · pandas · NumPy · FastAPI · Supabase · pytest · ruff · mypy
MIT — see LICENSE for details.