Skip to content

fix(trading212): normalize GBX/ZAc/ILA fractional currencies#159

Merged
GeiserX merged 1 commit into
mainfrom
fix/trading212-gbx-normalization
May 11, 2026
Merged

fix(trading212): normalize GBX/ZAc/ILA fractional currencies#159
GeiserX merged 1 commit into
mainfrom
fix/trading212-gbx-normalization

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented May 11, 2026

Summary

  • Trading 212 reports UK stock prices in GBX (pence), not GBP
  • The ECB only publishes GBP rates, so getEcbRate("GBX", ...) fails
  • Parser now normalizes fractional currencies (GBX→GBP, ZAc→ZAR, ILA→ILS) and divides amounts by 100
  • Applies to trade prices, proceeds, dividends, and withholding tax amounts

Closes #86

Test plan

  • GBX buy normalized to GBP with price ÷100
  • GBX sell proceeds normalized to GBP ÷100
  • GBX dividends normalized to GBP ÷100
  • GBX withholding tax normalized to GBP ÷100
  • Actual GBP prices are NOT divided (guard against false positive)
  • All 1015 existing tests pass

Summary by CodeRabbit

  • Bug Fixes
    • Trading 212 imports now normalize fractional currencies (GBX, ZAc, ILA) to their standard equivalents (GBP, ZAR, ILS) with appropriate amount conversions for trades, dividends, and withholding tax.

Review Change Stack

…(÷100)

Trading 212 reports prices in GBX (pence) for UK stocks. The ECB only
publishes GBP rates, so the parser must normalize GBX→GBP and divide
amounts by 100. Also handles ZAc→ZAR and ILA→ILS.

Closes #86
@GeiserX GeiserX merged commit 71d2676 into main May 11, 2026
2 of 3 checks passed
@GeiserX GeiserX deleted the fix/trading212-gbx-normalization branch May 11, 2026 10:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dbabe86a-365c-45c5-98f7-a1df9a78ba17

📥 Commits

Reviewing files that changed from the base of the PR and between a896b39 and 6a8b29a.

📒 Files selected for processing (2)
  • src/parsers/trading212.ts
  • tests/parsers/trading212.test.ts

📝 Walkthrough

Walkthrough

The Trading 212 parser gains support for fractional currencies by normalizing GBX/ZAc/ILA codes to GBP/ZAR/ILS and scaling amounts by 100 during parsing and calculation.

Changes

Fractional Currency Normalization

Layer / File(s) Summary
Currency Mapping
src/parsers/trading212.ts
FRACTIONAL_CURRENCIES map and normalizeCurrency() helper convert GBX/ZAc/ILA to GBP/ZAR/ILS with divisor 100; other currencies return divisor 1.
Currency Resolution
src/parsers/trading212.ts
parseTrading212Csv resolves priceDivisor and cashDivisor by normalizing the price and cash currencies from CSV columns.
Cash Transaction Scaling
src/parsers/trading212.ts
Withholding tax, dividend, and interest-on-cash amounts are computed by dividing absolute Total by cashDivisor.
Trade Normalization
src/parsers/trading212.ts
Buy/sell trade priceDec and totalDec are divided by their respective divisors before gross/cost/proceeds calculations.
Test Coverage
tests/parsers/trading212.test.ts
New test suite verifies GBX amounts are divided by 100 for prices, proceeds, dividends, and withholding tax; confirms GBP amounts are not further divided.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • GeiserX/DeclaRenta#146: Main Trading 212 parser addition; this PR extends it with fractional-currency normalization for GBX/ZAc/ILA codes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/trading212-gbx-normalization

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.64%. Comparing base (8f6bef2) to head (6a8b29a).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #159   +/-   ##
=======================================
  Coverage   97.63%   97.64%           
=======================================
  Files          38       38           
  Lines        7622     7637   +15     
  Branches     1549     1552    +3     
=======================================
+ Hits         7442     7457   +15     
  Misses        179      179           
  Partials        1        1           
Files with missing lines Coverage Δ
src/parsers/trading212.ts 97.71% <100.00%> (+0.16%) ⬆️
🚀 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.

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.

✨ Add support for Trading 212 CSV export

1 participant