Keep Trade Republic cash balance intact for open orders
Merged
NI
2mo ago+26+26+01234567890123456789-6-6-0123456789
Problem
The Trade Republic importer took the cash balance from the availableCash topic when it was present. That value subtracts funds reserved for open orders, such as unfilled limit buys. Those orders haven't executed, so no money has left the account. As a result, the cash account in Sure dropped without a matching transaction and no longer matched the balance shown in Trade Republic.
Real-world example: two open limit buys (€211 and €157) made the cash balance €777.19 in Sure, while Trade Republic showed €1,145.19. On the first sync after the orders were placed, a reconciliation valuation absorbed the €368 drop.
Change
Provider::TradeRepublicClient#sync_onceno longer subscribes toavailableCashand only returns the bookedcashamount and currency.TradeRepublicItem::Importer#cash_balanceno longer readsavailable_amount.- When an order executes, the cash moves through the timeline trade event as before.
Validation
- New importer test: when the payload has a lower
available_amount, the cash balance still equals the bookedamount. bin/rails test: 10,032 runs with 1 error, which also happens without this change.RecurringTransaction::PipelineTest#test_run_with_lock!_refuses_to_stack_on_a_held_family_lockreadsconfig[:username], butdatabase.ymlsetsuser:. So whenPOSTGRES_USERdiffers from the OS user, the test connects as the wrong user.bin/rubocop,erb_lint,npm run lintandbin/brakemanall pass with no offenses or warnings.- No system tests apply (no UI change).
Notes
- Existing reconciliation valuations recorded while orders were open keep the reduced value. The next sync writes the correct current anchor.
Summary by CodeRabbit
- Bug Fixes
- Cash balances now reflect the provider’s booked cash amount rather than the lower amount available to spend. Imported cash accounts use the booked amount for both their current balance and cash balance.
- Cash balance reporting no longer includes an available-balance amount or uses its currency as a fallback when a separate available-cash currency is missing.