Modeling Exchange Order Execution with Historical Order Book Data
Summary
The document explains how to build a simplified exchange execution simulator for backtesting. It recommends using historical order book snapshots or updates to estimate fills: a market order consumes available depth until its requested quantity is filled, which supports estimates of average fill price and slippage. For a limit order, the simulator can use better-priced liquidity first, then make an assumption about whether any remaining quantity at the limit receives a full or partial fill.
The answer highlights why realistic exchange matching is difficult: order arrivals are irregular, hidden liquidity exists, and orders can affect the market. Paper trading may simplify fills by treating a price touch as sufficient regardless of order size. Data granularity can also constrain how latency is represented. The proposed approach is therefore a practical approximation, not an exact exchange replica. More advanced applications may need richer data and an execution system; the document does not provide a tested implementation or quantify the simulator’s accuracy.
Key ideas
- Historical order book depth can approximate the prices and quantities available to a simulated market order.
- Average fill price and slippage can be estimated by consuming book levels until the order quantity is filled.
- Limit order simulation requires assumptions about fills when available liquidity at the limit is insufficient.
- Irregular arrivals, hidden orders, market impact, and latency make accurate exchange simulation difficult.
Tags
Full text
# Exchange order matching system/core for local testing # Exchange order matching system/core for local testing I am looking for a service that can be deployed locally or connected to it and would emulate the order matching system of exchange (a.k.a matching core). I remember, that I have seen on GitHub repo, with software, which allows simulating `NYSE` or `NASDAQ` exchange ECN behavior. So I could send orders to it, and check how they could be executed by the trading system. Of course it's not 100% the exact copy of exchange core, but it allows to simulate different behavior. I guess I am not the only one with this problem, so I am looking for advice. Could someone remind me or share their own expirience for emulating order-matching behavior? ## Answer by quantinho (score 3, accepted) https://quant.stackexchange.com/a/75282 I am not aware of any such service but simulating exchange behavior for backtest is very challenging given irregular order arrival and their impact and hidden orders. Even the paper trading service’s order execution is very simple and has limitations (if you send a limit order it will get filled by price-touch-limit and size is irrelevant). Even if you find some Execution Management Service to install locally you would still need data and a time series database to use them. Below are some considerations if you want to build your own tool. A good order execution system should take into account market order, limit order, slippage, latency and calculating average fill price and size for both market and limit orders. If a simplified option satisfies your needs, you can implement it by yourself. You would need historical order book data up to N level (snapshot or update both are fine). When you send a market order of a certain size you go down the orderbook and keep reducing size until the final size is zero. By doing so you can calculate the average fill price (weighted by size at that price) and slippage. When you send a limit order, you can check if a better fill is available or not. If yes then you can proceed like market order but the tricky part is when you reach limit price and remaining size is greater than zero (You can assume fill or partial-fill). Depending on granularity of your order book data you can implement some logic to take latency into account. [EDIT] For advanced use cases you can refer to following open source repo: https://github.com/exchange-core/exchange-core
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.