Katkat

Compute BBO and NBBO from order data

CitadelSoftware Engineer · Technical Screen

Last updated

This question evaluates a candidate's skill in designing efficient data structures and algorithms for aggregating and querying order-book data, including computing best bid/ask prices and summing quantities at those prices.

You are given a list data of order records. Each record is a 4-tuple:

(exchange_id, price, quantity, order_type)
  • exchange_id: string/int identifying the exchange
  • price: positive number
  • quantity: positive integer
  • order_type: either "B" (bid/buy) or "A" (ask/sell)

Implement a class QuoteBook initialized with data, supporting:

  1. get_exchange_bbo(exchange_id) -> (best_bid, best_ask)
  • Returns the best bid and best ask for that exchange.
  1. get_nbbo() -> (best_bid, best_ask)
  • Returns the national best bid and offer (NBBO) across all exchanges.

Definitions:

  • Best bid: highest bid price.
  • Best ask: lowest ask price.
  • If there are multiple orders at the same best price on the relevant scope (exchange or all exchanges), treat the displayed quantity as the sum of quantities at that best price.
  • If a side does not exist (no bids or no asks), return None for that side.

Return format:

  • best_bid and best_ask should each be either None or a tuple (price, total_quantity_at_price).

Constraints/expectations:

  • len(data) can be large (e.g., up to 10^5 or more), so repeated calls to these methods should be efficient.