Case Study
Kael Trading Intelligence
An autonomous trading bot and intelligence dashboard with live WebSocket market data, ICT strategy regime detection, a 5-phase safety gate, and 1,300+ automated tests.
What It Is
Kael is a production trading intelligence platform. It connects to TopstepX via SignalR WebSocket, scans 13 instruments in real-time, runs an ICT strategy engine for regime detection and signal generation, enforces a 5-phase safety gate before any live execution, and displays everything on a Flask dashboard with live candlestick charts.
It's not a strategy tester. It runs against real broker infrastructure with real account routing, verified sub-account connections, and a live position tracking system that shows P&L, stop-loss, and take-profit overlays on each position card.
The Engineering
SignalR WebSocket Integration
Live market data streams via TopstepX SignalR WebSocket. Thread-safe caches hold the latest bar data per instrument. Three executor state methods use SignalR-first with REST fallback, so stale data never reaches the strategy engine.
5-Phase Safety Gate
Before any live trade executes: (1) broker connection verified, (2) account balance validated against risk limits, (3) daily loss limit checked, (4) regime conditions confirmed, (5) position size calculated and confirmed within $120 stop-loss. None of these checks can be skipped — the architecture won't allow it.
Source Truth Dashboard
The dashboard Source Truth panel shows exact state: broker mode (Paper Sim / Runtime Sim / Broker-Verified), viewing account label (name + ID, not generic "Default"), session status, and scanner health. Every label is sourced from live DB state, not inferred from config.
1,300+ Automated Tests
The trading brain has comprehensive test coverage: ICT signal detection, regime classification, risk calculation, data fetcher routing across 3 brokers, integration suite for the full decision pipeline, and DOM tests for the dashboard. 58 passing on the platform, 1,300+ on the bot.
Hard Problems Solved
Dashboard lying about broker connection
The Source Truth panel was accepting a paper trading heartbeat as proof of live broker connection. The dashboard showed live-mode labels when the system was in paper mode. Fixed by requiring broker-verified account routing and adding explicit state labels to the panel.
SQL NULL vs TRUE migration bug
Sub-accounts were consistently returning None even after creation. Root cause: the migration added an is_active column but didn't backfill existing rows. NULL doesn't match TRUE in a WHERE clause. Fix: one-line data repair via Railway SSH — no code change needed.
CSP headers blocking Chrome video cache
Chrome threw ERR_CACHE_OPERATION_NOT_SUPPORTED on dashboard video assets. CSP headers on the video route were preventing browser caching. Fixed by removing the conflicting directive and setting explicit cache-control headers.
TopstepX login email vs display handle
Broker auth was failing consistently. TOPSTEP_USERNAME was set to the display handle (josephrich90) instead of the login email. TopstepX requires the email address. One env var update, verified with a live connection test.
Current State
Live at kael.polarisdgtl.com. Scanner active, 13 instruments, paper mode running. Phase 5B (account routing) deployed and verified. Full test suite at 1,300+ passing.