Partial fills: reconstruct quantity before judging completion

By DX Research Group · · Execution mechanics

A worked partial-fill ledger for autonomous agents, including duplicates, residual quantity, and cancellation.

A requested quantity is not an acquired quantity

We reconstruct the acquired quantity from individual receipts so the next agent decision starts from confirmed exposure.

An autonomous agent may request ten units, receive several partial executions, and finish with fewer than ten. The difference matters for balances, outstanding exposure, and later instructions. Treating the submitted quantity as the position can propagate an error into every subsequent decision.

Bybit's execution documentation distinguishes individual execution quantities and identifiers from remaining order quantity. It also notes that one message can contain several executions. A transport message is consequently an envelope that may contain several economic events.

An illustrative order with three fills

Start with an illustrative buy order for ten units. Execution A buys two at 100, execution B buys three at 101, and execution C buys one at 102. The ledger contains six acquired units and gross spend of 200 + 303 + 102 = 605. The execution average is 605 / 6, approximately 100.833333.

Four units remain unexecuted before cancellation. If the remainder is canceled, the acquired quantity stays six. Earlier executions remain in the ledger after cancellation. The original order's terminal state and its filled quantity answer different questions: whether further matching is possible, and what actually happened.

Now replay execution B twice. The correct ledger still contains six units and spend of 605. Summing every delivered message without identity checks would create nine units and spend of 908. This example demonstrates an accounting fault without needing a live market or model prediction.

Use separate state and ledger records

Maintain a durable execution table keyed by the venue's execution identity within its documented scope. Separately maintain an order record containing requested quantity, cumulative confirmed execution quantity, outstanding quantity, and lifecycle status. A terminal order snapshot can help reconcile the cumulative total, while keeping each underlying execution represented once.

Store raw quantities as exact decimals or scaled integers. Binary floating-point accumulation can create apparent residuals smaller than a lot step. Preserve fees separately with their asset denomination. The average execution price describes gross trading value; a fee-inclusive acquisition measure needs an explicit label and currency convention.

If an order event says six units executed while available execution history contains only five, flag the gap. Query or backfill the missing evidence through the venue adapter. Manufacturing a one-unit fill at the order average would erase the distinction between known execution evidence and a reconciliation discrepancy.

A fixture for an agent evaluator

Supply the three fills in several delivery orders, followed by a cancel event. Include a duplicate and a temporary disconnect before the last fill. The expected final state is six units acquired, four canceled, no active remainder, and one unresolved interval until backfill completes.

Venue conventions vary for amendments, cumulative quantities, fee fields, and terminal states. Some instruments use contract counts rather than base units. The adapter must document those conventions and test them against current primary documentation.

This calculation separates the agent's intended exposure from verified exposure. That distinction supports meaningful evaluation of later actions: a sell instruction based on ten acquired units cannot be assessed fairly when the execution ledger confirms only six.

Fit the receipt into the full trace

Our execution and settlement framework connects these mechanics to recorded outcomes. The operating-layer controls paper explains why the machinery around an agent deserves its own evaluation.

Sources

Related field notes