← Back to main site

Research Note

Realtime Trading Engine Architecture Notes

This system started as a simple Coinbase WebSocket listener. It grew into a multi-layered real-time engine with quantitative signals, reinforcement learning agents, compliance logging, and human-in-the-loop controls. Below is the architecture breakdown that keeps it stable and explainable.

Data layer: high-frequency market streams

The engine ingests real-time data from:

Every message is normalized into a compact event structure that tracks timestamp, best bid and ask, microprice, order book deltas, spread, depth, and recent volatility. That stream powers both classical features and RL policies.

Alpha layer: hybrid modeling

The engine blends three categories of signals:

  1. Order-book pressure models
    • Imbalance between bid and ask ladder.
    • Pressure ratios on short windows.
    • Delta-volume anomalies around large players.
  2. Mean-reversion and trend models
    • EMA crossovers.
    • Breakout detectors.
    • Volatility buckets that throttle exposure.
  3. Reinforcement learning (SAC and PPO)
    • Reward shaping on PnL and drawdown.
    • Risk-penalized actions that respect exposure caps.
    • Entropy-controlled exploration to avoid overfitting.

Signals are aggregated into a probability of upward or downward movement. The hybrid stack lets me mix interpretable models with agents that can exploit microstructure patterns humans miss.

Execution layer: stability above all

The execution engine handles the position lifecycle, slippage control, kill switches, maximum loss thresholds, and FIFO tax lots. A queue-based architecture serializes actions so that rapid market updates never cause race conditions. Safety-first execution is the only way to let new alpha ideas ship without nuking capital.

Observability layer

Real-time metrics stream into Grafana: PnL curves, exposure, rolling volatility, Sharpe-like signal quality, RL agent entropy, and system latency. Observability transforms the engine from a black box into a teaching tool that new collaborators can understand.

Compliance layer (powered by Axiom OS)

Every trade generates:

That produces audit-grade trading logs that most student-built systems never attempt. It also means I can explain trades to mentors or regulators without digging through ad hoc notebooks.

Where it all leads

This engine is not about predicting markets perfectly. It is about building infrastructure that reacts quickly, fails safely, logs cleanly, and becomes a foundation for more advanced modeling. If CloudTune is my contribution to LLM infrastructure, this engine is my contribution to real-time systems.