ECB.Currency.Converter 1.0.5

dotnet add package ECB.Currency.Converter --version 1.0.5
                    
NuGet\Install-Package ECB.Currency.Converter -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ECB.Currency.Converter" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ECB.Currency.Converter" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="ECB.Currency.Converter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ECB.Currency.Converter --version 1.0.5
                    
#r "nuget: ECB.Currency.Converter, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=ECB.Currency.Converter&version=1.0.5
                    
Install ECB.Currency.Converter as a Cake Addin
#tool nuget:?package=ECB.Currency.Converter&version=1.0.5
                    
Install ECB.Currency.Converter as a Cake Tool

ECB.Currency.Converter ๐Ÿ’ฑ

NuGet version License: MIT codecov

ECB.Currency.Converter is a lightweight, reliable, and easy-to-use library for converting currencies using the official daily exchange rates published by the European Central Bank (ECB). Ideal for .NET applications that need to handle currencies without relying on paid services or API keys.


๐Ÿค” Why ECB.Currency.Converter?

Many applications need to handle different currencies or display up-to-date exchange rates. Getting this data can require paid API subscriptions or managing complex API keys.

However, for many use cases, the official daily reference rates provided for free by the European Central Bank (ECB) are sufficient and highly reliable.

ECB.Currency.Converter encapsulates the retrieval, parsing, and in-memory caching of this data, offering a simple and robust API to integrate into your .NET applications with no hassle and no cost.


๐Ÿš€ Installation

Install the package via the .NET CLI:

dotnet add package ECB.Currency.Converter

Or via the NuGet Package Manager Console:

Install-Package ECB.Currency.Converter

โœจ Features

  • โœ”๏ธ Based on official ECB exchange rates
  • ๐Ÿ” Currency amount conversion
  • ๐Ÿ“ˆ Fetch exchange rate between two currencies
  • ๐Ÿง  Automatically creates CurrencyEntity and MoneyEntity
  • ๐Ÿ—“๏ธ Retrieve last update timestamp
  • ๐Ÿ’พ In-memory cache to avoid unnecessary calls
  • โ˜‘๏ธ Asynchronous API with Result<T> for safe error handling
  • ๐Ÿงช Testable and injectable via IExchangeRateProvider
  • ๐Ÿ“ฆ No unnecessary external dependencies

๐Ÿ› ๏ธ Usage Example

Convert amount between currencies

EcbConverterClient client = new EcbConverterClient();

Result<MoneyEntity> result = await client.ConvertAsync("USD", "GBP", 100m);

if (result.IsSuccess)
    Console.WriteLine($"Result: {result.Value.Amount} {result.Value.Currency}");
else
    Console.WriteLine($"Error: {result.Error.Code} - {result.Error.Message}");

Get exchange rate

EcbConverterClient client = new EcbConverterClient();

Result<ExchangeRateEntity> rateResult = await client.GetExchangeRateAsync("USD", "EUR");

if (rateResult.IsSuccess)
    Console.WriteLine($"1 {rateResult.Value.BaseCurrency} = {rateResult.Value.Rate} {rateResult.Value.QuoteCurrency}  (Date: {rateResult.Value.Timestamp:yyyy-MM-dd})");
else
    Console.WriteLine($"Error: {rateResult.Error.Code} - {rateResult.Error.Message}");

Get last update timestamp

EcbConverterClient client = new EcbConverterClient();

DateTimeOffset? timestamp = client.GetLastRateUpdateTimestamp();

if (timestamp.HasValue)
    Console.WriteLine($"Last update: {timestamp.Value:yyyy-MM-dd HH:mm:ss}");
else
    Console.WriteLine("Last update: unknown");

๐Ÿ”„ Custom Provider Injection

You can use your own implementation of IExchangeRateProvider:

IExchangeRateProvider myProvider = new EcbRateProvider(new HttpClient());
EcbConverterClient client = new EcbConverterClient(myProvider);

๐Ÿ“œ License

Distributed under the MIT License. See the LICENSE file for more information.


๐ŸŒ Supported Currencies

This library supports conversions between any of the following currencies, using the Euro (EUR) as an internal reference base. That means you can convert from USD to JPY, GBP to AUD, and so on โ€” not just to or from EUR.

Supported currencies (as published daily by the ECB):

  • EUR (Euro)
  • USD (US Dollar)
  • JPY (Japanese Yen)
  • BGN (Bulgarian Lev)
  • CZK (Czech Koruna)
  • DKK (Danish Krone)
  • GBP (British Pound)
  • HUF (Hungarian Forint)
  • PLN (Polish Zloty)
  • RON (Romanian Leu)
  • SEK (Swedish Krona)
  • CHF (Swiss Franc)
  • ISK (Icelandic Krona)
  • NOK (Norwegian Krone)
  • TRY (Turkish Lira)
  • AUD (Australian Dollar)
  • BRL (Brazilian Real)
  • CAD (Canadian Dollar)
  • CNY (Chinese Yuan)
  • HKD (Hong Kong Dollar)
  • IDR (Indonesian Rupiah)
  • ILS (Israeli Shekel)
  • INR (Indian Rupee)
  • KRW (South Korean Won)
  • MXN (Mexican Peso)
  • MYR (Malaysian Ringgit)
  • NZD (New Zealand Dollar)
  • PHP (Philippine Peso)
  • SGD (Singapore Dollar)
  • THB (Thai Baht)
  • ZAR (South African Rand)

Note: These are the only currencies supported. All conversions are internally routed through EUR.


๐Ÿ™Œ Author

Created by Javier Angosto Barjollo


Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 135 5/8/2025
1.0.4 137 5/8/2025
1.0.3 132 5/8/2025
1.0.2 136 5/7/2025
1.0.1 131 5/7/2025
1.0.0 131 5/7/2025

**Release (v1.0.5)** 🎉

Provides a simple and reliable way to perform currency conversions and retrieve daily exchange rates using the official feed from the European Central Bank (ECB).

**Key Features:**
* Fetches daily reference rates directly from the European Central Bank (ECB).
* Supports conversion between any currencies available in the ECB feed (calculates cross-rates automatically, e.g., USD to JPY).
* Provides methods to get exchange rates (`GetExchangeRateAsync`) and convert amounts (`ConvertAsync`) via the `EcbConverterClient` class.
* Robust error handling using the Result pattern (`Result<T>`) - no unexpected exceptions for common issues like network errors, parsing errors, or invalid input.
* Built-in caching (4-hour default) to minimize requests to the ECB feed and improve performance.
* Asynchronous API (`async/await`).
* Targets .NET Standard 2.0 for broad compatibility across .NET Framework and modern .NET versions.
* Uses Value Objects (`Currency`, `Money`, `ExchangeRate`) for improved type safety and domain representation.
* Lightweight with no external runtime dependencies.

See the project README for detailed usage examples.