Tor.Currencylayer.Client 1.0.0

dotnet add package Tor.Currencylayer.Client --version 1.0.0
                    
NuGet\Install-Package Tor.Currencylayer.Client -Version 1.0.0
                    
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="Tor.Currencylayer.Client" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tor.Currencylayer.Client" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Tor.Currencylayer.Client" />
                    
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 Tor.Currencylayer.Client --version 1.0.0
                    
#r "nuget: Tor.Currencylayer.Client, 1.0.0"
                    
#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 Tor.Currencylayer.Client@1.0.0
                    
#: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=Tor.Currencylayer.Client&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Tor.Currencylayer.Client&version=1.0.0
                    
Install as a Cake Tool

Tor.Currencylayer.Client

alternate text is missing from this package README image alternate text is missing from this package README image

A C# client library for Currencylayer.com API with dependency injection support.

Installation

Install-Package Tor.Currencylayer.Client

Usage

Registering to .NET Core service collection

You have to register the CurrencylayerClient with the dependencies in the Program.cs file.

For the minimal registration, you have to add your Currencylayer API key to the options builder:

services.AddCurrencylayer(options =>
{
    options.WithApiKey("Your API key");
});
Options

Setting the API key:

services.AddCurrencylayer(options =>
{
    options.WithApiKey("Your Currencylayer API key");
});

If you want to implement some API key factory logic, f.e.: if you want to change your API key in runtime:

public static class SharedData
{
    public static string ApiKey { get; set; } = "Your Currencylayer API key";
}
services.AddCurrencylayer(options =>
{
    options.WithApiKeyFactory(() => SharedData.ApiKey);
});

If you use an alias accessing Currencylayer or the Currencylayer base address changes and this package is not updated yet, you can override the base address:

services.AddCurrencylayer(options =>
{
    options.WithBaseUrl("Your URL");
});

Based on your design, you can choose a http error handling mode with the following code:

services.AddCurrencylayer(options =>
{
    options.WithHttpErrorHandling(HttpErrorHandlingMode.ReturnsError);
});

There are two options (default: ReturnsError):

  • ReturnsError: when the http call ends with an errorcode, the error will be in the response, there will be no exceptions
  • ThrowsException: when http call ends with an errorcode, there will be an exception

Of course, you can combine these options for your needs except WithApiKey and WithApiKeyFactory.

ICurrencylayerClient usage

You can get the ICurrencylayerClient via dependency injection:

public class MyService
{
    public MyService(ICurrencylayerClient client)
    {
    }   
}

NOTE: Please note that depending on your subscription plan, certain API endpoints may or may not be available.

Response object

Every method call will return with the following CurrencylayerResponse<TResult> class:

public class CurrencylayerResponse<TResult>
{
    public bool Success { get; set; }

    public TResult Result { get; set; }

    public CurrencylayerError Error { get; set; }

    public string Terms { get; set; }

    public string Privacy { get; set; }
}
  • When the request succeed
    • Success: true
    • Error: null
    • Result: object
    • Terms: url
    • Privacy: url
  • When the request failed
    • Success: false
    • Error: object
    • Result: null
    • Terms: url / null
    • Privacy: url / null
ICurrencylayerClient.GetLatestRatesAsync method

Method parameters:

Parameter Description Optional / Required
sourceCurrencyCode Three letter source currency code Optional
destinationCurrencyCodes The codes of the expected result destination currencies Optional

Response:

Property Description
SourceCurrencyCode Three letter source currency code
Timestamp The UNIX timestamp of the data
Rates List of the exchange rates
Rates → CurrencyCode Three letter currency code
Rates → ExchangeRate Exchange rate
ICurrencylayerClient.GetHistoricalRatesAsync method

Method parameters:

Parameter Description Optional / Required
date A date in the past for which historical rates are requested Required
sourceCurrencyCode Three letter source currency code Optional
destinationCurrencyCodes The codes of the expected result destination currencies Optional

Response:

Property Description
Historical true / false
SourceCurrencyCode Three letter source currency code
Date The date of the data
Timestamp The UNIX timestamp of the data
Rates List of the exchange rates
Rates → CurrencyCode Three letter currency code
Rates → ExchangeRate Exchange rate
ICurrencylayerClient.ConvertAsync method

Method parameters:

Parameter Description Optional / Required
sourceCurrencyCode Three letter source currency code Required
destinationCurrencyCode Three letter destination currency code Required
amount Amount to exchange Required
date A date in the past for which exchange is requested Optional

Response:

Property Description
Result The converted amount
Historical true / false
Date The date of the data (null if not historical)
Query Request query info
Query → SourceCurrencyCode Three letter source currency code
Query → DestinationCurrencyCode Three letter destination currency code
Query → Amount Amount to exchange
Info Exchange info
Info → Timestamp The UNIX timestamp of the exchange rate
Info → Rate Exchange rate
ICurrencylayerClient.GetTimeFrameAsync method

Method parameters:

Parameter Description Optional / Required
startDate Start date Required
endDate End date Required
baseCurrencyCode Three letter base currency code Optional
destinationCurrencyCodes The codes of the expected result destination currencies Optional

Response:

Property Description
TimeFrame true / false
StartDate The start date
EndDate The end date
SourceCurrencyCode Three letter source currency code
Items Exchange rate list
Items → Date Date of the exchanges
Items → Rates → CurrencyCode Three letter currency code
Items → Rates → ExchangeRate Exchange rate
ICurrencylayerClient.GetChangeAsync method

Method parameters:

Parameter Description Optional / Required
startDate Start date Required
endDate End date Required
sourceCurrencyCode Three letter source currency code Optional
destinationCurrencyCodes The codes of the expected result destination currencies Optional

Response:

Property Description
Change true / false
StartDate The start date
EndDate The end date
SourceCurrencyCode Three letter source currency code
Rates Exchange fluctuation list
Rates → CurrencyCode Three letter currency code
Rates → StartRate Start date
Rates → EndRate End date
Rates → Change The change of the given currency rate between your start and end date
Rates → ChangePercentage The percentage change of the given currency rate between your start and end date
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.

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.0 109 4/4/2025