Skip to content

Unusual exchange rates that are actually incorrect #107

Open

Description

@DanilZherebtsov

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

Activity

  1. uwesimm commented on Feb 18, 2022

    @uwesimm

    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

  2. ashwin31 commented on Aug 7, 2022

    @ashwin31
    Member

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

  3. ashwin31 commented on Aug 7, 2022

    @ashwin31
    Member

    @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.

  4. portikCoder commented on Apr 22, 2023

    @portikCoder

    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:

    • https://theforexapi.com/api/2022-04-04?base=EUR: it returns actually "RON":4.9432 (the closes to the reality)
    • https://api.exchangeratesapi.io/ API which returns "rate": 4.942597,
      and the latter is much closer to the correct result compared to this Python lib (while not the most precise one): to validate all I've looked up on https://www.exchangerates.org.uk/EUR-RON-spot-exchange-rates-history-2022.html and it returns €1 EUR = lei4.9435

    CAVEAT: lei == RON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions