TradeWatch
In progressPhase 10 of 12 completeMarket Intelligence & Paper-Trading Platform
The diagram scrolls sideways.
Provider
Consumer groups: stop one, keep sending, then restart it
0 trades, 0 stored, 0 bars, 0 flagged, 0 alerts.
- price
- 102.19
- expected
- 102.29
- σ
- 1.21
- z
- -0.08
t+0065 Flagged: 5.3 robust standard deviations below the expected move.
equity: strategy vs ‐ ‐ buy & hold
- strategy
- +9.0%
- buy & hold
- -7.1%
- max drawdown
- -13.0%
- trades
- 7
- win rate
- 33%
- in market
- 43%
7 trades, +9.0% against -7.1% for buying and holding.
TradeWatch watches live market data and notices when a stock starts behaving unusually compared to its own recent history. Around that sits a full paper-trading platform: write a trading strategy, backtest it against stored history, then run it against the live feed with simulated money, all from one React dashboard.
Under the hood, market data flows into Kafka and fans out to independent processes that each read the same stream at their own pace. One stores every trade, one builds one minute candles and rolls them up to five minute, hourly and daily ones, one pushes live prices to the browser, one runs the paper-trading strategies, and one scores every closed candle for unusual activity and hands anything it flags to an alert service. Kafka only promises that a message arrives at least once, so every one of those writes is idempotent: receiving the same trade twice never changes the result.
Most of the effort went into making that plumbing trustworthy before building on top of it, which is why the project was built in phases with the pipeline, storage and CI first and strategies and detection after. Ten of the twelve phases are done; what remains is end-to-end failure-recovery testing and cloud deployment. The anomaly detector only ever flags activity that is unusual for a specific stock compared to its own history. It does not try to catch fraud or market manipulation, and the project is careful never to claim that it does.
Implementation detail12
- Real-time pipeline: a market data provider feeds Kafka, which fans out to six independent consumer groups: raw trade storage, candle aggregation (1-minute bars with 5m/1h/1d rollups), live broadcast through Redis to WebSockets, paper trading, anomaly detection, and alert dispatch.
- At-least-once delivery with idempotent writes; offsets are only committed after data is durably stored.
- Strategies are configuration run by one shared execution core, so a backtest and a live paper-trading run use the same decision code.
- Anomaly detection: a rolling median and median-absolute-deviation z-score over each symbol's own recent candles, across return, volatility, volume and trade count. An Isolation Forest model can replace it only if offline evaluation shows it does at least as well. Flags unusual activity, explicitly not fraud or manipulation.
- Simulates trading only: no brokerage connectivity, no real money moves.
- Accounts with JWT authentication; every strategy, backtest and portfolio is scoped to its owner.
- Prometheus metrics on every process and a committed Grafana dashboard.
- Benchmarked on one laptop with everything running locally: 750 trade events per second sustained into PostgreSQL, and a median of 37 ms from the data provider to the browser. Single-machine figures, not production ones.
- Layered architecture (domain / application / infrastructure) enforced by import-linter in CI.
- Typed settings that fail startup with every missing config variable named at once.
- Six independent CI jobs: lint and type-check, unit and API tests, integration tests against real PostgreSQL, Redis and Kafka, a startup check, the frontend, and a Docker build.
- No performance number appears anywhere in the project unless a benchmark produced it.
- Python
- FastAPI
- Kafka
- PostgreSQL
- Redis
- Alembic
- scikit-learn
- React
- TypeScript
- Vite
- Recharts
- WebSockets
- Prometheus
- Grafana
- Docker
- GitHub Actions