Tor.Fixer.Client
1.0.1
dotnet add package Tor.Fixer.Client --version 1.0.1
NuGet\Install-Package Tor.Fixer.Client -Version 1.0.1
<PackageReference Include="Tor.Fixer.Client" Version="1.0.1" />
<PackageVersion Include="Tor.Fixer.Client" Version="1.0.1" />
<PackageReference Include="Tor.Fixer.Client" />
paket add Tor.Fixer.Client --version 1.0.1
#r "nuget: Tor.Fixer.Client, 1.0.1"
#addin nuget:?package=Tor.Fixer.Client&version=1.0.1
#tool nuget:?package=Tor.Fixer.Client&version=1.0.1
Tor.Fixer.Client
A C# client library for Fixer.io API with dependency injection support.
Installation
Install-Package Tor.Fixer.Client
Usage
Registering to .NET Core service collection
You have to register the FixerClient with the dependencies in the Program.cs file.
For the minimal registration, you have to add your Fixer.io API key to the options builder:
services.AddFixer(options =>
{
options.WithApiKey("Your API key");
});
Options
Setting the API key:
services.AddFixer(options =>
{
options.WithApiKey("Your Fixer.io 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 FixerApiKey { get; set; } = "Your Fixer.io API key";
}
services.AddFixer(options =>
{
options.WithApiKeyFactory(() => SharedData.FixerApiKey);
});
If you use an alias accessing Fixer.io or the Fixer.io base address changes and this package is not updated yet, you can override the base address:
services.AddFixer(options =>
{
options.WithBaseUrl("Your URL");
});
Based on your design, you can choose a http error handling mode with the following code:
services.AddFixer(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.
IFixerClient usage
You can get the IFixerClient via dependency injection:
public class MyService
{
public MyService(IFixerClient 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 FixerResponse<TResult> class:
public class FixerResponse<TResult>
{
public bool Success { get; set; }
public TResult Result { get; set; }
public FixerError Error { get; set; }
}
- When the request succeed
- Success: true
- Error: null
- Result: object
- When the request failed
- Success: false
- Error: object
- Result: null
IFixerClient.GetSymbolsAsync method
No method parameters.
Response:
Property | Description |
---|---|
Code | Three letter currency code |
Name | The name of the currency |
IFixerClient.GetLatestRatesAsync method
Method parameters:
Parameter | Description | Optional / Required |
---|---|---|
baseCurrencyCode | Three letter base currency code | Optional |
destinationCurrencyCodes | The codes of the expected result destination currencies | Optional |
Response:
Property | Description |
---|---|
BaseCurrencyCode | Three letter base 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 |
IFixerClient.GetHistoricalRatesAsync method
Method parameters:
Parameter | Description | Optional / Required |
---|---|---|
date | A date in the past for which historical rates are requested | Required |
baseCurrencyCode | Three letter base currency code | Optional |
destinationCurrencyCodes | The codes of the expected result destination currencies | Optional |
Response:
Property | Description |
---|---|
Historical | true / false |
BaseCurrencyCode | Three letter base 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 |
IFixerClient.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 |
---|---|
Historical | true / false |
Date | The date of the data |
Result | The converted amount |
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 |
IFixerClient.GetTimeSeriesAsync 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 |
---|---|
TimeSeries | true / false |
StartDate | The start date |
EndDate | The end date |
BaseCurrencyCode | Three letter base currency code |
Items | Exchange rate list |
Items → Date | Date of the exchanges |
Items → Rates → CurrencyCode | Three letter currency code |
Items → Rates → ExchangeRate | Exchange rate |
IFixerClient.GetFluctuationAsync 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 |
---|---|
Fluctuation | true / false |
StartDate | The start date |
EndDate | The end date |
BaseCurrencyCode | Three letter base 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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.