Design and implement a continuous double-auction in-memory Limit Order Book (LOB) matching engine conforming to production exchange specifications.
Price-Time Priority (FIFO):
Your Task
Implement the LimitOrderBook class:
add_limit_order(order_id: int, side: str, price: float, volume: int) -> list[dict]:
'buy' or 'sell'. Matches against existing opposite resting liquidity.[{'maker_id': int, 'taker_id': int, 'price': float, 'volume': int}, ...].add_market_order(order_id: int, side: str, volume: int) -> list[dict]:
cancel_order(order_id: int) -> bool:
True if found, False otherwise.get_bbo() -> tuple[tuple[float, int] | None, tuple[float, int] | None]:
((best_bid_price, best_bid_volume), (best_ask_price, best_ask_volume)) or None for empty side.get_depth(levels: int = 5) -> dict[str, list[tuple[float, int]]]: Returns top price levels with cumulative volume: {'bids': [...], 'asks': [...]}.Constraints