Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexandergugel/hmrc-exchange-rates
💷 💶 💵 Download monthly exchange rates from HMRC and generate corresponding CSV files.
https://github.com/alexandergugel/hmrc-exchange-rates
csv golang tax
Last synced: about 2 months ago
JSON representation
💷 💶 💵 Download monthly exchange rates from HMRC and generate corresponding CSV files.
- Host: GitHub
- URL: https://github.com/alexandergugel/hmrc-exchange-rates
- Owner: alexanderGugel
- License: mit
- Created: 2023-05-01T12:57:18.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-04T20:41:50.000Z (about 1 year ago)
- Last Synced: 2024-10-26T12:12:18.406Z (3 months ago)
- Topics: csv, golang, tax
- Language: Go
- Homepage:
- Size: 332 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `hmrc-exchange-rates`
HMRC publishes monthly exchange rates in XML format [[Source](http://www.hmrc.gov.uk/softwaredevelopers/2023-exrates.html)]. Unfortunately, the format in which those exchange rates are published is rather unwieldy.
`hmrc-exchange-rates` downloads exchange rates from HMRC and produces a single, easy-to-use CSV file, containing monthly exchange rates for all major currencies between February 2021 and the most recent month for which HMRC has published rates.
**How is this different from the CSV files published by HMRC?**
HMRC publishes **one CSV file per month**, containing exchange rates against all major currencies [[Example](https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/1120505/exrates-monthly-1222.csv/preview)]. If you need to look up monthly exchange rates over three years, you'd need to download and normalize 12 * 3 = 36 CSV files. This is annoying.
This script produces a **single CSV** containing monthly exchange rates against **all** major currencies, starting February 2021.
The resulting CSV looks something like this:
```CSV
period_start,period_end,country_name,country_code,currency_name,currency_code,rate_new
2015-02-01,2015-02-28,Argentina,AR,Peso ,ARS,13.02
2015-02-01,2015-02-28,Australia,AU,Dollar ,AUD,1.8385
2015-02-01,2015-02-28,Austria,AT,Euro ,EUR,1.3008
2015-02-01,2015-02-28,Belgium,BE,Euro ,EUR,1.3008
2015-02-01,2015-02-28,Brazil,BR,Real ,BRL,3.9326
2015-02-01,2015-02-28,Canada,CA,Dollar,CAD,1.8251
2015-02-01,2015-02-28,Cyprus,CY,Euro ,EUR,1.3008
2015-02-01,2015-02-28,Denmark,DK,Krone ,DKK,9.664
2015-02-01,2015-02-28,Estonia,EE,Euro,EUR,1.3008
2015-02-01,2015-02-28,Finland,FI,Euro ,EUR,1.3008
2015-02-01,2015-02-28,France,FR,Euro ,EUR,1.3008
2015-02-01,2015-02-28,Germany,DE,Euro ,EUR,1.3008
[...]
2023-05-01,2023-05-31,Vanuatu,VU,Vatu ,VUV,148.3112
2023-05-01,2023-05-31,Venezuela,VE,Bolivar Fuerte ,VEF,319866.39
2023-05-01,2023-05-31,Vietnam,VN,Dong ,VND,29259.5291
2023-05-01,2023-05-31,Wallis & Futuna Islands,WF,CFP Franc ,XPF,135.5738
2023-05-01,2023-05-31,Western Samoa,WS,Tala ,WST,3.3924
2023-05-01,2023-05-31,Yemen (Rep of),YE,Rial ,YER,311.4628
2023-05-01,2023-05-31,Zambia,ZM,Kwacha ,ZMW,21.5483
2023-05-01,2023-05-31,Zimbabwe,ZW,Dollar ,ZWL,450.5671
```## Usage
Run `make all`, which will
1. build the binary,
2. download monthly exchange rates between February 2021 and the most recent month for which HMRC has published rates,
3. generate `hmrc_exchange_rates.csv`, `hmrc_exchange_rates_usd.csv`, and `hmrc_exchange_rates_eur.csv`.```sh
alexandergugel@192 hmrc-exchange-rates % make clean && make
rm -f hmrc-exchange-rates hmrc_exchange_rates.csv hmrc_exchange_rates_usd.csv hmrc_exchange_rates_eur.csv
go build
./hmrc-exchange-rates > hmrc_exchange_rates.csv
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-2.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-3.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-4.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-5.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-6.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-7.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-8.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-9.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-10.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-11.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2021-12.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-1.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-2.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-3.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-4.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-5.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-6.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-7.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-8.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-9.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-10.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-11.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-12.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-1.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-2.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-3.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-4.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-5.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-6.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-7.xml...
2024/02/04 20:40:25 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-8.xml...
2024/02/04 20:40:26 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-9.xml...
2024/02/04 20:40:26 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-10.xml...
2024/02/04 20:40:26 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-11.xml...
2024/02/04 20:40:26 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2023-12.xml...
2024/02/04 20:40:26 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2024-1.xml...
2024/02/04 20:40:26 fetching https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2024-2.xml...
awk -F ',' "NR == 1 || \$6 == \"USD\" {print}" hmrc_exchange_rates.csv > hmrc_exchange_rates_usd.csv
awk -F ',' "NR == 1 || \$6 == \"EUR\" {print}" hmrc_exchange_rates.csv > hmrc_exchange_rates_eur.csv
alexandergugel@192 hmrc-exchange-rates %
```- `hmrc_exchange_rates.csv` contains monthly exchange rates for **all** major currencies.
- `hmrc_exchange_rates_{usd,eur}.csv` are filtered versions of `hmrc_exchange_rates.csv`, only containing USD / EUR exchange rates respectively.The program requires a somewhat recent version of Go. I've tested things with go1.19.2, but older versions should work as well.
## License
This program is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.