Trading Technology
Building Trading Alerts With Real-Time Market Data
A price alert sounds trivial until you need it to fire in real time, exactly once, without lying to you.
"Alert me when SPY crosses 560." Easy, right? It is — until you want it to be real-time, fire exactly once, survive a reconnect, and never trigger on a garbage tick. Then it's a distributed-systems problem.
The naive version (and why it breaks)
every 60s: fetch price; if price > threshold: send alert
Polling misses fast moves, double-fires across restarts, and hammers your data vendor. It's fine for a toy and dangerous for money.
The real design
How it works
- STREAMING FEED
- PER-SYMBOL STATE
- CROSS DETECTION
- DEDUPE / DEBOUNCE
- DELIVER (once)
The core insight is edge detection: you don't alert when price is above the threshold, you alert when it crosses — a transition from below to above. That requires remembering the previous state per symbol.
Exactly-once is the hard requirement
Store a 'fired' flag with the alert and reset it only on the reverse cross. On reconnect, rehydrate state before you start evaluating, or you'll re-fire every alert at once.
Delivery matters too
A correct alert that arrives 30 seconds late is a wrong alert. Push channels, backpressure, and idempotent delivery are as important as the detection logic.
Key takeaway
An alert engine is edge detection plus exactly-once delivery over an unreliable stream. Get state, dedupe and reconnect right and the 'feature' becomes genuinely reliable infrastructure.