Implement a simplified trading simulation in three parts.
Design a minimal limit-order-book simulator for a single symbol.
Each event is one of:
NEW orderId side price qty
side
is
B
(buy) or
S
(sell)
CANCEL orderId
When a new order arrives, immediately match it against resting orders on the opposite side using:
A match produces one or more trades. A trade is:
tradePrice
= resting order’s price
tradeQty
= min(incomingRemaining, restingRemaining)
For every input event, output the list of trades generated by that event (may be empty).
A single client submits a parent order:
clientId
,
side
, total target quantity
Q
, and participation rate
p
(0 < p <= 1).
You also receive a time-ordered stream of market prints (executed market volume):
PRINT t marketQty
At each print, you may execute some quantity for the client, but must satisfy at all times:
Where marketVolumeSoFar is the cumulative sum of marketQty from prints up to time t.
For each print, output how many shares you execute for the client at that time (0 if none), until the client reaches Q or prints end.
Now there are multiple simultaneous clients, each with (Q_i, p_i).
At each PRINT, compute executions for all clients such that:
i
:
executed_i <= floor(p_i * marketVolumeSoFar)
.
marketQty
.
ties broken by smaller clientId.
Implement the simulator for all three parts.
p_i * marketVolumeSoFar
allowing more than remaining.