Market Making Trading System
GitHubOverview
Production-oriented market-making engine for systematic liquidity provision under real microstructure, execution, inventory, and latency constraints.
The system combines:
- live L2 market data
- deterministic historical replay
- regime-dependent alpha
- structural fair-value estimation
- residual alphatoxicity / adverse-selection modeling
- queue-aware execution simulation
- inventory-aware quoting
- exchange execution and reconciliation
The system has progressed from historical research and simulation to live capital deployment, allowing execution assumptions, fill models, latency, queue dynamics, and signal behavior to be evaluated against real exchange executions.
Core Insight
Market making is not a forecasting problem.
It is a conditional execution problem under microstructure constraints:
- alpha identifies where edge exists
- regimes determine when edge is valid
- toxicity determines whether liquidity should be provided
- execution determines whether edge is realized
- fees + queue dynamics determine whether edge survives
The key design principle is therefore:
Selective participation under realistic execution constraints is more important than maximizing predictive accuracy.
The system explicitly couples signal generation with execution, rather than evaluating alpha independently from the mechanism through which it is monetized.
System Overview
Market Discovery
│
▼
Market Data / Replay
│
▼
Order Book State
│
▼
Regime Detection (GMM clustering)
│
▼
Alpha Stack
├─ Microstructure Alpha
├─ Structural Alpha
└─ Residual Alpha (XGBoost)
│
▼
Toxicity Model (expected markout - XGBoost)
│
▼
Quote / Skew / Size Decision
│
▼
Execution Model (queue + cancellations + fees)
│
▼
Inventory / Risk
│
▼
Dataset Generation & Research
The same stack supports:
- live capital deployment
- paper trading
- exchange Testnet execution
- historical replay
Market Discovery
Market discovery identifies markets where market making has sufficient structural edge to justify quoting.
The objective is not to select markets based on headline spread alone, but to find markets where net spread, liquidity, activity, and execution quality combine to create favorable conditions for passive liquidity provision.
Market Selection:
The discovery layer continuously evaluates:
transaction fees
gross and net spread
bid/ask liquidity
trade activity
order-book depth
A wide spread is only attractive if it is executable and persistent. For example:
Net Spread = Gross Spread − Fees − Expected Execution Costs
Liquidity is evaluated conservatively using the smaller side of the book:
- L_min = min(Bid Liquidity, Ask Liquidity)
and relative balance:
- Balance = min(Bid, Ask) / max(Bid, Ask)
This avoids prioritizing markets where apparent spread is supported by only one side of a thin or unstable order book.
Candidate Ranking:
Markets are ranked using a combination of:
Net Spread × Liquidity × Liquidity Balance × Transaction Fees × Market Activity
The resulting candidates are passed into the trading stack.
Market discovery therefore answers::
Where should we trade?
While the downstream models determine:
When should we quote, which side should we favor, and how much should we trade?
This separation prevents high displayed spreads from being mistaken for genuine trading opportunities and focuses capital on markets where the realized spread has the highest probability of surviving fees, adverse selection, queue dynamics, and execution latency.
Regime Model
Unsupervised Gaussian Mixture Model (GMM) using:
- spread
- volatility
- order imbalance
- trade imbalance
- microprice deviation (microprice - mid)
The regime layer is used primarily as a conditional gate on alpha and liquidity provision, rather than as an independent source of predictive edge.
Different regimes exhibit materially different:
- alpha decay
- spread behavior
- adverse-selection risk
- fill dynamics
- inventory risk
This allows the execution policy to become more selective when the liquidity environment becomes fragile.:
Alpha Stack
1. Microprice Alpha
The fastest alpha component is based on the displacement between microprice and the mid:
micro_signal_t = (microprice_t - mid_t) / mid_t
where microprice incorporates top-of-book price and liquidity imbalance.
The signal is evaluated against future mid returns:
y_h = (mid_{t+h} - mid_t) / mid_t
This deliberately evaluates the raw microstructure signal against future price movement before structural delta is incorporated into the quoting policy.
Current out-of-sample diagnostics:
The main observation is that microprice deviation contains predictive information beyond the immediate quote horizon.
Rather than exhibiting purely rapid decay, the current results show increasing predictive strength through the 5-second horizon:
100ms → IC 0.129
500ms → IC 0.200
1s → IC 0.273
5s → IC 0.416
This suggests that the top-of-book state is capturing information about subsequent order-flow and price evolution that persists beyond the immediate matching interval.
2. Structural Alpha
Slower microstructure signal:
- volatility
- order imbalance
- trade imbalance
- microprice deviation
- inventory pressure
This makes structural alpha a policy-controlled adjustment to the quoting center rather than an unconstrained directional forecast.
The coefficient alpha_struct controls how aggressively the execution policy incorporates structural fair value into the final reservation price.
3. Residual Alpha (XGBoost)
Learns residual drift after structured fair value:
log(mid_{t+h} / fair_value_t)
Behavior:
- weak short-horizon signal
- improves at 1 - 5s horizons
- acts as correction layer, not primary alpha
Toxicity Model (Execution Risk)
Predicts expected markout conditional on execution:
T(x) = E[future markout_h ∣ fill, state]
Inputs:
- spread
- volatility
- order imbalance
- trade imbalance
- microprice deviation
- regime
Outputs:
- negative → toxic liquidity
- positive → favorable execution
The model is used to::
- gate participation
- skew quotes
- adjust order size
- reduce exposure during adverse-selection conditions
A central design constraint is avoiding over-filtering.
A liquidity filter that removes every potentially adverse fill can improve markout statistics while simultaneously destroying the economics of market making through reduced participation.
The objective is therefore not:
maximize fill quality
but:
maximize expected execution value conditional on the cost of not participating.
Execution Model
1. Queue / Fill Model
Passive fills are modeled using explicit queue-ahead dynamics.
- trade-driven depletion (explicitly modeled)
-depth-driven depletion (cancellations, additions, quote churn estimation, hawkes)
-hawkes excitation
Q_t (Queue_ahead) = Q_t-1 - trade-driven depletion - (β_raw * multiplier * excitation) * (depth-driven depletion)
Passive fill modeled as stochastic Poisson queue depletion:
P(fill) = 1 − exp(−(λ_t / Q_t) ⋅ Δ_t)
Key correction:
- queue reduction is not equivalent to executed volume
2. Cost Model
PnL = spread capture + alpha − fees − adverse selection − slippage
This decomposition allows the strategy to determine whether improvements are coming from:
- better pricing
- better directional selection
- better fill selection
- better inventory management
- better execution
rather than simply observing aggregate PnL.
3. Latency Model
Execution timing significantly affects realized outcomes.
Future work:
- order placement latency
- cancellation latency
- exchange acknowledgement delays
Inventory / Risk
Inventory treated as a continuous risk state.
Reservation price adjusts based on:
- inventory level
- volatility
- regime
- toxicity
Objective:
- balance spread capture vs directional exposure under changing conditions.
Live Execution
The system has progressed from simulation and Testnet execution to live capital deployment.The live execution stack currently includes:
Broker Layer
- REST order placement/cancel with HMAC authentication
- user data stream (listenKey) for order lifecycle tracking
- position reconciliation via positionRisk
- session keepalive and recovery handling
Execution Engine
- inventory- and volatility-adjusted asymmetric quoting
- toxicity-aware participation and sizing
- queue-aware cancel/replace logic
- real-time trade-flow ingestion for state updates
User Stream
- handles WebSocket NEW / TRADE / CANCELED / REJECTED trades
- maintains queue position estimates at entry
- synchronizes internal execution state with exchange events
Live Execution Results
Initial live deployment is being used primarily as execution validation, rather than as a claim of statistically significant strategy performance.
Current fills provide direct measurements of the difference between the simulated execution environment and the real exchange.
Observed live characteristics include:
1. Maker vs Taker Execution
The live execution log explicitly records whether a fill was passive or aggressive.
This enables separate attribution of:
- maker spread capture
- taker execution
- adverse selection
- fees
- inventory effects
The distinction is important because a theoretically attractive market-making signal can become uneconomic if execution logic repeatedly crosses the spread to manage inventory.
2. Live Markout Analysis
Each live fill is now evaluated against future market movement using signed markouts:
100ms
500ms
1s
5s
The live dataset records:
- signed markout
- signed adverse selection
- signal at decision time
- quote churn
- snapshot age
- execution latency
- time to fill
- side
- price
- quantity
- maker/taker status
This allows the system to connect:
State at Quote
↓
Decision
↓
Queue / Latency
↓
Fill
↓
Future Price Path
rather than evaluating fills only through realized PnL.
The current live sample is still too small to make strong statistical claims about profitability. Its primary value is establishing the instrumentation required to measure whether the simulated execution assumptions survive contact with the exchange.
Live Validation Loop
The live system is designed as a closed feedback loop:
Historical Research
↓
Simulation
↓
Paper / Testnet
↓
Live Execution
↓
Execution Diagnostics
↓
Model Calibration
↓
Simulation
↓
Live Deployment
The most important parameters being validated live are:
- latency distribution
- snapshot staleness
- queue-ahead estimates
- trade-driven depletion
- cancellation-driven depletion
- fill probability
- toxicity / markout predictions
- regime classification
- inventory response
This allows the live system to improve the execution model using observed exchange behavior rather than relying entirely on historical assumptions.
4. Execution dominates marginal alpha gains
- queue dynamics + cancellations + fees significantly alter outcomes
- naive alpha materially degrades under realistic execution
Key Results
1. Alpha is horizon-dependent
The current micro signal alpha exhibits increasing predictive information with horizon:
Micro Signal IC:
100ms 0.129
500ms 0.200
1s 0.273
5s 0.416
This suggests that the micro signal is better suited to medium short-horizon fair-value correction than to ultra-fast quote decisions.
2. Regimes improve conditional participation
Regimes are used to determine when existing signals should be trusted and when liquidity provision should be reduced.
They are not treated as an independent alpha source.
3. Toxicity is an execution signal
The objective of toxicity modeling is not simply to predict future price movement.
It is to answer:
If I get filled here, was I providing liquidity to informed flow?
This makes markout conditional on execution substantially more relevant than unconditional return prediction.
4. Execution dominates marginal signal improvements
Live deployment is reinforcing the importance of:
- queue position
- latency
- snapshot age
- cancellation dynamics
- order arrival timing
- fill selection
A small improvement in predictive accuracy can be economically irrelevant if the corresponding quote arrives too late or joins an unfavorable queue.
Edge Decomposition
The system decomposes market-making performance into:
Alpha
→ where edge exists
Regime
→ when the edge is reliable
Toxicity
→ whether providing liquidity is attractive
Reservation Price
→ how the edge is incorporated into quotes
Queue
→ probability of actually getting filled
Latency
→ whether the quote is still relevant when it arrives
Execution
→ whether theoretical edge becomes realized edge
Fees
→ whether realized edge survives costs
Inventory
→ whether repeated fills create unacceptable directional risk
This decomposition is central to the architecture.
Core Takeaway
The system's main optimization problem is not:
predict the next price better.
It is:
decide when the expected value of providing liquidity exceeds the combined cost of adverse selection, queue risk, latency, fees, and inventory exposure.
Live deployment makes this distinction explicit.
The research stack identifies potential edge.
The execution stack determines whether that edge can actually be monetized.
Future Directions
- Exchange-specific latency and acknowledgement modeling.
- Hawkes-process based order-flow forecasting. (completed)
- C++ engine for low-latency execution. (completed)
- Paper-trading and Testnet liquidity-provision deployment. (completed)
- Live validation for:
- fill probability estimates
- toxicity predictions
- regime classifications
against real Binance executions under small-capital deployment. (in-progress)
Trading Engine Visualizations
Trading terminal dashboard with live L2 market feed, regime detection, quoting strategy, and risk management.
Live L2 Binance Feed
Continuous updates of quotes, inventory, and market state under streaming data
Real-time microstructure execution engine
Visualizing order flow, queue state, and execution-driven PnL updates
Market Microstructure Model - Central Limit Order Book Simulation
GitHubOverview
C++ limit order book simulation modeling execution, queue priority, and liquidity dynamics in a price-time priority exchange environment.
Built to study how order flow and queue position determine execution outcomes in fast-moving markets.
Trading Problem
Execution in order-driven markets is determined by microstructure, not price alone.
Queue position, order arrival dynamics, and liquidity depth determine execution outcomes.
Core Idea
A price-time priority limit order book simulator is built to model execution under stochastic order flow.
The system focuses on how execution uncertainty emerges from matching mechanics and queue priority.
Trading Mapping
This models:
- Passive execution risk under queue position uncertainty
- Market vs limit order interaction in liquidity consumption
- Queue dynamics in market making environments
- Path-dependent execution outcomes under stochastic order arrival
Key Mechanisms
- Price-time priority (FIFO matching)
- Market / limit / cancel order flow
- Order book liquidity depletion and replenishment dynamics
- Partial fills and queue-based execution
Key Insights
- Queue position is a primary driver of execution probability in passive order flow
- Displayed liquidity is not equivalent to executable liquidity under fast order flow
- Execution outcomes are path-dependent and sensitive to order arrival sequence
- Liquidity consumption dynamics determine short-horizon fill uncertainty
Core Takeaway
Execution outcomes emerge from microstructure mechanics - specifically queue priority and stochastic liquidity interaction - rather than price levels alone.
Market Microstructure & Execution Visualizations
Benchmarks comparing execution throughput, matching latency, and order book query performance across C++ vs Python implementations.
High-Throughput Price-Time Priority Matching Engine (C++ Implementation)
C++ limit order book processing 99,999 order events in ~0.67s, demonstrating low-latency execution, queue-based matching, and high-frequency order flow processing.
Reference Order Book Engine for Logic Validation (Python Baseline)
Python implementation processing identical order flow (~6s), used as correctness benchmark for execution logic, matching consistency, and state parity validation.
Low-Latency Order Book State Query for Liquidity and Depth Inspection
Efficient retrieval of live and historical order book states enabling real-time liquidity inference and execution timing analysis.
Reconstructed Order Book Depth Snapshot for Liquidity Structure Analysis
Full market depth reconstruction illustrating resting liquidity distribution and executable order book structure at a given timestamp.
Order Book Snapshot (Add + Cancel functionality)
Order addition / cancellation behavior demonstrating liquidity removal, depth reshaping, and microstructure-driven book evolution.