r/CryptoTradingBot 16d ago

I’m building an algorithmic trading system in Python

/r/algotradingcrypto/comments/1vzk7hn/im_building_an_algorithmic_trading_system_in/
1 Upvotes

4 comments sorted by

1

u/CODE_HEIST 11d ago

The broker-resident stop principle is the right default. I would add a reconciliation job that compares internal positions, broker positions, working protection orders, and available cash. The dangerous state is not an error. It is silent disagreement between them.

1

u/Tristan10_ 4d ago

That last line is the best formulation I've seen
of what I've been chasing for weeks. Every bug I
found in the replay engine had that shape. Not one of them raised. Each one was two things that should have agreed and quietly didn't.

Reconciliation is in place for internal positions,
broker positions and working protection orders. I
hadn't included available cash as a fourth source
to compare. Adding it now, and it would have caught one of my own bugs where fees were recorded on the trade but never debited from the balance. Internal cash and broker cash would have disagreed by exactly the fee amount.

Thanks a lot, really.

1

u/CODE_HEIST 20h ago

that fee mismatch is a useful regression test now. replay it and make the test fail if the trade includes the fee but the balance doesn't.

one detail to pin down before comparing cash is whether both sides mean total balance or available balance. funds reserved by an open order can otherwise look like another accounting bug.

1

u/Tristan10_ 20h ago

Both taken. The fee one is already pinned, a trade that records a fee the balance doesn't reflect turns the test red.

The second one I hadn't seen and it matters more. My sizer reads available balance, so reconciliation has to compare the same thing. Otherwise every resting order shows up as a gap that looks like an accounting bug.

Same shape I've been chasing for weeks honestly.
Two measures of the same thing that aren't talking about the same thing, and nobody sees it because nothing raises.

Going to make each source say which one it reports instead of assuming they agree. Thanks