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?
You need to use a life Api tracker for exchange rate to get a right data, you may use Open exchange rates they have a documentation to how to use their api you can find them here Open exchange rate API
and then you can modify your code to look like this