Design and Implement an In-Memory Order Book
Model resting orders, support cancellation, and return the exact aggregate volume at a requested price level.
Design and implement the core of an in-memory order book. The reported interview task required three capabilities: insert a new order, delete an existing order, and retrieve the total volume at a given price level.
For this exercise, assume the book handles one instrument and stores resting limit orders only; matching, trade execution, persistence, networking, and market-data distribution are outside scope.
Each order has a unique string order ID, a BUY or SELL side, a positive integer price in ticks, and a positive integer quantity. A price level is identified by side and price. Adding a duplicate order ID or cancelling an unknown order must return an explicit error without changing state.
Cancelling an order removes its full remaining quantity. The aggregate returned for a level must always equal the sum of quantities of the resting orders at that side and price.
Present a design that keeps these operations consistent, then implement the three central operations using your own interfaces and object model.