Glosten-Milgrom, Critical Daily-Loss Breaker Fix and Sidebar Cleanup
Audit / Issue Found
A real-world side-panel screenshot of the Glosten-Milgrom strategy showed Total PnL of zero and Today PnL of zero while the same panel showed a realized loss of fourteen thousand two hundred fifty-three quote currency, on eighty percent exposure, with the daily-loss circuit breaker still off. The cause was a dual-tier profit-and-loss accounting setup where a newer cost-basis-equity detector updated only the new realized fields, while the older legacy fields stayed at zero. The safety code that decides when to trip the daily-loss breaker reads the legacy field, so the breaker was effectively asleep at the wheel and the bot kept trading while bleeding through any configured daily loss cap.
Before the patch
The strategy maintained two parallel sets of profit-and-loss counters. A newer pair of fields, called realized profit and daily realized profit, was updated by the cost-basis-equity detector on every confirmed fill, fees included. An older pair of fields, called total profit and daily profit, was only updated by the emergency stop-loss block, which rarely or never fires while the strategy is making spread in normal operation. The daily-loss circuit breaker compared the older daily-profit field against a configured threshold of two percent of allocated capital, but because that field was stuck at zero, the breaker never fired even when the strategy was bleeding badly. The side panel also showed both pairs of fields under different labels, with the new pair showing the real number and the old pair showing zero, which was confusing for the operator.
In addition to the breaker safety failure, the emergency stop-loss path bumped the legacy fields directly, while the cost-basis-equity detector also booked the same fill on the next cycle, which would have double-counted any stop-loss exit if the legacy fields were being used at all.
After the patch
The cost-basis-equity detector is now the single source of truth for all profit-and-loss accounting. On every confirmed fill, it updates both the new realized fields and the older total profit and daily profit fields, with the same delta. The daily-loss circuit breaker now reads a field that is being kept current, so it will fire when daily losses cross two percent of allocated capital, exactly as the safety design intended.
The emergency stop-loss block no longer bumps profit, daily profit, win count, or loss count directly. Those fields are now booked by the detector on the next cycle when it observes the inventory drop, which avoids the previous double-count. The trade count is still bumped at the stop-loss site so the panel reflects the action immediately. The break-even guard flag, which was previously reset inside the stop-loss block, is reset at the start of every cycle elsewhere, so removing the manual reset is safe.
A one-shot backfill runs once on the first cycle after this fix lands. If the strategy already accumulated a non-zero realized profit under the buggy dual-tier code, that figure is copied into the legacy total profit field so the historical loss is not silently reset to zero on restart. A warning is logged when the backfill fires so the operator can see it happen.
The side panel was simplified. The four contradictory rows (Realized (net), Today realized, Total PnL (legacy), Today PnL) have been collapsed into two clean rows: Total PnL and Today PnL, both pulling from the authoritative cost-basis-equity detector. The new tooltips state explicitly that this is the single source-of-truth number and that the daily one drives the circuit breaker.
The win and loss counters are now also bumped by the detector on every sell fill, so the W/L panel reflects spread captures and adverse selections rather than stop-loss-only events.
Bottom line
The daily-loss circuit breaker will now actually fire when the strategy crosses its configured daily loss cap. The side panel shows one consistent set of profit-and-loss numbers instead of four contradictory rows. The realized loss accumulated under the previous buggy code is preserved on restart instead of being silently zeroed.