Order Lifecycle and Queue State
6 algorithms in Matching Engines and Venue Logic.
In this family#
-
Limit-Order Lifecycle State Machine contract
Replays an order's events into its state history — new, partially filled, replaced, cancelled, done. The value is rejecting *invalid* transitions: a fill after a cancel is a bug somewhere upstream, and it must not be absorbed silently.
limitOrderLifecycle(orderIdRaw, orderQuantityRaw, eventsRaw) -
Cancel/Replace Priority Rule contract
Decides whether an amendment keeps queue position. Reducing quantity usually keeps it; raising quantity or changing price loses it. This one rule determines whether an amend is nearly free or extremely expensive.
cancelReplacePriority(originalRaw, replacementRaw) -
Partial-Fill and Residual-Quantity Processing contract
Tracks cumulative fills against an order and computes the residual. Over-fill is impossible on a correct venue, so detecting it is detecting a defect rather than handling a case.
partialFillResidual(orderQuantityRaw, fillsRaw) -
Queue Position and Ahead-Volume Calculation contract
How much volume sits ahead of a given order at its price. This is the number that decides fill probability under price-time priority — position in the queue, not distance from the touch.
queuePositionAheadVolume(ordersRaw, targetIdRaw) -
Iceberg/Reserve-Order Replenishment contract
Manages a hidden reserve that refills the displayed quantity as it fills. The trap is priority: on most venues each replenishment goes to the **back** of the queue, which is the cost of hiding size.
icebergReplenishment(totalRaw, initialRaw, displaySizeRaw, fillsRaw, priorityRaw) -
Marketable-Order Multi-Level Sweep contract
Walks a marketable order across price levels until filled or exhausted — the matching-engine counterpart of the expected-fill-price calculation, producing actual fills rather than an estimate.
marketableOrderSweep(incomingRaw, restingRaw)
What they share#
Every topic here is a record-transform, so once you have
called one the rest follow the same shape. Import paths differ only in the final segment:
import { limitOrderLifecycle } from "fintech-algorithms/matching-engines-and-venue-logic/order-lifecycle-and-queue-state/limit-order-lifecycle-state-machine";
import { cancelReplacePriority } from "fintech-algorithms/matching-engines-and-venue-logic/order-lifecycle-and-queue-state/cancel-replace-priority-rule";Read them in the order above — the sequence is pedagogical, not alphabetical.
Where this sits#
Matching Engines and Venue Logic collects 21 algorithms across 4 families. For the concept behind this family rather than the call signatures, see the concept guides.