This is a currency converter that uses historical rates against a reference currency (Euro).
The default source is the European Central Bank. This is the ECB historical rates for 42 currencies against the Euro since 1999. It can be downloaded here: eurofxref-hist.zip. The converter can use different sources as long as the format is the same.
You can install directly after cloning:
Or use the Python package:
After installation, you should have currency_converter
in your $PATH
:
Example:
Convert from EUR to USD:
Default target currency is EUR:
Change reference date for rate:
Get a rate:
Fallback mode on not supported dates:
Sometimes rates are missing:
But we also have a fallback mode for those:
>>> c = CurrencyConverter(fallback_on_wrong_date=True,
... fallback_on_missing_rate=True,
... verbose=True)
>>> c.convert(100, 'BGN', date=datetime(1999, 11, 10))
/!\ Missing rate for BGN, fallback to 2000-07-19
51.36...
>>> c.convert(100, 'BGN', 'EUR', date=datetime(1980, 1, 1))
/!\ Invalid date (currency was BGN), fallback to 1999-01-04
/!\ Missing rate for BGN, fallback to 2000-07-19
/!\ Invalid date (currency was EUR), fallback to 1999-01-04
51.36...
Other public members:
Error cases: