InterviewDB
Question
·
Los Angeles
Exchange Broker: Implement an Order Matching Engine for a Simple Exchange
Onsite
Question Details
Problem
Build a simplified order matching engine for a single trading pair. Support limit orders (buy/sell at a specific price) and market orders (execute at best available price). Match buy orders against sell orders using price-time priority.
Return a list of fills.
python
class Exchange:
def place_order(self, order_id: str, side: str, order_type: str,
price: float | None, qty: int) -> list[dict]:
"""
side: 'buy' or 'sell'
order_type: 'limit' or 'market'
**Returns** list of fills: [{buy_id, sell_id, price, qty}]
"""
pass
def cancel_order(self, order_id: str) -> bool: ...
def get_orderbook(self) -> dict: ... # {bids: [...], asks: [...]}
Example:
place_order("B1", "buy", "limit", 100.0, 10) -> [] # sits in book
place_order("S1", "sell", "limit", 99.0, 5) -> [{buy:B1, sell:S1, price:100.0, qty:5}]
Follow-ups
- Why does a limit buy match against a sell at 99 when the buy was placed at 100?
- What data structures back your bid and ask books for O(log n) insert and O(1) best-price lookup?
- How do you handle partial fills and track remaining quantity?
- Extend to support stop-loss orders — how do they interact with the matching loop?
Full Details
Problem
Build a simplified order matching engine for a single trading pair. Support limit orders (buy/sell at a specific price) and market orders (execute at best available price). Match buy orders against sell orders using price-time priority.
Return a list of fills.
python
class Exchange:
def place_order(self, order_id: str, side: str, order_type: str,
price: float | None, qty: int) -> list[dict]:
"""
side: 'buy' or 'sell'
order_type: 'limit' or 'market'
**Returns** list of fills: [{buy_id, sell_id, price, qty}]
"""
pass
def cancel_order(self, order_id: str) -> bool: ...
def get_orderbook(self) -> dict: ... # {bids: [...], asks: [...]}
Example:
place_order("B1", "buy", "limit", 100.0, 10) -> [] # sits in book
place_order("S1", "sell", "limit", 99.0, 5) -> [{buy:B1, sell:S1, price:100.0, qty:5}]
Follow-ups
- Why does a limit buy match against a sell at 99 when the buy was placed at 100?
- What data structures back your bid and ask books for O(log n) insert and O(1) best-price lookup?
- How do you handle partial fills and track remaining quantity?
- Extend to support stop-loss orders — how do they interact with the matching loop?
Free preview. Unlock all Voleon Group questions →
About This Question
This is a reported interview question from a voleon group interview during the onsite round.
More Voleon Group Interview Questions
InterviewDB
Voleon Group SWE Phone - Blanket of White (Matrix/BFS)
InterviewDB
Voleon Group SWE Onsite - Good String (Strings)
InterviewDB
Voleon Group SWE Phone - Chess Move (Matrix/Simulation)
InterviewDB
Voleon Group SWE Phone - Circular Ring (Arrays/Math)
InterviewDB
Matrix Operations: Implement Efficient Sparse Matrix Addition, Multiplication, and Transpose