Python >= 3.7
python -m src.ordermatch.main
python -m unittest
Constant time.
log2(number of orders with different prices)
Constant time.
Create a buy order heap and a sell order heap with every node in the heap being a FIFO list of same-price orders. The top element in the buy order heap has the highest price, which that in the sell order heap has the lowest price.
Maintain a hash map from order ID to the actual order. Upon cancellation, simply mark the order as cancelled, and the order would be lazily removed from the heap.
- Contains non digit characters
- Too few or too many fields
- Order side field is neither 0 nor 1
- Order to be cancelled does not exist or has already been cancelled
- Message type is neither 0 nor 1