Skip to content

fix: broker fallback from card selection + FX double-counting detection#136

Merged
GeiserX merged 3 commits into
mainfrom
fix/broker-fallback-fx-double-count
Apr 27, 2026
Merged

fix: broker fallback from card selection + FX double-counting detection#136
GeiserX merged 3 commits into
mainfrom
fix/broker-fallback-fx-double-count

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented Apr 27, 2026

Summary

  • Broker fallback: When auto-detection fails for an uploaded file, the system now tries parsers for brokers the user selected in the card grid (step 1) before showing an error. If multiple brokers were selected and only one file fails detection, the unmatched broker's parser is attempted automatically.

  • FX double-counting fix (Signal 4): Adds amount-correlation heuristic to FxFifoEngine.detectAutoConvert() for EUR-base IBKR accounts that don't export the Notes field (missing AFx marker). Detects auto-convert when CASH trade amounts match same-day securities tradeMoney within 2% — requires ≥3 CASH trades and 90%+ matched. This prevents spurious FX gains from being double-counted on top of EUR-denominated capital gains.

Test plan

  • Verify Signal 4 detects auto-convert with amount-correlated CASH/STK pairs (new test)
  • Verify Signal 4 does NOT trigger with bulk manual conversions (new test)
  • Verify Signal 4 does NOT trigger with <3 CASH trades (new test)
  • Verify existing 42 FX tests still pass (no regressions)
  • Upload a Trade Republic CSV after selecting Trade Republic in card grid — should parse via fallback even if detect() somehow misses
  • Upload an IBKR Flex Query without Notes field — FX gains should no longer be double-counted

When auto-detection fails for a file, try parsers for brokers the user
selected in the card grid before throwing an error.

Add Signal 4 to FxFifoEngine.detectAutoConvert(): amount-correlation
heuristic detects auto-convert when CASH trade amounts match same-day
securities tradeMoney within 2% (≥3 trades, 90%+ matched). Fixes
double-counted FX gains for EUR-base IBKR accounts missing Notes/AFx.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

@GeiserX has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 59 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bdb13dc9-7c72-4b04-9bcf-698712bd0541

📥 Commits

Reviewing files that changed from the base of the PR and between 029841e and 6ccc041.

📒 Files selected for processing (9)
  • src/engine/fx-fifo.ts
  • src/i18n/locales/ca.ts
  • src/i18n/locales/en.ts
  • src/i18n/locales/es.ts
  • src/i18n/locales/eu.ts
  • src/i18n/locales/gl.ts
  • src/web/broker-guides.ts
  • src/web/main.ts
  • tests/engine/fx-fifo.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/broker-fallback-fx-double-count

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

GeiserX added 2 commits April 27, 2026 18:35
Add step 5 telling users to check all field boxes in each Flex Query
section, emphasizing Notes field is critical for FX auto-convert
detection. Renumbers subsequent steps.
IBKR shows section/field names in English regardless of user locale.
Use Trades, Cash Transactions, Open Positions, Financial Instrument
Information instead of translated names that don't match the UI.
@GeiserX GeiserX merged commit 1c592ee into main Apr 27, 2026
3 checks passed
@GeiserX GeiserX deleted the fix/broker-fallback-fx-double-count branch April 27, 2026 16:40
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.76%. Comparing base (3f07d07) to head (6ccc041).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
+ Coverage   97.75%   97.76%   +0.01%     
==========================================
  Files          34       34              
  Lines        6594     6633      +39     
  Branches     1322     1335      +13     
==========================================
+ Hits         6446     6485      +39     
  Misses        147      147              
  Partials        1        1              
Files with missing lines Coverage Δ
src/engine/fx-fifo.ts 99.02% <100.00%> (+0.19%) ⬆️
src/i18n/locales/ca.ts 100.00% <100.00%> (ø)
src/i18n/locales/en.ts 100.00% <100.00%> (ø)
src/i18n/locales/es.ts 100.00% <100.00%> (ø)
src/i18n/locales/eu.ts 100.00% <100.00%> (ø)
src/i18n/locales/gl.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

GeiserX added a commit that referenced this pull request Apr 28, 2026
…on (#136)

* fix: broker fallback from card selection + FX double-counting detection

When auto-detection fails for a file, try parsers for brokers the user
selected in the card grid before throwing an error.

Add Signal 4 to FxFifoEngine.detectAutoConvert(): amount-correlation
heuristic detects auto-convert when CASH trade amounts match same-day
securities tradeMoney within 2% (≥3 trades, 90%+ matched). Fixes
double-counted FX gains for EUR-base IBKR accounts missing Notes/AFx.

* fix: update IBKR guide to recommend selecting all fields

Add step 5 telling users to check all field boxes in each Flex Query
section, emphasizing Notes field is critical for FX auto-convert
detection. Renumbers subsequent steps.

* fix: use English IBKR interface names in Flex Query guide

IBKR shows section/field names in English regardless of user locale.
Use Trades, Cash Transactions, Open Positions, Financial Instrument
Information instead of translated names that don't match the UI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant