Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting wrong values for conversion rate EUR to USD and GBP to USD using forex_python package #145

Open
sabeonunes opened this issue Sep 12, 2023 · 3 comments

Comments

@sabeonunes
Copy link

I have written a python script for converting EUR to USD and GBP to USD based on today's value using python package forex_python, but I am getting incorrect conversion rates for both.

Here is my code -

from forex_python.converter import CurrencyRates
from datetime import datetime

Get the current date in the format "YYYY-MM-DD"

current_date = datetime.now().strftime("%Y-%m-%d")

Define the currency pairs

from_currency = 'GBP'
to_currency_usd = 'USD'
to_currency_eur = 'EUR'

Initialize the CurrencyRates object

c = CurrencyRates()

Fetch the exchange rates for today

y = c.get_rate(from_currency, to_currency_usd)
z = c.get_rate(to_currency_eur, to_currency_usd)

I am getting EUR to USD as 0.27 whereas today's value is 1.07
I am getting GBP to USD as 1.27 whereas today's value is 1.25

Any solution for it?

@Daviid-P
Copy link

Daviid-P commented Sep 12, 2023

It's broken?

from forex_python.converter import CurrencyRates
from datetime import datetime

# Get the current date in the format "YYYY-MM-DD"
current_date = datetime.now().strftime("%Y-%m-%d")

# Define the currency pairs
from_currency = 'GBP'
to_currency_usd = 'USD'
to_currency_eur = 'EUR'

# Initialize the CurrencyRates object
cr = CurrencyRates()

# Fetch the exchange rates for today
rates = cr.get_rates('EUR') # same as https://theforexapi.com/api/latest?base=EUR
eur_to_usd = cr.get_rate('EUR', 'USD') # same as https://theforexapi.com/api/latest?base=EUR&symbols=USD (Seems to be broken, shows rates for ILS)

print(rates)
print(eur_to_usd)

https://theforexapi.com/api/latest?base=EUR&symbols=USD returns ILS (Israeli new shekel) as base


{
  "_id": "6467476f7730823eedeb6748",
  "date": "2023-05-18",
  "base": "ILS",
  "rates": {
    "EUR": 0.25413606444890596,
    "USD": 0.274797326488602,
    "JPY": 37.886604488042906,
    "BGN": 0.49703931484917024,
    "CZK": 6.01870441434344,
    "DKK": 1.8927291671961168,
    "GBP": 0.2208188263996544,
    "HUF": 95.01385041551247,
    "PLN": 1.1545401407913798,
    "RON": 1.2632595491626217,
    "SEK": 2.887214414597576,
    "CHF": 0.24740145874100997,
    "ISK": 38.50161376400925,
    "NOK": 2.982794988436809,
    "TRY": 5.437596889374571,
    "AUD": 0.41386058095504336,
    "BRL": 1.3624742687234745,
    "CAD": 0.3702254186891662,
    "CNY": 1.9310020585021221,
    "HKD": 2.15100764949554,
    "IDR": 4088.8917126229385,
    "ILS": 1,
    "INR": 22.692190398739484,
    "KRW": 366.4819944598338,
    "MXN": 4.865689089938754,
    "MYR": 1.2466136369412184,
    "NZD": 0.4402399044448398,
    "PHP": 15.330503951815801,
    "SGD": 0.3696154921344888,
    "THB": 9.432514168085593,
    "ZAR": 5.329055376248443
  }
}

Wrong date too, maybe a hacker manipulating the market!! Puts on tinfoil hat

https://stackoverflow.com/a/77087186/5640517

@sabeonunes
Copy link
Author

Still has the same values for me. No change

@Daviid-P
Copy link

Still has the same values for me. No change

This is not something the creator of the package can fix, it's TheForexAPI's problem apiforfun/theforexapi#18 if anything MicroPyramid could just add a warning or return NULL until this is fixed so people who might have automations around this don't possibly lose money.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants