-
Notifications
You must be signed in to change notification settings - Fork 12
Business Logic Market Data and Pricing
This document details market data aggregation, Level-1 / Level-2 order book depth structure, Price-Time priority matching, and micro-price / VWAP calculation formulas in Emporia Trading Platform's market-data-service.
market-data-service aggregates prices from multiple venue sources (FIX protocol simulators, Alpaca IEX WebSocket, external price feeds) to produce composite order books.
flowchart TD
FixFeed["FIX Protocol Simulator"] -->|FIX Incremental Refresh| Aggregator["QuoteAggregator Engine"]
AlpacaFeed["Alpaca IEX WebSocket"] -->|JSON Depth Snapshots| Aggregator
SimFeed["Synthetic Quote Generator"] -->|Tick Stream| Aggregator
Aggregator -->|Consolidate Depth| L1Book["Level-1 Top of Book (BBO)"]
Aggregator -->|Consolidate Depth| L2Book["Level-2 Depth of Book (5-10 Levels)"]
L1Book -->|HTTP SSE Stream| WebUI["React 19 Trading Dashboard"]
L2Book -->|gRPC Proto Stream| Services["Execution & Portfolio Services"]
An order book organizes active resting limit orders into two sorted sides:
-
Bids (Buy Orders): Sorted in descending order by price (
$\max P_{\text{bid}}$ first). Ties sorted by earliest timestamp (FIFO). -
Asks (Sell Orders): Sorted in ascending order by price (
$\min P_{\text{ask}}$ first). Ties sorted by earliest timestamp (FIFO).
| Bid Quantity | Bid Price | Ask Price | Ask Quantity |
|---|---|---|---|
| โ | โ | $150.05 (Ask 3) | 500 |
| โ | โ | $150.02 (Ask 2) | 300 |
| โ | โ | $150.00 (Best Ask) | 100 |
| $149.98 (Best Bid) | 250 | โ | โ |
| $149.95 (Bid 2) | 400 | โ | โ |
| $149.90 (Bid 3) | 1,000 | โ | โ |
-
Best Bid (
$P_{\text{bid}}$ ): Highest resting buy price. -
Best Ask (
$P_{\text{ask}}$ ): Lowest resting sell price. -
Bid-Ask Spread:
$$\text{Spread} = P_{\text{ask}} - P_{\text{bid}}$$
The simple mid-point price between top-of-book bid and ask:
The micro-price adjusts the mid-price based on order book depth imbalance, providing a superior predictive indicator for short-term price direction:
Properties:
- If bid volume
$Q_{\text{bid}} \gg Q_{\text{ask}}$ (heavy buying pressure),$P_{\text{micro}}$ shifts upward toward$P_{\text{ask}}$ . - If ask volume
$Q_{\text{ask}} \gg Q_{\text{bid}}$ (heavy selling pressure),$P_{\text{micro}}$ shifts downward toward$P_{\text{bid}}$ .
-
Server-Sent Events (SSE): Pushes JSON tick objects (
{ symbol, bid, ask, last, volume, timestamp }) to web browsers over persistent HTTP connections (/api/market-data/stream). -
gRPC Streaming: Low-latency binary Protobuf streaming (
MarketDataService/SubscribeQuotes) for inter-service communication withexecution-serviceandportfolio-service.
- Trading Terminology Glossary
- Order Lifecycle & Validation
- Order Routing & SOR
- Market Data & Pricing
- Portfolio & Risk Management
- Architecture & Order Flow
- Static Data Service
- Market Data Service
- Order Command Service
- Order Management Service (OMS)
- Execution Service
- Portfolio Service
- Design Patterns
- Microservices Overview
- Exchange-Core Integration
- Testing & Verification
- Deployment & Operations
- Repository: emporia
- Tech Stack: Java 21 | Spring Boot 4.0.7 | React 19 | Kafka | gRPC
- Coverage: 91.95% JaCoCo