Configure fallback modes for missing rates or dates
masterIf a specific rate is missing for a requested date, or if the date is outside the available currency bounds, you can enable fallback mechanisms.
Missing Rates Fallback
If a rate is missing for a date within the currency's known bounds, use fallback_on_missing_rate=True. You can choose the method via fallback_on_missing_rate_method.
- Supported methods:
"linear_interpolation"(default) and"last_known".
c = CurrencyConverter(fallback_on_missing_rate=True)
# Uses linear interpolation if the exact date rate is missing
c.convert(100, 'BGN', date=date(2010, 11, 21))Out-of-Bounds Date Fallback
If the requested date is outside the available range for a currency, use fallback_on_wrong_date=True to fall back to the closest available bound.
c = CurrencyConverter(fallback_on_wrong_date=True)
# Falls back to the earliest available date in the dataset
c.convert(100, 'EUR', 'USD', date=date(1986, 2, 2))c = CurrencyConverter(fallback_on_missing_rate=True, fallback_on_wrong_date=True)