Back to projects

Auditing Tradie: never report a state the broker hasn't confirmed

Tradie is my event-driven trading platform. Nobody gave me a spec for the audit, so I read the whole codebase and decided what mattered most.

The problem

A trading system acts on money, so its idea of the world has to match the broker's. I audited the full codebase looking for places where the two could disagree.

The finding

Tradie could mark a position as closed before the broker had confirmed the fill. If the close order was rejected or delayed, the system would believe it was flat while the broker still held the position.

The fix

I added a CLOSING state. A position stays in CLOSING until the broker's snapshot confirms it is gone, and only then becomes CLOSED.

Position states before and after the fix Before: OPEN goes straight to CLOSED. After: OPEN goes to CLOSING, then to CLOSED once the broker confirms. Before OPEN close requested CLOSED After OPEN CLOSING broker confirms CLOSED
A position now becomes CLOSED only after the broker confirms it.

Other findings

The lesson

The system should never report a state the broker hasn't confirmed. I check that with tests, and by reconciling Tradie's positions against the broker's data.

View the Tradie repository