Market Data & Web Scraping
Beginner
Automated Multi-Currency Forex Rate Converter & Historical Logger in Python
Fetch live USD, INR, EUR, GBP, and AED foreign exchange rates in Python using open JSON endpoints and convert multi-currency invoice CSVs.
#requests#pandas
Problem Statement
Freelancers, exporters, and global SaaS founders need automated USD/EUR/GBP to INR conversion for tax and accounting reconciliation. This script fetches live spot rates and converts invoice amounts.
Formula / Core Logic
Amount_Target = Amount_Base * Spot_Rate(Base -> Target)
Installation
pip install requests pandas
forex-exchange-rate-live-api-fetcher-python.py
import requests
import pandas as pd
def convert_currency_dataframe(df, amount_col='Amount_USD', base='USD', target='INR'):
url = f'https://open.er-api.com/v6/latest/{base}'
data = requests.get(url, timeout=10).json()
rate = data['rates'][target]
df = df.copy()
df[f'Rate_{base}_{target}'] = rate
df[f'Converted_{target}'] = (df[amount_col] * rate).round(2)
return df
if __name__ == '__main__':
sample = pd.DataFrame({'Invoice_ID': ['INV-01', 'INV-02'], 'Amount_USD': [250.0, 1200.0]})
print(convert_currency_dataframe(sample))
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: Does this Forex API require an API key?
No, the `open.er-api.com` v6 endpoint provides daily reference rates without registration or API keys.