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.
Other findings
- A confidence-scale mismatch between services, which I fixed.
- Telegram commands had no authentication, so I added chat-ID checks.
- The remaining findings went into a prioritized TODO list that I work through in order.
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.