Architecture
Before & After
Before
Manual chart analysis prone to emotional decision-making, no systematic approach to entry/exit points, and delayed reaction to market structure shifts using Smart Money Concepts.
After
Automated trading system executing SMC-based strategies with real-time MT5 integration, automatic position sizing, circuit breaker protection, and instant Telegram notifications for all trades.
Results
Technical Challenge
Real-time Market Data Synchronization
The Problem
MT5's Python API has unpredictable latency spikes under heavy market conditions. A trade signal could arrive during a latency spike, causing the system to either miss the trade entirely or place it at an unfavorable price.
The Solution
Implemented a circuit breaker pattern with adaptive thresholds. The breaker monitors response times and failure rates in real-time. When latency exceeds 2x the rolling average, the breaker opens and queues incoming signals. Once MT5 recovers (detected by successful ping responses), the breaker half-opens and gradually reintroduces live trading.
This reduced missed trades by 94% during volatility events while maintaining sub-50ms execution when markets are stable.
Tech Decisions
FastAPI over Flask
FastAPI's native async support was critical for handling multiple concurrent WebSocket connections to MT5. While Flask could handle synchronous requests, FastAPI's automatic async/await handling and built-in WebSocket support reduced boilerplate significantly. The automatic OpenAPI documentation also helped when debugging trade execution flows.
PostgreSQL for Trade Persistence
Every trade needs ACID compliance. PostgreSQL's JSONB support also let me store complex trade metadata (execution prices, slippage, signal strength) without schema changes. The TimescaleDB extension provides historical performance analytics, essential for backtesting strategy improvements.
WebSocket for Real-time Updates
Price feeds require sub-second latency. Polling REST endpoints would create unnecessary load and miss price movements. WebSocket connections to MT5's DLL bridge provide direct price updates, with the backend normalizing and broadcasting to connected dashboard clients.