Price Time Priority Matching for a Limit Order Book
Last updated: November 29, 2026
Quick Overview
Implement a single-symbol limit order book that accepts limit orders and cancels, matches crossing orders at the resting order's price with price-then-time priority, and returns the fills produced by each submission.
D. E. Shaw
November 29, 20260
0
0 solved
Implement a single-symbol limit order book that accepts limit orders and cancels, matches crossing orders at the resting order's price with price-then-time priority, and returns the fills produced by each submission.
A core onsite coding problem in the style of D. E. Shaw's trading systems interviews, where engineers build and simulate execution infrastructure. The interviewer looks for correct priority rules, clean handling of partial fills and cancels, and data structures that keep best-price lookup fast.
What the Interviewer Expects
- Keeps bids as a max structure and asks as a min structure keyed by price
- Uses a FIFO queue per price level for time priority
- Fills at the resting price and handles partial fills on both sides
- Implements cancel in O(1) using lazy deletion or a linked list
- States complexity per operation and walks through a crossing example
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support market orders and immediate-or-cancel orders?
- How do you make cancel truly O(1) without lazy deletion?
- How would you replay a day of exchange messages through this to test a strategy's fills?
- What changes for a production engine written in C++ with latency targets in microseconds?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
submit(id, side, price, qty) matches against the opposite side while the best opposite price crosses (best ask <= buy limit, or best bid >= sell limit). Each match trades `min(remaining, resting qty...
High-Level Design
Two heaps hold price levels (bids negated). A dict maps (side, price) to a deque of order ids in arrival order, giving time priority within a level. A dict orders holds live orders with remaining ...