How to get historical currency exchange rate

1k Views Asked by At

Title sums it up. I cannot use most API because they have a ratelimit and I have 50-60k values I need to retrieve from different days and currencies(it's about as many different days as requests).

I tried using from forex_python.converter import CurrencyRates

With a script that looks like that :

def get_exchange_rate(from_currency: str, date_ts: int, to_currency: str = "USD"):
    """
    This function returns the historical exchange rate between two currencies
    """
    cr = CurrencyRates()

    date = datetime.datetime.fromtimestamp(date_ts)
    rate = cr.get_rate(from_currency, to_currency, date)
    return rate

The issue is that it returns an error: forex_python.converter.RatesNotAvailableError: Currency Rates Source Not Ready and when I looked it up people were saying it's not a bug it's just that the distant server the library tries to query is not up right now.

Thanks for help

1

There are 1 best solutions below

0
Jacob On
  1. In this situation i would recommend to obtain publicly available information sources from relevant websites of financial organizations or banks and then just store the data locally, this is one way to avoid remote APIs, but i guess you want to retrieve all that from one server.
  2. One of the options i checked for you in the net is to check if the API you're using allows batch requests, if yes, it just allows you to get several rates in one API call.

I hope I helped. Good Luck !