-
Notifications
You must be signed in to change notification settings - Fork 12
Business Logic Order Routing and Execution
This document explains the execution routing strategies, Smart Order Routing (SOR) NBBO matching algorithms, and VWAP algorithmic time-slicing implemented in Emporia Trading Platform's execution-service.
When execution-service consumes an OrderCreated event from emporia.orders.v1, it selects an execution strategy based on order characteristics:
flowchart TD
OrderEvent["OrderCreated Event"] --> StrategySelection{"Strategy Selected"}
StrategySelection -->|DIRECT| DirectRoute["Direct Execution Route"]
StrategySelection -->|SMART| SorRoute["Smart Order Router (SOR)"]
StrategySelection -->|VWAP| VwapRoute["VWAP Algorithmic Execution"]
DirectRoute --> ExchangeCore["Exchange Core Matching Engine"]
SorRoute --> NbboEval["Evaluate NBBO Across Exchange Venues"]
NbboEval --> VenueSlice["Route Child Slice to Best Price Venue"]
VwapRoute --> TimeSlice["Decompose Parent Order into Time Slices"]
TimeSlice --> ChildOrders["Issue Child Orders via Kafka (order.commands.v1)"]
The Smart Order Router (SOR) enforces regulatory Best Execution by analyzing the National Best Bid and Offer (NBBO) across connected liquidity venues.
-
For BUY Orders: Route to the venue displaying the lowest Ask price (
$\min P_{\text{ask}}$ ). -
For SELL Orders: Route to the venue displaying the highest Bid price (
$\max P_{\text{bid}}$ ). -
Tie-Breaking Rule: If multiple venues offer identical prices, priority is given to the venue displaying the largest available depth / size (
$\max Q_{\text{available}}$ ).
If a single venue does not possess sufficient quantity to satisfy the incoming order size
Example:
- Parent Order:
BUY 500 AAPL @ MARKET - Venue A Depth:
100 AAPL @ $150.00 - Venue B Depth:
300 AAPL @ $150.00 - Venue C Depth:
200 AAPL @ $150.05 -
Routing Decision:
- Slice 1:
BUY 300 AAPLto Venue B @ $150.00 - Slice 2:
BUY 100 AAPLto Venue A @ $150.00 - Slice 3:
BUY 100 AAPLto Venue C @ $150.05
- Slice 1:
The Volume-Weighted Average Price (VWAP) strategy minimizes market impact for large institutional parent orders by slicing them into child orders distributed across a specified trading time horizon
The algorithm divides the trading day into
For a parent order of size
sequenceDiagram
autonumber
participant ParentOrder as Parent Order (10,000 shares)
participant VWAP as VWAP Execution Engine
participant Kafka as Kafka (emporia.order.commands.v1)
participant Venue as Execution Venue
Note over VWAP: Load 5-min Intraday Volume Profile
loop Every 5-Minute Time Interval
VWAP->>VWAP: Calculate target slice q_i = Q_parent * w_i
VWAP->>Kafka: Issue Child Order (CREATE 500 shares)
Kafka->>Venue: Execute Child Order
Venue-->>VWAP: Child Order Filled
end
- Parent Order ID: Unique UUID generated upon initial order placement.
-
Child Order ID: Each algorithmic slice receives a unique
childOrderIdwith a reference toparentOrderId. -
Completion Criteria: Parent order transitions to
FILLEDonly when the cumulative filled quantity of all child orders equals the parentquantity.
- 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