PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Two Sigma

Implement Price-Time Order Matching

Last updated: May 15, 2026

Quick Overview

This question evaluates understanding of limit-order book mechanics, priority-based matching, stateful stream processing, and data-structure management for handling partial fills and price-time tie-breaking.

  • medium
  • Two Sigma
  • Coding & Algorithms
  • Software Engineer

Implement Price-Time Order Matching

Company: Two Sigma

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a simplified limit-order matching engine for a stock exchange. You receive a stream of orders. Each order has: - `order_id`: unique identifier - `side`: `BUY` or `SELL` - `price`: limit price - `quantity`: positive integer share quantity - `timestamp`: arrival time, or an equivalent sequence number Matching rules: 1. A buy order can match a resting sell order when the buy price is greater than or equal to the sell price. 2. A sell order can match a resting buy order when the sell price is less than or equal to the buy price. 3. Among eligible resting orders, match by best price first: highest bid for buys, lowest ask for sells. 4. If multiple resting orders have the same price, match the earliest order first. 5. A trade quantity is the minimum of the incoming order's remaining quantity and the resting order's remaining quantity. 6. Partially filled orders keep their remaining quantity. Fully filled orders leave the book. Any unfilled remainder of the incoming order is added to the book. Implement an API such as `add_order(order)` that processes one order and returns the trades generated by that order. Each trade should include the buy order id, sell order id, execution price, and executed quantity. Also maintain the current order book state so that future orders can match against it. Discuss the data structures you would use and handle partial fills, price-time tie breaking, heap updates, and order ids correctly.

Quick Answer: This question evaluates understanding of limit-order book mechanics, priority-based matching, stateful stream processing, and data-structure management for handling partial fills and price-time tie-breaking.

Related Interview Questions

  • Compute Piecewise Linear Interpolation - Two Sigma (medium)
  • Merge two sorted linked lists - Two Sigma (hard)
  • Implement an In-Memory Database - Two Sigma (hard)
  • Merge Two Sorted Lists - Two Sigma (hard)
  • Evaluate a Piecewise Linear Function - Two Sigma (medium)
|Home/Coding & Algorithms/Two Sigma

Implement Price-Time Order Matching

Two Sigma logo
Two Sigma
May 9, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
3
0
Practice Read
Loading...

Implement a simplified limit-order matching engine for a stock exchange.

You receive a stream of orders. Each order has:

  • order_id : unique identifier
  • side : BUY or SELL
  • price : limit price
  • quantity : positive integer share quantity
  • timestamp : arrival time, or an equivalent sequence number

Matching rules:

  1. A buy order can match a resting sell order when the buy price is greater than or equal to the sell price.
  2. A sell order can match a resting buy order when the sell price is less than or equal to the buy price.
  3. Among eligible resting orders, match by best price first: highest bid for buys, lowest ask for sells.
  4. If multiple resting orders have the same price, match the earliest order first.
  5. A trade quantity is the minimum of the incoming order's remaining quantity and the resting order's remaining quantity.
  6. Partially filled orders keep their remaining quantity. Fully filled orders leave the book. Any unfilled remainder of the incoming order is added to the book.

Implement an API such as add_order(order) that processes one order and returns the trades generated by that order. Each trade should include the buy order id, sell order id, execution price, and executed quantity. Also maintain the current order book state so that future orders can match against it.

Discuss the data structures you would use and handle partial fills, price-time tie breaking, heap updates, and order ids correctly.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Two Sigma•More Software Engineer•Two Sigma Software Engineer•Two Sigma Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.