ExchangeRateConverter 1.0.2

dotnet add package ExchangeRateConverter --version 1.0.2
                    
NuGet\Install-Package ExchangeRateConverter -Version 1.0.2
                    
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="ExchangeRateConverter" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ExchangeRateConverter" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="ExchangeRateConverter" />
                    
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 ExchangeRateConverter --version 1.0.2
                    
#r "nuget: ExchangeRateConverter, 1.0.2"
                    
#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.
#:package ExchangeRateConverter@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ExchangeRateConverter&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=ExchangeRateConverter&version=1.0.2
                    
Install as a Cake Tool

ExchangeRateConverter

Basic library to retrieve currencies exchange rates base on European Central Bank.

This library store rates data when the are fetched from the website to reduce call to the website and improve the performance after the first download it's done. If data is older than 1 day then the data will be refresh.

All the tranformations that doesn't have EUR as origin or target are computed as follow:

  1. Retrieve Original currency to EUR rates
  2. Retrieve EUR to Target currency rates
  3. Compute Orinal to Target based on previous rates.

If there is no rate in a specific date the previous closest one will be returned.

Public classes

  • ExchangeRateTool (static class)
  • ExchangeRate

Basic configuration

There are some static fields that can be modified to determine where to save rates file data and how many days should check before an error is raised when a determined date does not have rate data.

  • ExchangeRateTool.DataDirectory: Determine the folder where the file data will be stored. Default: "../DefaultExchangeRateConverter".
  • ExchangeRateTool.DataFileName: Determine the data file name. Default: "ExchangeRateData.json".
  • ExchangeRateTool.DataFilePath: combination of previous fields, you can directly update this field with full path and the other ones will be updated accordingly.

ExchangeRateTool Static Class

Static class with main methods to retrieve and use exchange rates.

ExchangeRateTool.GetCurrencyRates

Description

Return a dictionary with all available rates for specific currencies

Input arguments

  • CurrencyType currencyFrom: original currency type.
  • CurrencyType currencyTo: target currency type.

Return object

Dictionary<DateTime, double>: dictionary with date as Key and Rate as value

Code Example

Dictionary<DateTime, double> jpyToIdr = ExchangeRateTool.GetCurrencyRates(CurrencyType.JPY, CurrencyType.IDR);
Console.WriteLine(jpyToIdr[new DateTime(2024, 1, 12)]);

ExchangeRateTool.GetExchangeRateAtDate

Description

Returns a rate from currencyFrom currency type to currencyTo type for specific date or the closest previous value.

Input arguments

  • CurrencyType currencyFrom: original currency type.
  • CurrencyType currencyTo: target currency type.
  • DateTime Date: date of the rate to retrieve.

Return object

double: specific exchange rate for a given date or nearest one.

Code Example

double rate = ExchangeRateTool.GetExchangeRateAtDate(CurrencyType.USD, CurrencyType.GBP, new DateTime(2024, 1, 12));
Console.WriteLine(rate);

ExchangeRateTool.ConvertAmount

Description

Return a dictionary with all available rates for specific currencies

Input arguments

  • Amount: amount to convert by exchange rate.
  • CurrencyType currencyFrom: original currency type.
  • CurrencyType currencyTo: target currency type.
  • Date: date of the rate to use in the conversion.

Return object

double: value of the converted amount.

Code Example

double newAmount = ExchangeRateTool.ConvertAmount(100, CurrencyType.EUR, CurrencyType.USD, new DateTime(2023, 06, 06));
Console.WriteLine(newAmount);

ExchangeRateTool.GetClosestRateToDate

Description

Return the closets rate to the specified rate from the provieded rates

Input arguments

  • Dictionary<DateTime, double> rates: dictionary of dates and rates to search for closest rate.
  • DateTime Date: date of the rate to retrieve.

Return object

double: specific exchange rate for a given date or nearest one.

Code Example

double rate = ExchangeRateTool.GetClosestRateToDate(ExchangeRateTool.GetCurrencyRates(CurrencyType.USD, CurrencyType.GBP), new DateTime(2024, 1, 1));
Console.WriteLine(rate);

ExchangeRate Class

Class that keeps data about exchange rates between currencies.

GetExchangeRate

Description

Return the closets rate for the current ExchangeRate object given a specific date.

Input arguments

  • DateTime Date: date of the rate to retrieve.

Return object

double: specific exchange rate for a given date or nearest one.

Code Example

ExchangeRate eurToEur = new ExchangeRate(CurrencyType.EUR, CurrencyType.EUR);
Console.WriteLine(eurToEur.Rates.Count);
Console.WriteLine(eurToEur.GetExchangeRate(DateTime.Now));

ExchangeRate eurToUsd = new ExchangeRate(CurrencyType.EUR, CurrencyType.USD);
Console.WriteLine(eurToUsd.Rates.Count);
Console.WriteLine(eurToUsd.GetExchangeRate(new DateTime(2022, 8, 31)));
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.
  • net7.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.2 193 1/16/2024
1.0.1 130 1/15/2024
1.0.0 126 1/15/2024

Improve Readme.md