alexprengere / currencyconverter

A Python currency converter using the European Central Bank data.
http://alexprengere.github.io/currencyconverter
Apache License 2.0
215 stars 59 forks source link

Data is wrong! #33

Closed AceFromSpace closed 2 years ago

AceFromSpace commented 3 years ago

Hi I compared results from yours code with this available on EBC website and there is huge difference between results.

For 'EUR-USD' I get 1.1696, but on the EBC there is 1.1569 For 'EUR-PLN' I get 4.5832, but on the EBC there is 4.61

I get results with:

>>> from currency_converter import CurrencyConverter
>>> c = CurrencyConverter()
>>> c.convert(1, 'EUR', 'USD')
1.1696
>>> c.convert(1, 'EUR', 'PLN')
4.5832
alexprengere commented 2 years ago

No, data is not wrong 😉 This is because rates change every day, and the rates used in both calculations are likely not the same. The currency converter does not query the API in real time, to avoid the overhead of the HTTP request. It uses embedded data in the library, which might not be up to date. There are more details in #18, but if you want to download the latest rates available when creating the instance:

from currency_converter import CurrencyConverter
c = CurrencyConverter('http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip')

This is explained towards the end of the README, but should probably be made more prominent.