Day 52 — Volume Matching: Partial Fills Based on Simulated Liquidity
Real markets do not give you what you ask for. You ask for 500 shares of AAPL and the market might hand you 312 — spread across four price levels, arriving in separate confirmations over the next 80 milliseconds. What your engine does with that gap between “asked” and “received” is what separates a simulation from a trading system.
Today you will build the piece of the engine that handles exactly this: a volume matching engine that walks order book price levels, applies a participation rate cap, emits partial fill events, and drives an order through a proper state machine. You will wire it to the Alpaca paper trading sandbox to validate your simulation against real market behaviour.
By the end of this lesson, your engine will never assume an order is filled until every share is confirmed.
What You Are Building
Before touching code, here is the full picture of what this module does and where it fits.



