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

Actual currency rates frozen on last release date #49

Closed Tomasz-Ch closed 11 months ago

Tomasz-Ch commented 11 months ago

I try to get actual currency rate (4.4653) for EUR/PLN, but the converter returns value 4.6343 from the date of last converter release (2023-09-28).

c = CurrencyConverter()
c.convert(1, 'EUR', 'PLN') # Actual rate should be 4.4653 according to ECB website on 2023-10-20

Using code for exact date

c = CurrencyConverter()
c.convert(1, 'EUR', 'PLN', date=datetime.date(2023, 10, 20))

the answer is RateNotFoundError: 2023-10-20 not in PLN bounds 1999-01-04/2023-09-28

alexprengere commented 11 months ago

The data is not fetched dynamically, it is bundled with every release, by design. This is explained in the README:

Note that 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. If you need the latest data, please refer to the data section.

So if need the latest data, you can fetch it, then pass it to the object. This is an example of how to do this:

import os.path as op
import urllib.request
from datetime import date

from currency_converter import ECB_URL, CurrencyConverter

filename = f"ecb_{date.today():%Y%m%d}.zip"
if not op.isfile(filename):
    urllib.request.urlretrieve(ECB_URL, filename)
c = CurrencyConverter(filename)
Tomasz-Ch commented 9 months ago

Thank you for the code example, very helpful. Works!