Prerequisites
Before you begin, make sure you have:- Docker and Docker Compose installed
- API keys from the following providers (all have free tiers):
The API aggregates rates from all three providers for accuracy, so you’ll need keys for each one.
Installation
Configure environment variables
Copy the example environment file and add your API keys:Edit
docker/.env with your API credentials:docker/.env
Start the services
Launch all services using Docker Compose:This command will:
- Start PostgreSQL database
- Start Redis cache
- Create database tables
- Initialize supported currencies from providers
- Start the FastAPI server on port 8000
Verify the installation
Check that the API is running by opening the interactive documentation:You should see the Swagger UI interface in your browser at http://localhost:8000/docs
Make your first API call
Now that the API is running, let’s convert some currency.Convert currency
Convert 100 USD to EUR using the path parameter format:Get exchange rate
Fetch the current exchange rate between two currencies:Response
List supported currencies
Get all available currency codes:Response
The API only supports currencies that are available across all three providers. This ensures consistent results.
Understanding the response
The conversion response includes several important fields:| Field | Description |
|---|---|
from_currency | The source currency code (ISO 4217) |
to_currency | The target currency code |
original_amount | The amount you requested to convert |
converted_amount | The result after applying the exchange rate |
exchange_rate | The averaged rate used for conversion |
timestamp | When the rate was fetched (ISO 8601) |
source | Provider information (typically “averaged”) |
How it works
Under the hood, your request triggers the following flow:Provider aggregation
If not cached, the API fetches rates from all three providers in parallel:
- Fixer.io
- OpenExchangeRates
- CurrencyAPI
Rate averaging
Successful responses are averaged together. If one provider fails, the others are used.
Caching and persistence
The averaged rate is:
- Cached in Redis (5 minute TTL)
- Stored in PostgreSQL for historical tracking
Subsequent requests for the same currency pair within 5 minutes will be served from cache instantly.
Next steps
Now that you have the API running, explore these topics:- Learn about the architecture and design decisions
- View detailed API reference documentation
- Understand error handling patterns
- Explore caching strategies for optimization
Troubleshooting
Port already in use
If port 8000 is already in use, modify the port mapping indocker/docker-compose.yml or stop the conflicting service.
Provider errors at startup
If you seeProviderError during startup:
- Verify your API keys are correct in
docker/.env - Check that all three provider APIs are accessible from your network
- Ensure you haven’t exceeded free tier rate limits
Database connection errors
If PostgreSQL fails to connect:- Ensure Docker Compose started all services successfully
- Check that port 5432 is not blocked by another PostgreSQL instance
- Review Docker logs:
docker-compose -f docker/docker-compose.yml logs db
