Currency Converter
Project Overview
This Currency Converter is a comprehensive Python application that provides real-time and historical currency exchange rates. Built with a user-friendly Tkinter interface, the app enables users to convert between different currencies, visualize historical exchange rate trends through interactive graphs, and efficiently manages API requests through a smart caching system.
Interactive Demo
Try out a simplified version of the Currency Converter below. You can convert between currencies and see historical exchange rate trends.
Currency Conversion
Exchange Rate Graph
Features
Real-time Exchange Rates
Fetches the latest exchange rates from a reliable API for up-to-date currency conversions.
Historical Data
Access exchange rates from specific dates to compare historical currency values.
Trend Visualization
Plot exchange rate trends over custom date ranges to identify patterns and make informed decisions.
Smart Caching
Implements a caching system to store previously fetched rates, reducing API calls and improving performance.
Multiple Currencies
Support for a wide range of international currencies with ISO 4217 standard codes.
Exponential Backoff
Implements exponential backoff strategy for handling API rate limits and ensuring reliable data retrieval.
Application Interface
The Currency Converter provides a clean, intuitive interface for performing conversions and visualizing exchange rate trends:
Technical Implementation
The Currency Converter is built with Python and leverages several key libraries:
Core Components
- requests: For making HTTP requests to the exchange rate API
- matplotlib: For generating visual charts of historical exchange rates
- Tkinter: For creating the graphical user interface
- tkcalendar: For providing date picker widgets
- json: For managing the exchange rate cache data
Key Functions
The application implements several important functions for currency conversion:
def get_exchange_rate(api_key, from_currency, date=None, retries=5, delay=10):
cache = load_cache()
cache_key = f"{from_currency}_{date}"
if cache_key in cache:
return cache[cache_key]
if date:
url = f"https://api.apilayer.com/exchangerates_data/{date}?base={from_currency}"
else:
url = f"https://api.apilayer.com/exchangerates_data/latest?base={from_currency}"
headers = {
'apikey': api_key
}
for attempt in range(retries):
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
rates = data.get('rates')
cache[cache_key] = rates
save_cache(cache)
return rates
except requests.exceptions.RequestException as e:
logging.error(f"Error fetching exchange rates: {e}")
if response.status_code == 429:
delay = min(delay * 2, 60)
if attempt < retries - 1:
time.sleep(delay)
else:
return None
The plotting functionality generates visual representations of exchange rate trends:
def plot_exchange_rate(api_key, from_currency, to_currency, start_date, end_date):
dates = []
rates = []
current_date = start_date
while current_date <= end_date:
rate = get_exchange_rate(api_key, from_currency, current_date)
if rate and to_currency in rate:
dates.append(current_date)
rates.append(rate[to_currency])
current_date += timedelta(days=1)
plt.figure(figsize=(10, 5))
plt.plot(dates, rates, marker='o')
plt.title(f'Exchange Rate from {from_currency} to {to_currency}')
plt.xlabel('Date')
plt.ylabel(f'Exchange Rate ({to_currency})')
plt.grid(True)
plt.show()
How to Use
- Enter the amount you want to convert in the "Amount" field
- Select the currency to convert from using the "From Currency" dropdown
- Select the currency to convert to using the "To Currency" dropdown
- Optionally, select a specific date to get historical exchange rates
- Click the "Convert" button to perform the conversion
- To visualize exchange rate trends:
- Select the currencies to compare
- Choose a date range for the graph
- Click "Plot Exchange Rate" to generate the graph
Advanced Features
The Currency Converter implements several advanced features for optimal performance and user experience:
- API Cache: Stores previously fetched exchange rates in a local cache file to minimize API requests
- Date Range Validation: Ensures that selected dates are valid and within available historical data ranges
- Error Handling: Robust error handling for API failures, network issues, and input validation
- Rate Limiting: Implements exponential backoff to handle API rate limits gracefully
- Progress Indicators: Visual feedback during API requests and data processing
Back to Projects