Market Data Service: Simulating Real-Time Feeds
Building a synthetic quote generator to drive risk and matching logic
In trading systems, market data is the heartbeat. Orders by themselves are inert — they only gain meaning when validated against live quotes. Without market data, an OMS cannot enforce risk checks, cannot price trades, and cannot simulate realistic execution. To make my OMS project authentic, I built a dedicated Market Data Service that generates, streams, and exposes real-time quotes.
Why a Market Data Service?
In real-world capital markets:
- Exchanges and ECNs broadcast tens of thousands of updates per second.
- Risk engines rely on quotes to validate order prices and enforce regulatory bands.
- Matching engines need quotes to maintain reference prices and simulate execution.
- Analytics/reporting systems use quotes to calculate spreads, VWAP, and liquidity.
For my OMS, I needed a self-contained, configurable, and realistic feed that could:
- Provide continuous quotes for multiple symbols.
- Stress-test downstream services under both normal and bursty conditions.
- Be simple enough to run locally in Docker Compose, yet extensible for future scaling.
Design Goals
I defined four guiding principles:
- Configurable: Symbols, update rates, and burst patterns should be adjustable at runtime.
- Realistic: Quotes should mimic real-world behavior (bid/ask spread, volatility, last trade).
- Event-driven: All updates flow through Kafka (
quotestopic) for asynchronous consumption. - Debuggable: REST endpoints provide snapshots for quick inspection and validation.
Architecture
The Market Data Service is a Spring Boot microservice with three main components:
-
Quote Generator
- Implements a random walk algorithm with volatility factors.
- Ensures bid < ask, maintains a configurable spread.
- Supports both synthetic generation and CSV replay of historical ticks.
-
Publisher
- Serializes quotes into Avro.
- Publishes to Kafka
quotestopic. - Handles backpressure gracefully with producer configs (acks, retries, batching).
-
REST API
GET /api/quotes?symbol=AAPL→ returns the latest snapshot.- Useful for debugging, demos, and recruiter walkthroughs.
Kafka Integration
- Topic:
quotes - Schema:
{ "symbol": "AAPL", "bid": 174.20, "ask": 174.25, "last": 174.22, "timestamp": 1698326400000, "venue": "SIM-EX" }