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
Coding & Algorithms
Software Engineer
D. E. Shaw
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
order book
heaps
FIFO queues
lazy deletion
matching engine
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions