Build a Price-Level Book From Order-Level Feed Messages

Last updated: November 29, 2026

Quick Overview

Implement a structure that consumes order-level market data messages (add, partial execute or cancel, delete, replace with new id) and maintains aggregated quantity per price level, answering best bid, best offer, and top-N depth queries efficiently.

Chicago Trading Company
Coding & Algorithms
Software Engineer
Chicago Trading Company
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Implement a structure that consumes order-level market data messages (add, partial execute or cancel, delete, replace with new id) and maintains aggregated quantity per price level, answering best bid, best offer, and top-N depth queries efficiently.

CTC hires C++ engineers for its market data platform and feed handlers for protocols such as ITCH that publish every order. This question checks that you can design the two-level mapping (orders to levels) and keep best-price queries fast while levels empty out constantly.

What the Interviewer Expects
  • Keeps an order id map so executes and cancels can find side and price
  • Aggregates quantity per price level and removes empty levels
  • Gives fast best-price lookup (heap with lazy deletion, or sorted structure)
  • Implements replace as delete plus add preserving the side
  • Rejects or handles duplicate and unknown order ids
  • Discusses the C++ version: flat arrays indexed by price tick
Key Topics to Cover
order book
hash maps
heaps with lazy deletion
ITCH-style messages
market data
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
  • Prices fall in a bounded tick range near the touch. How would you lay this out for cache efficiency in C++?
  • How do you detect and recover when a message references an order id you never saw?
  • What changes to support order-by-order queue position for your own orders?
  • How would you publish incremental level updates to downstream strategies?
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

Messages: add(oid, side, price, qty), reduce(oid, qty) for partial executions or partial cancels, delete(oid), replace(oid, new_oid, price, qty). Queries: best(side) returning `(price, total...

High-Level Design

Two maps. orders: oid -> (side, price, qty) lets every non-add message locate its level. levels[side]: price -> total_qty is the aggregated view. For the best price keep a heap per side with lazy ...


Submit Your Answer
Markdown supported

Related Questions