MicroPyramid / forex-python

Foreign exchange rates, Bitcoin price index and currency conversion using ratesapi.io
http://forex-python.readthedocs.io/en/latest/usage.html
MIT License
661 stars 195 forks source link

Unusual exchange rates that are actually incorrect #107

Open DanilZherebtsov opened 2 years ago

DanilZherebtsov commented 2 years ago

forex_python returns incorrect exchange rates for some dates

# example
import pandas as pd
df = pd.DataFrame({'date': ['2011-08-01 02:12:55',
                            '2011-08-23 03:14:11',
                            '2011-08-27 14:11:51',
                            '2011-09-01 06:33:21',
                            '2011-09-05 23:15:11',
                            '2011-09-06 21:19:52',
                            '2011-09-08 17:01:16',
                            '2011-09-09 14:11:17',
                            '2011-09-10 19:15:12',
                            '2011-09-15 01:52:19']})
from forex_python import CurrencyRates
c = CurrencyRates()
rates = []
for val in df['date']:
    dt = datetime.strptime(val, '%Y-%m-%d %H:%M:%S')
    rate = c.get_rate('USD', 'RUB', dt)
    rates.append(rate)

print(rates) [27.567811307665625, 28.92096528834186, 28.919594500763782, 28.990549527476368, 76.28786342123057, <--- incorrect 29.580679480814247, 26.931377115354756, 27.043069694596714, 76.15971737613398, <--- incorrect 76.15971737613398] <--- incorrect

And while we're at it, could you please comment: can I pass a list of dates to the api call? Because it takes a lot of time to make even 10 api calls. Some of my datasets have tens of thousands of rows with datetime values. It will take forever to parse them one by one as in the code above

uwesimm commented 2 years ago

actually the problem is with the underlying api itself:

uwe@air-uwe xxx % curl 'https://theforexapi.com/api/2021-06-01/?base=USD&symbols=EUR' {"date":"2021-06-01","base":"USD","rates":{"EUR":0.8179959100204499}}% uwe@air-uwe xxx % curl 'https://theforexapi.com/api/2021-06-01/?base=USD&symbols=EUR' {"date":"2022-02-04","base":"USD","rates":{"EUR":0.8722958827634333}}%

as you can see even a curl returns the wrong rate for the wrong date. so it is an issue of the underlying service

ashwin31 commented 2 years ago

@uwesimm the underlying api got fixed and returining consistent data.

ashwin31 commented 2 years ago

@DanilZherebtsov we can't post multiple dates at once. I will see how to improve performance. I will implement some caching and get back to you.

portikCoder commented 1 year ago

IMO the problem is still existing in the following form of being an outlier:

CurrencyRates().get_rate("EUR", "RON", datetime.date(2022, 4, 4)) returns 5.597789077041813, which is not correct. I've used the 2 APIs for validation:

CAVEAT: lei == RON