-
Notifications
You must be signed in to change notification settings - Fork 12
Business Logic Order Lifecycle
This document details the financial domain rules governing order types, order validation constraints, mathematical invariants, state machine transitions, and fill accounting in the Emporia Trading Platform.
Emporia supports equity order submission with parameters aligned to institutional execution standards:
| Parameter | Type / Values | Description & Constraints |
|---|---|---|
side |
BUY / SELL
|
Order side. BUY increases long position or covers short; SELL decreases long or initiates short. |
orderType |
MARKET / LIMIT / STOP_LOSS / TAKE_PROFIT
|
Execution instruction type. MARKET executes immediately at best available price; LIMIT requires limitPrice. |
quantity |
BigDecimal ( |
Total requested order quantity in shares. Must be a positive multiple of the instrument's sizeIncrement. |
limitPrice |
BigDecimal ( |
Maximum price for a BUY limit order or minimum price for a SELL limit order. Must align with tickSize. |
timeInForce |
DAY / IOC / FOK / GTC
|
Order validity duration. IOC (Immediate-or-Cancel), FOK (Fill-or-Kill), GTC (Good-Till-Cancelled). |
Before an order command is accepted by order-command-service, it undergoes quantitative validation against static exchange listings:
flowchart TD
Command["Order Command Received"] --> CheckQty{"Quantity > 0 & Aligned to Size Increment?"}
CheckQty -- No --> RejectQty["Reject: Invalid Quantity / Lot Size"]
CheckQty -- Yes --> CheckPrice{"Is LIMIT order & Price > 0?"}
CheckPrice -- No --> RejectPrice["Reject: Missing / Non-positive Limit Price"]
CheckPrice -- Yes --> CheckTick{"Price Aligned to Tick Size?"}
CheckTick -- No --> RejectTick["Reject: Price violates Tick Increment"]
CheckTick -- Yes --> CheckBand{"Price within Price Collar Band?"}
CheckBand -- No --> RejectCollar["Reject: Price outside Permitted Collar"]
CheckBand -- Yes --> Accept["Publish CREATE to Kafka (order.commands.v1)"]
-
Size Increment Alignment:
$$\text{quantity} \pmod{\text{sizeIncrement}} = 0$$ Example: IfsizeIncrement = 1.0, an order for 100 shares is valid; 100.5 shares is rejected. -
Tick Size Alignment:
$$\text{limitPrice} \pmod{\text{tickSize}} = 0$$ Example: IftickSize = 0.01, $25.10 is valid; $25.105 is rejected. -
Price Collar Band Guard:
$$\text{lowerBand} \le \text{limitPrice} \le \text{upperBand}$$ Protects against fat-finger errors and rogue algorithmic prices.
Trading orders move through deterministic state transitions enforced by synchronized methods on the TradingOrder domain entity.
stateDiagram-v2
[*] --> PENDING_NEW: Order Received
PENDING_NEW --> LIVE: Validated & Acked by OMS
PENDING_NEW --> REJECTED: Validation Failure / Risk Breach
LIVE --> PARTIALLY_FILLED: Partial Venue Fill
LIVE --> FILLED: Full Venue Fill
LIVE --> CANCELLED: Order Cancel Confirmed
PARTIALLY_FILLED --> PARTIALLY_FILLED: Additional Partial Fill
PARTIALLY_FILLED --> FILLED: Final Fill (Remaining Qty = 0)
PARTIALLY_FILLED --> CANCELLED: Cancel Unfilled Balance
CANCELLED --> FILLED: Late Full Fill Accepted
CANCELLED --> CANCELLED: Late Partial Fill Accepted
FILLED --> [*]
CANCELLED --> [*]
REJECTED --> [*]
For every execution fill applied to a TradingOrder, the following mathematical invariants are strictly enforced:
At order creation:
When a fill of size
Decimal Precision: Calculated using BigDecimal with 6 decimal places of precision (RoundingMode.HALF_UP).
In real-world electronic trading, execution venue fills and cancellation messages race over networks.
-
Rule: If an order has been
CANCELLED, any execution fill that occurred at the exchange prior to or concurrently with the cancellation must still be accepted and accounted for. -
Handling:
applyFill()accepts fills on orders inLIVE,PARTIALLY_FILLED, orCANCELLEDstatus. If a fill consumes the remaining quantity, the order status advances toFILLED, ensuring position and trade accounting accuracy.
- 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