Interpreting Order Prices, Quantities, and Partial Fills in a Matching Engine
Summary
The document clarifies basic assumptions for a simple order-matching simulator. It treats the quoted price as a per-unit limit: a seller sets the minimum price they will accept, while a buyer sets the maximum they will pay. A match is possible when the buyer’s limit is at least the seller’s, and the transaction price follows the order that arrived first. The discussion frames these limits as expressions of participants’ valuations, rather than prices that should necessarily be marked up from a separate hidden minimum or maximum.
For quantities, the answer recommends allowing partial executions when the problem does not specify all-or-none orders, filling as much as possible and leaving any unfilled remainder available. This is a reasonable default for a coding exercise, not a universal rule: order types and market rules can restrict partial fills. The source offers conceptual guidance rather than a complete matching algorithm, and it does not define tie-breaking, order priority beyond arrival order, or how to handle cancellations and other order conditions.
Key ideas
- Treat the order price as a per-unit limit price.
- A seller’s limit is the minimum acceptable price, while a buyer’s limit is the maximum they will pay.
- A trade can occur when the buyer’s limit meets or exceeds the seller’s limit.
- When order details do not specify fill constraints, allowing partial fills is a practical simulator assumption.
- Order types and market rules may require all-or-none execution instead.
Tags
Full text
# Stock market simulator coding problem # Stock market simulator coding problem I'm working on a coding problem that I was given for simulating a stock market simulator. I don't really know anything about the stock market, but the instructions state that stock market domain knowledge isn't necessary to complete this coding problem. I'm still a bit confused however, and was hoping someone here could help interpret this for me. The problem is as follows: > You're given a list of buy and sell orders represented as [buy or sell, quantity that is for sell or for buy, price]. e.g., [sell, 50, 4.50]. The order in which these orders are given is in chronological order. You're also told that a buyer has a maximum price in which they will pay for the item, and correspondingly, the seller has a minimum price in which they will sell their order. As long as there is a set of buy and sell orders that match this criteria, a transaction will occur. The cost of the transaction is in accordance with whichever order appeared first. Simulate this with code. There's a lot of ambiguities, and unfortunately, I wasn't given more information, but I'm not sure if these are actually ambiguities, or if it's just my ignorance due to lack of experience in this area. Some things that I think are ambiguous are: (1) Is the given price, a price per unit quantity, or for the entirety of the quantity? e.g., is 4.50 for the entire 50 units, or is it $4.50 per unit (so 4.50*50 for the entire order)? Is there some kind of industry standard for this? (2) We are told that the seller and buyers have their minimum and maximum bounds for selling and buying their desired item. Is this bound the price that is given? e.g., [sell, 50, 4.50] means that that specific seller will not go below 4.50? If so, that's kind of confusing to me? Why would they broadcast their lowest price instead of marking it up? On the other hand, if that's not their lowest price, then I assume that the given price is just their asking price, but then I guess we would need to be provided with their lowest price somehow? (3) Can you partially fulfill an order? e.g., say the first order is [sell, 10, 5.50] and the second order is [buy, 8, 6.00]. Can the buyer simply get 8 units from the seller (i.e., fulfill his buy order entirely and then leave that sell order with 2 units?), or do they have to buy all 10 orders? This isn't "supposed" to be a difficult problem, and I don't think it would be algorithmically. I just don't understand the question's parameters. I tagged "orderbook" but I don't think this problem is the classical order book problem? ## Answer by Mayeul sgc (score 1, accepted) https://quant.stackexchange.com/a/66459 The price is given per unit, the quantity gives you the available size or depth. The actors of the market will give you the lowest at which they are ready to sell and highest at which they are willing to buy as it translate their vision of the asset value, and they don't want to loose money. The system can match them if there is a counterparty willing to buy their sell order for a higher price than the one the specified, so no interest to pump your price. If you have troubles understanding I recommend you to check up Market Microstructure for Practitioners from Larry Harris Chapter 6, Order-driven markets. For the partial filling of the order it should depend on the type of order as it can be specified that it should be executed as a whole or can be partially filled. Given that you don't have the information I would consider that you should fill as much orders as possible even partially.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.