Market Making & Microstructure Research Platform
GitHubOverview
Research framework for market making as a coupled system of alpha, execution, inventory, and regime-dependent liquidity provision.
Built for live L2 market data, deterministic replay, and execution-aware signal evaluation.
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
Most theoretical edge is lost through execution and adverse selection, not prediction error.
System Overview
Market Data / Replay
│
▼
Order Book State
│
▼
Regime Detection (GMM clustering)
│
▼
Alpha Stack
├─ Microstructure Alpha (fast signal)
├─ Structural Alpha (slow microstructure)
└─ ML Residual Alpha (XGBoost correction)
│
▼
Toxicity Model (expected markout)
│
▼
Quote / Skew / Size Decision
│
▼
Execution Model (queue + cancellations + fees)
│
▼
Inventory / Risk
│
▼
Dataset Generation & Research
Supports:
- live trading
- paper trading
- full historical replay
Regime Model
Unsupervised Gaussian Mixture Model (GMM) using:
- volatility
- spread
- order imbalance
- trade imbalance
- quote churn
- inventory
- inventory volatility
- microprice error
Results:
- discrete market regimes with materially different alpha expression.
Key observations:
- regimes gate alpha effectiveness rather than generate edge.
Alpha Stack
1. Microprice Alpha
Top-of-book imbalance signal.
- strongest at 100 - 500ms horizons
- captures immediate order book pressure
- fast-decaying but directionally informative
2. Structural Alpha
Slower microstructure signal:
- volatility
- order/trade imbalance
- inventory pressure
- microprice deviation
More stable estimate of short-horizon fair value than microprice alone.
3. Residual ML (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:
- imbalance
- spread
- volatility
- microprice deviation
- inventory pressure
- queue position
Outputs:
- negative → toxic liquidity
- positive → favorable execution
Role:
- execution gating / participation filter
- used for skewing and size adjustment
Results:
- strong short-horizon predictability of adverse selection
- improves execution quality more than standalone PnL
Execution Model
1. Fill Model
Passive fill modeled as stochastic Poisson queue depletion:
P(fill) = 1 − exp(−(λ_t / Q_t) ⋅ Δ_t)
Includes:
- trade-driven depletion
- cancellation-driven depletion (explicitly modeled)
Key correction:
- queue reduction is not equivalent to executed volume
2. Cost Model
PnL = spread capture + alpha − fees − adverse selection − slippage
Key implications:
- fees + turnover materially impact viability
- small execution inefficiencies dominate marginal signal gains
3. Latency Model
Execution timing significantly affects realized outcomes.
Future work:
- order placement latency
- cancellation latency
- exchange acknowledgement delays
Inventory Model
Inventory treated as a continuous risk state.
Reservation price adjusts based on:
- inventory level
- volatility
- regime
Objective:
- balance spread capture vs directional exposure under changing conditions.
Key Results
1. Alpha hierarchy is stable
- structural alpha > microprice > residual ML (short horizon)
2. Regimes improve selection, not edge
- reduce drawdowns
- improve consistency
- do not independently generate alpha
3. Toxicity is execution-side signal
- strong markout predictability
- improves fill quality
- can reduce PnL if overused (over-filtering)
4. Execution dominates marginal alpha gains
- queue dynamics + cancellations + fees significantly alter outcomes
- naive alpha materially degrades under realistic execution
Edge Decomposition
Market making performance decomposes into:
- alpha: where edge exists
- regime: when edge is valid
- toxicity: whether to participate
- execution: whether edge is realized
- fees: whether edge survives
- latency: how fast edge is captured
Core Takeaway
Market making performance decomposes into:
- alpha: where edge exists
- regime: when edge is valid
- toxicity: whether to participate
- execution: whether edge is realized
- fees: whether edge survives
- latency: how fast edge is captured
Live Execution (Binance Futures Testnet)
The platform includes a full live execution layer on Binance Futures Testnet, closing the loop from signal generation → quoting → execution → fills → PnL, and validating microstructure assumptions against real exchange behavior.
Execution Stack
Broker Layer (BinanceBroker)
- 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 (LiveExecution)
- 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 Handler (BinanceUserStream)
- WebSocket ORDER_TRADE_UPDATE processing
- handles NEW / TRADE / CANCELED / REJECTED states
- maintains queue position estimates at entry
- synchronizes internal execution state with exchange events
Key Live Findings
1. Latency is structural (~600-700ms end-to-end)
signal → execution exhibits latency dominated by REST gateway, network RTT, and WebSocket propagation
latency is a first-order state variable; it must be explicitly modeled in fill probability and queue dynamics
2. Market data is asynchronous (~150-300ms bursty updates)
order book updates arrive in event-driven bursts rather than fixed intervals due to batched WebSocket delivery
L2 data is intrinsically irregular; fixed-timestep assumptions distort microstructure inference
3. Execution dominates signal quality
queue position, cancellation timing, and latency differentials materially affect realized outcomes
most theoretical alpha is reshaped by execution mechanics rather than prediction error
4. Alpha-execution decomposition holds in practice
alpha identifies directional bias, toxicity captures adverse selection risk, and execution determines realized PnL
short-horizon variance is dominated by execution noise rather than signal quality
5. Queue state is first-class signal
queue position, cancellation dynamics, and trade-driven depletion are primary drivers of fill probability
validates explicit modeling of queue-ahead, cancellation resets, and trade-flow-based depletion
Updated Core Takeaway (Reinforced)
Market making is not constrained by predictive signal quality.
It is constrained by:
- latency uncertainty
- queue position randomness
- execution path dependence
- regime-dependent liquidity fragility
In live conditions, execution dynamics dominate alpha, and the primary optimization problem becomes:
- selective participation under microstructure and latency constraints, not prediction.
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.