TradeViora AcademyLearn. Analyze. Practice. Trade Smarter.
Menu

FREE FINANCIAL EDUCATION

Partial-fill state-machine invariants

Update positions and cash only from confirmed unique executions.

0%

What you will learn

Prerequisites: Distinguish order quantity, executed quantity, live leaves and canceled unfilled quantity.

Mechanism and decision rules

An order is an instruction whose execution can arrive in several pieces. Maintain confirmed cumulative fills, live remaining quantity, status and the set of execution identifiers already processed. Position changes come from unique fills, not from acknowledgements or repeated status snapshots. A weighted average fill price uses executed quantity weights; multiplying an unfilled requested quantity by that average overstates both cash use and exposure.

For an active unmodified order, requested quantity normally reconciles to cumulative fills plus live leaves. After cancellation, live leaves can be zero even though the order was not fully filled. In this toy model, add a separate terminal-unfilled quantity so that fills+live leaves+terminal unfilled=requested quantity. A pending cancel is not a cancellation confirmation: executions may still arrive. Trade corrections, replacements and busts require additional explicitly modeled transitions beyond this basic case.

Worked example · synthetic data

A hypothetical buy order requests 100 units at limit 50. Unique fills arrive as 30 at 49.9 and 20 at 50. A cancellation is requested, but another 25 fill at 49.8 before confirmation. Total fills are 75, cash debit is 1,497+1,000+1,245=3,742 and average price is about 49.8933. Before cancellation completes, 25 remain live. After confirmation, live leaves are zero and 25 are terminal unfilled. The position remains 75. Repeating the message for the 20-unit execution must not add another 20 units.

Failure modes and limits

Broker status fields have documented semantics that may differ across endpoints. Some reports show cumulative quantities, others individual executions; applying both as new fills double-counts. Messages can arrive out of order, so reconcile to identifiers and authoritative state rather than relying on arrival order alone. The simple invariant assumes no replacement or trade correction; those events must adjust the relevant quantities explicitly. A canceled status never means already executed shares disappeared.

Practice case

A separate account starts long 100 units and submits a sell order for 80. Unique fills are 15 at 101 and 25 at 100.8, followed by confirmed cancellation of the remaining quantity. Calculate proceeds, weighted average fill price, remaining position and terminal-unfilled order quantity, excluding charges.

Reveal the worked answer

The order sells 40 units. Proceeds are 15×101+25×100.8=4,035, and average fill price is 4,035/40=100.875. The account retains 60 units. The canceled order has cumulative fills 40, live leaves zero and terminal unfilled 40, totaling its original requested 80. Position quantity and canceled unfilled order quantity describe different things and must not be interchanged.

Check your understanding

What is the worked final position after cancellation?


Explanation

Cancellation removes the unfilled remainder, not confirmed executions.

Should a duplicate execution identifier increase cumulative fills again?


Explanation

Each confirmed execution must affect the ledger once.

Why can requested quantity exceed cumulative fills plus live leaves after cancellation?


Explanation

The active-order identity has terminal-state exceptions; the separate canceled quantity completes this toy reconciliation.

Sources and next steps

The lesson, calculations and synthetic cases are original educational material. References explain underlying contract or chart conventions; none validates the profitability of a trading rule. Actual contract specifications, settlement obligations and charges must be checked before trading.

Explore OHLCV data in the chart lab · Explore volume-at-price and TPO data · Practice library