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

Adjust to HMRC moving older exchanges rates. #446

Merged
merged 2 commits into from
Dec 13, 2023

Conversation

nihn
Copy link
Contributor

@nihn nihn commented Dec 11, 2023

Data for years prior to 2021 was moved to a different service.

Trying to run without the changes:

mateuszm@non-client-XR974FX65W capital-gains-calculator-forked % /Users/mateuszm/.local/bin/poetry run cgt-calc  --raw ../capital-gains-calculator/test2.csv --no-balance-check --no-pdflatex --year 2022
INFO: No schwab file provided
INFO: No schwab Equity Award JSON file provided
INFO: No trading212 folder provided
INFO: No mssb folder provided
INFO: No sharesight file provided
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/main.py", line 713, in init
    sys.exit(main())
             ^^^^^^
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/main.py", line 692, in main
    acquisition_list, disposal_list = calculator.convert_to_hmrc_transactions(
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/main.py", line 198, in convert_to_hmrc_transactions
    self.add_acquisition(portfolio, acquisition_list, transaction)
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/main.py", line 128, in add_acquisition
    self.converter.to_gbp_for(amount, transaction),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/currency_converter.py", line 115, in to_gbp_for
    return self.to_gbp(amount, transaction.currency, transaction.date)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/currency_converter.py", line 110, in to_gbp
    return amount / self.currency_to_gbp_rate(currency.upper(), date)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/currency_converter.py", line 101, in currency_to_gbp_rate
    self._query_hmrc_api(month_str)
  File "/Users/mateuszm/github/capital-gains-calculator-forked/cgt_calc/currency_converter.py", line 81, in _query_hmrc_api
    raise ParsingError(
cgt_calc.exceptions.ParsingError: While parsing http://www.hmrc.gov.uk/softwaredevelopers/rates/exrates-monthly-1123.xml, HMRC API returned a 504 response

After:

mateuszm@non-client-XR974FX65W capital-gains-calculator-forked % /Users/mateuszm/.local/bin/poetry run cgt-calc  --raw ../capital-gains-calculator/test2.csv --no-balance-check --no-pdflatex --year 2022
INFO: No schwab file provided
INFO: No schwab Equity Award JSON file provided
INFO: No trading212 folder provided
INFO: No mssb folder provided
INFO: No sharesight file provided
First pass completed
Final portfolio:
...

Veryfied that caching of the exchange rates works as well (ran twice):

mateuszm@non-client-XR974FX65W capital-gains-calculator-forked % /Users/mateuszm/.local/bin/poetry run cgt-calc  --raw ../capital-gains-calculator/test2.csv --no-balance-check --no-pdflatex --year 2022 --exchange-rates-file rates.csv
INFO: No schwab file provided
INFO: No schwab Equity Award JSON file provided
INFO: No trading212 folder provided
INFO: No mssb folder provided
INFO: No sharesight file provided
First pass completed
...

Also this diff starts using requests.Session to speed up things a bit.

@KapJI KapJI added the bug Something isn't working label Dec 13, 2023
@KapJI
Copy link
Owner

KapJI commented Dec 13, 2023

Thanks a lot!

@KapJI KapJI merged commit c2b9776 into KapJI:main Dec 13, 2023
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