Currency Converter

Currency Converter Screenshot

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
Enter an amount and select currencies to see the conversion result
Date
Exchange Rate

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:

Currency Converter Interface

Technical Implementation

The Currency Converter is built with Python and leverages several key libraries:

Core Components

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() # Raise an HTTPError for bad responses 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) # Exponential backoff with a max delay of 60 seconds if attempt < retries - 1: time.sleep(delay) # Wait before retrying 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

  1. Enter the amount you want to convert in the "Amount" field
  2. Select the currency to convert from using the "From Currency" dropdown
  3. Select the currency to convert to using the "To Currency" dropdown
  4. Optionally, select a specific date to get historical exchange rates
  5. Click the "Convert" button to perform the conversion
  6. 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:

Back to Projects