Skip to content

Support the current Trading 212 export and read dates in UK time - #1000

Merged
KapJI merged 3 commits into
cgt-calc:mainfrom
casperdcl:fix-trading212
Aug 25, 2026
Merged

KapJI merged 3 commits into
cgt-calc:mainfrom
casperdcl:fix-trading212

Conversation

@casperdcl

@casperdcl casperdcl commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Haven't bothered updating tests, but seems like the format needs updating (at least as per exports today).

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.10%. Comparing base (5ea4cc2) to head (b43633b).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1000      +/-   ##
==========================================
+ Coverage   94.07%   94.10%   +0.02%     
==========================================
  Files          37       37              
  Lines        4847     4867      +20     
  Branches      800      804       +4     
==========================================
+ Hits         4560     4580      +20     
  Misses        149      149              
  Partials      138      138              
Flag Coverage Δ
docker 93.85% <100.00%> (+0.02%) ⬆️
python-3.12-macos-latest 93.61% <100.00%> (+0.02%) ⬆️
python-3.12-ubuntu-latest 93.61% <100.00%> (+0.02%) ⬆️
python-3.12-windows-latest 93.65% <100.00%> (+0.02%) ⬆️
python-3.13-ubuntu-latest 93.61% <100.00%> (+0.02%) ⬆️
python-3.14-ubuntu-latest 93.58% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Core calculation 94.81% <100.00%> (+<0.01%) ⬆️
Broker parsers 93.60% <100.00%> (+0.04%) ⬆️
ERI importers 96.48% <ø> (ø)
Files with missing lines Coverage Δ
cgt_calc/const.py 100.00% <100.00%> (ø)
cgt_calc/parsers/trading212.py 93.96% <100.00%> (+0.50%) ⬆️

Comment thread cgt_calc/parsers/trading212.py Outdated
Comment thread cgt_calc/parsers/trading212.py Outdated
@KapJI

KapJI commented Aug 25, 2026

Copy link
Copy Markdown
Member

Thanks! I can review it and fix tests later.

Just to confirm: these changes are coming from your recent export?

In the meantime, please take a look at tqdm/shtab#256 🙂

@casperdcl

casperdcl commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Tested manually today, yes.

Also, while we're off-topic: https://github.com/KapJI/capital-gains-calculator/blob/0adf60ce8f83600c6cf8ef5f90564724fccd78fc/cgt_calc/isin_converter.py#L106 was annoying. Can it be a warning instead of an exception? Or perhaps at least have some common aliases built in to suppress the error?

ISIN,symbol
US67066G1040,NVD,NVDA
US11135F1012,1YD,AVGO

@vmartinv vmartinv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this change would break the previous format. Can you make the change backwards compatible?

casperdcl and others added 2 commits August 25, 2026 18:05
Recent exports renamed the Time column to "Time (UTC)", but older
exports still use "Time" and a directory is expected to hold several
years of them, so accept both spellings.

Parse timestamps with fromisoformat so whole seconds, milliseconds and
a zone designator all work, and an unparsable value still raises a
ParsingError with the row instead of being silently truncated.

The spurious dividend price warning comes from withholding tax: the
Total is net of it while the Price per Share stays gross. Add the tax
back for the consistency check only. It is not a dealing cost, so it
never reaches the reported fees.
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

📖 Docs preview: https://pr-1000.cgt-calc.pages.dev

Built from b43633b · updated 2026-08-25 21:27 BST

Comment thread cgt_calc/parsers/trading212.py Outdated
@KapJI KapJI changed the title fix trading212 import Support the current Trading 212 export and read dates in UK time Aug 25, 2026
@KapJI KapJI added the bug Something isn't working label Aug 25, 2026
The tax year boundary and the same-day and 30-day matching rules run on
UK calendar days, and 5 April always falls inside BST. Taking the date
straight from the UTC instant put anything stamped after 23:00 UTC on
5 April in the previous tax year.

Keep the instant in UTC for ordering and derive the date in
Europe/London. zoneinfo needs tzdata where the OS ships no tz database.
@KapJI
KapJI dismissed vmartinv’s stale review August 25, 2026 20:35

Old format is supported now

@KapJI
KapJI merged commit 6e7019e into cgt-calc:main Aug 25, 2026
16 checks passed
kodiakhq Bot pushed a commit that referenced this pull request Aug 26, 2026
The Freetrade export timestamps every transaction in UTC, and the parser
took the calendar date straight from that instant. The tax year boundary
and the same-day and 30-day matching rules run on UK calendar days, and
5 April always falls inside BST, so anything stamped after 23:00 UTC on
5 April was filed in the previous tax year.

Convert to Europe/London before taking the date, the same way Trading
212 does since #1000. A zone-less timestamp is read as UTC rather than
as the machine's local time, so the parsed date does not depend on where
the calculation is run.

Document the behaviour on the Freetrade page. The date-only exports
(Schwab, Interactive Brokers, Hargreaves Lansdown, Vanguard, Morgan
Stanley, Sharesight and RAW) carry no time to convert, so say so once on
the brokers index rather than on each page.

Co-authored-by: Martín Villagra <mvillagra0@gmail.com>
@casperdcl
casperdcl deleted the fix-trading212 branch September 1, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants