Build a Price-Time Priority Matching Engine for Power Blocks
Last updated: November 29, 2026
Quick Overview
Implement a continuous double-auction matcher for a single half-hour power contract: process limit buy and sell orders in arrival order, match against the best resting prices with time priority, support partial fills, and return the list of trades.
Fuse Energy
November 29, 20260
0
0 solved
Implement a continuous double-auction matcher for a single half-hour power contract: process limit buy and sell orders in arrival order, match against the best resting prices with time priority, support partial fills, and return the list of trades.
Fuse trades power in real time on intraday markets, and engineers on the trading team need a precise mental model of how continuous order books match. The screen checks correct heap use, partial fills that keep time priority, and trading at the resting order's price.
What the Interviewer Expects
- Use a max-heap for bids and a min-heap for asks keyed by (price, arrival sequence)
- Trade at the resting order's price, not the aggressor's
- Handle partial fills on both the incoming and resting order
- Preserve time priority of a partially filled resting order
- Discuss complexity per order
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support cancel and amend by order id efficiently?
- How would you extend to many contracts (48 half-hours, blocks spanning several periods)?
- What changes for iceberg orders that only show part of their size?
- How would you make the engine deterministic and replayable for audits?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Orders: (id, side 'B' or 'S', price, qty) in arrival order for one contract. An incoming buy matches resting asks priced at or below its limit, best (lowest) price first and earliest first among equ...
High-Level Design
Two heaps: asks as (price, seq, id, qty) (min-heap), bids as (-price, seq, id, qty). A global counter gives seq so ties break by arrival. When a resting order is partially filled, push it back w...