Table of Contents

OandaRateProvider Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.ExchangeRates.Oanda.dll
Package
Bodu.Financial.ExchangeRates.Oanda 0.7.1 (not published on nuget.org)
Source
OandaRateProvider.cs

Serves OANDA (Historical Currency Converter) exchange rates as ExchangeRate values, implementing the Bodu.Financial provider contracts over the public OANDA Rates history JSON service.

public sealed class OandaRateProvider : PairWebRateProvider<OandaSeriesInfo>, IDatedRateProvider, IRateProvider, IPairRateLoader, IHistoricalRateProvider, IDisposable
Inheritance
OandaRateProvider
Implements
Inherited Members
Extension Methods

Examples

using var oanda = new OandaRateProvider(new OandaRateProviderOptions());
var today = DateOnly.FromDateTime(DateTime.UtcNow);
await oanda.LoadPairAsync("AUD", "USD", today.AddDays(-30), today);

RateLookupResult usd = oanda.GetRate("AUD", "USD", today.AddDays(-1));

Remarks

The provider derives from PairWebRateProvider<TSeries>, which supplies the per-pair coverage tracking, single-flight coalescing, fetch-and-accumulate orchestration, and diagnostic logging shared by every pair-based web source; this type contributes only the OANDA identity and the OANDA-specific exception text. OANDA serves arbitrary pairs through its rate-history endpoint, so any pair of ISO codes can be requested directly. Use LoadPairAsync(string, string, DateOnly, DateOnly, CancellationToken) to warm a pair's in-memory store.

History depth. The anonymous endpoint serves only a rolling recent window (roughly the last 180 days); requesting an earlier start date returns only what the feed publishes. The provider advertises this through HistoryAvailability, so a caller can resolve the earliest date worth requesting before issuing a lookup.

HttpClient ownership. The constructor that takes only options builds and owns an HttpClient configured with the options' UserAgent and HttpTimeout (the OANDA endpoint rejects requests without a recognizable user agent), disposing it with the provider. The constructor that takes an HttpClient uses the caller-supplied client as-is, leaving its configuration and lifetime to the caller; this is the path the dependency-injection package uses.

Constructors

OandaRateProvider(OandaRateProviderOptions, ILogger?, TimeProvider?)

Initializes a new instance of the OandaRateProvider class backed by an HttpClient the provider creates and owns, configured from the supplied options.

public OandaRateProvider(OandaRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)

Parameters

options OandaRateProviderOptions

The provider options.

logger ILogger

The logger that records downloads and on-demand network fetches. null selects a no-op logger.

timeProvider TimeProvider

The time source used to resolve the current instant for the undated lookup surface. null selects System.

Exceptions

ArgumentNullException

Thrown when options is null.

ArgumentException

Thrown when options fails validation.

OandaRateProvider(HttpClient, OandaRateProviderOptions, ILogger?, TimeProvider?)

Initializes a new instance of the OandaRateProvider class backed by the OANDA endpoint, queried with the caller-supplied HTTP client. The caller owns the client's configuration and lifetime.

public OandaRateProvider(HttpClient httpClient, OandaRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)

Parameters

httpClient HttpClient

The HTTP client used to issue history requests.

options OandaRateProviderOptions

The provider options.

logger ILogger

The logger that records downloads and on-demand network fetches. null selects a no-op logger.

timeProvider TimeProvider

The time source used to resolve the current instant for the undated lookup surface. null selects System.

Exceptions

ArgumentNullException

Thrown when httpClient or options is null.

ArgumentException

Thrown when options fails validation.

Fields

ProviderName

The provider identifier stamped on every rate this provider produces.

public const string ProviderName = "OANDA"

Field Value

string

Properties

ProviderId

Gets the provider identifier stamped on every rate this provider produces.

protected override string ProviderId { get; }

Property Value

string

The provider identifier.

Methods

FormatRateNotFound(string, string, DateOnly)

Formats the message for the KeyNotFoundException thrown when a single-rate lookup fails. Derived types may override to use a feed-specific resource string.

protected override string FormatRateNotFound(string fromIsoCode, string toIsoCode, DateOnly date)

Parameters

fromIsoCode string

The source-currency ISO code.

toIsoCode string

The destination-currency ISO code.

date DateOnly

The requested date.

Returns

string

The exception message.

Applies to

ProductVersions
.NET8, 10