A .NET API for retrieving currency exchange rates from the Czech National Bank (CNB).
The program for testing the currencies defined in the original repository runs on the startup of Program.cs in the development environment.
- Retrieve exchange rates for specific currency pairs
- Support for batch requests of multiple currency pairs
- Date-specific exchange rate data
- Redis caching for improved performance
- Health checks for monitoring API and dependencies
- Containerization with Docker and docker-compose
The solution follows clean architecture principles:
- Core Layer: Domain models, interfaces, and business logic
- Infrastructure Layer: External integrations (CNB, Redis cache)
- API Layer: HTTP endpoints, controllers, and configuration
- .NET 9.0 SDK
- Docker & Docker Compose
# Start the API and Redis
docker-compose up --buildThe API will be available at:
- HTTP: http://localhost:8080
# Restore packages
dotnet restore
# Run the API
cd src/ExchangeRateUpdater.Api
dotnet runThe API includes Swagger documentation available at the root URL when running in development mode.
GET /api/v1/ExchangeRate?sourceCurrency={sourceCurrency}&targetCurrency={targetCurrency}&date={date}
sourceCurrency: Source currency code (e.g., USD)targetCurrency: Target currency code (e.g., CZK)date(optional): Date in ISO-8601 format (yyyy-MM-dd)
Example:
GET /api/v1/ExchangeRate?sourceCurrency=USD&targetCurrency=CZK&date=2025-05-16
Response:
{
"sourceCurrency": "USD",
"targetCurrency": "CZK",
"rate": 22.274,
"date": "2025-05-16",
"datePublished": "2025-05-16"
}POST /api/v1/ExchangeRate/batch
Request Body:
{
"date": "2025-05-16",
"currencyPairs": [
"USD/CZK",
"EUR/CZK",
"GBP/CZK"
]
}Response:
{
"date": "2025-05-16",
"datePublished": "2025-05-16",
"rates": [
{
"sourceCurrency": "USD",
"targetCurrency": "CZK",
"rate": 22.274,
"date": "2025-05-16",
"datePublished": "2025-05-16"
},
{
"sourceCurrency": "EUR",
"targetCurrency": "CZK",
"rate": 24.930,
"date": "2025-05-16",
"datePublished": "2025-05-16"
},
{
"sourceCurrency": "GBP",
"targetCurrency": "CZK",
"rate": 29.587,
"date": "2025-05-16",
"datePublished": "2025-05-16"
}
]
}The API includes health check endpoints:
/health/live: Basic application health/health/ready: Checks dependencies (Redis, CNB API)
- Exchange rates of commonly traded currencies are declared every working day after 2:30 p.m.
- Rates are valid for the current working day and, where relevant, the following Saturday, Sunday, or public holiday.
- CNB API access example: https://www.cnb.cz/en/financial-markets/foreign-exchange-market/central-bank-exchange-rate-fixing/central-bank-exchange-rate-fixing/daily.txt?date=16.05.2025
- Date format for the CNB API is dd.MM.yyyy
To be production ready the following needs to be added:
- Use Azure Key Vault or similar for managing secrets in production
- Enable HTTPS with valid SSL certificates
- Configure proper network security groups and firewall rules
- Set up monitoring and alerting (Grafana, SlACK)
- Implement rate limiting for API endpoints
- Add a deployment pipeline (GitHub Actions, Azure DevOps)
- Deploy to a cloud service (Azure App Service, AWS Lambda, Kubernetes)