Jianxin Shen
Lab / Trading state replay

Which rule keeps the books true?

A short trading session runs through twelve events: a repeated request, a fill delivered twice, a lost notification, an exit, and a cancel that loses a race. Five rules from the Trading Infrastructure page keep the system's books in step with the broker. Switch one off, run the session, and watch where they part ways.

Constructed data, with no connection to a real account or any real system. The page computes every state from the inputs and the rules you choose; it illustrates its own rules, not production performance.

Rules
Before the session
Target0what the strategy wants
Broker0confirmed execution
Books0matches the broker

Nothing has happened yet. The strategy holds nothing and wants nothing.

OMS orders · what the system believes

None yet.

Broker orders · what actually exists

None yet.

What each rule prevents

The same session with one rule off at a time. Every result below is computed from the same inputs and the same calculation module the page uses.

Rule setBooksBrokerTargetMost heldFirst thing that went wrong
All rules on 0 0 02 Nothing; the books and the broker agree at every check.
Retry key off 0 0 04 E2: The repeated request became a second order O-2; 4 units are now working for a target of 2.
Count each fill once off 0 -1 02 E4: F1 counted twice: books 2, broker 1.
Reconcile from history off -1 0 02 E6: The system waits for O-1 to fill; at the broker it already has. Books 1, broker 2.
Fills, not intent off -2 0 02 E8: Books show 0 while the broker still holds 2; the exit has not filled.
Wait for cancel confirmation off 0 0 02 E11: F4 arrived for O-2, which the system had already marked cancelled. Dropped: books 1, broker 0.

Two rows end with the books agreeing and still show a problem. Without the retry key the books are right, but the system held twice the position it wanted for a while. Without cancel confirmation a late fill was dropped, and only reconciliation from the broker's history put it back. Agreement at the end is not the same as being right along the way.

Try two at once

Rules cover for each other in some combinations and compound each other in others. With the fill-once rule off, reconciliation from history is what exposes the double count. Switch the history rule off as well and the session ends with the books and the broker agreeing at −1: the double count and the lost notification cancel out in the books, the exit sells one unit too many, and both records agree on a position the strategy never wanted. Two records that agree are not necessarily right.

Model assumptions, inputs and calculation rules

One instrument and one account, with no prices, no risk checks and no rejected orders. The broker acknowledges an order as soon as it is sent. The sequence of market events is fixed; only the five rules change. The PMS sizes each order as the target minus the books' position minus what the OMS believes is still working, which is why a lost notification can leave the system waiting for an order that already filled.

Reconciliation compares positions at a cutoff. With the history rule on, it also fetches the broker's fills and records any that are missing from the books, once by ID. Equal quantities alone do not prove that every underlying record is correct.

The calculation is deterministic: the same inputs and rules always produce the same states, and regression checks cover each rule switched off on its own and all 32 combinations running to an end state.

Download model inputs (JSON)Download calculation rules (JavaScript)

An earlier version of this page followed a single order through one lost notification. The Note The position didn’t change. Did the button work? describes that version and keeps its comparison.