Improve Trade Republic sync: routing, tickers, fees, and timeline quality

Merged
NI
2mo ago
+5164-242

Summary

Consolidates Trade Republic sync fixes that previously started in #3661 (now closed) into one reviewable PR.

Event routing

  • Saveback imports as a portfolio-only trade; Round Up as portfolio trade + cash outflow, with reconciliation of stale Saveback cash entries
  • Savings-plan invoices (SAVINGS_PLAN_INVOICE_CREATED) import as portfolio trades instead of cash noise
  • Safer timeline classification: status/deleted/hidden filtering, ignored admin/legal rows, Google Pay deposits mapped correctly

Sync mechanics

  • Timeline cursor advances when pagination completes even if detail backfill remains
  • Progressive detail enrichment for incomplete trade details and for complete trades missing share price

Securities & pricing

  • Holdings resolve to exchange tickers (e.g. ISPA) instead of offline ISINs when the instrument feed provides a usable symbol
  • Historical / fully sold trade ISINs are looked up during sync (including delta syncs via stored ISINs) and rematched on re-import
  • Share price and transaction fees are parsed from timeline details and stored on Trade (fee no longer folded into per-share price)
  • Private-markets positions fall back to NAV / unit-price valuation when live tickers are missing

Test plan

  • bin/rails test test/models/trade_republic_client_test.rb test/models/trade_republic_item_importer_test.rb test/models/trade_republic_account_activities_processor_test.rb test/models/trade_republic_account_holdings_processor_test.rb
  • Re-sync Trade Republic:
    • Saveback: portfolio buy, no unprotected Saveback cash withdrawal
    • Round Up: portfolio buy + cash “Round up” outflow
    • Savings-plan executions appear as portfolio trades
    • Held ETFs show exchange tickers (ISPA/SXR8/…) not ISINs
    • Fully sold names (e.g. ABN AMRO) rematch to tickers after sync (may take more than one sync due to caps)
    • Trade with €1 fee shows share price ≈ TR app price and fee €1.00 (not total/qty)
    • Private-markets holdings keep a valuation when ticker feeds are empty
    • Google Pay inbound deposits import; “Legal documents” rows are ignored
  • Re-sync is idempotent (no duplicate trades/cash)

Closes follow-up from #3661. Related: #3475.

Summary by CodeRabbit

  • New Features
    • Trade Republic imports now enrich trades with execution details, prices, fees, dividends, symbols, and exchange information, with fallback pricing when market prices are unavailable.
    • Added support for Saveback, Round up, and savings-plan activities, plus visibility into trades awaiting details.
  • Bug Fixes
    • Improved activity filtering, event deduplication, cash-activity reconciliation, and matching securities to exchanges.
    • Added recognition for Tradegate Exchange.
  • Localization
    • Added translated labels for Round up activities and trades awaiting details.