Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and fix Trading212 parser #531

Merged
merged 1 commit into from
Jun 8, 2024
Merged

Update and fix Trading212 parser #531

merged 1 commit into from
Jun 8, 2024

Conversation

vmartinv
Copy link
Collaborator

@vmartinv vmartinv commented Jun 7, 2024

This introduces a few improvements to the Trading212 parser:

  • Add support for a few new columns (keeping backward compatibility with the old format)
  • Fix a bug when calculating the fees (I was able to spot this when I compared the calculated balance vs the actual balance in my account). Trading212 rounds off the price strangely so I just added an assert that checks that the discrepancy is less than 1 cent per share.
  • Add one test with the new format
  • Added a Stock Split, this event is actually missing in csv, I had to add it manually. I asked Trading212 to include it in the export but who knows when they will fix it.

cgt_calc/parsers/trading212.py Outdated Show resolved Hide resolved
and (self.currency_foreign == "GBP" or self.exchange_rate is not None)
):
reported_price /= self.exchange_rate or Decimal("1")
assert abs(reported_price - price) < Decimal("0.01"), (
Copy link
Owner

Choose a reason for hiding this comment

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

That could be a reason why you had mismatch here.

Copy link
Collaborator Author

@vmartinv vmartinv Jun 7, 2024

Choose a reason for hiding this comment

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

The reason there's a mismatch is because trading212 rounds the price / share.
Even when checking the transaction in the UI I get this discrepancy:
Sell 24 shares at $164.01 with exchange rate 1.25229 and £4.71 fees. Trading212 total says £3138.50. However,
24*164.01/1.25229-4.71=£3138.52

I believe there might be some implicit rounding both in the csv and in the UI. Some of them I was able to fetch more decimals from the UI and updating the csv. Others are unfixable, but since is just a few cents is not that important. I set it to a warning now when the discrepancy is more than 0.015 in the share price.
Ultimately, what matters is the £££ received/sent, which is what I'm using here.

@KapJI KapJI added the bug Something isn't working label Jun 7, 2024
@KapJI
Copy link
Owner

KapJI commented Jun 8, 2024

Looks good to me, thanks!

@KapJI KapJI merged commit 83d5ff3 into KapJI:main Jun 8, 2024
3 checks passed
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.

2 participants