OfxRateProvider Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Ofx.dll
- Package
- Bodu.Financial.ExchangeRates.Ofx 0.7.1
- Source
- OfxRateProvider.cs
Serves OFX (ofx.com) exchange rates as ExchangeRate values, implementing the Bodu.Financial provider contracts over the OFX public spot-rate-history JSON REST service.
public sealed class OfxRateProvider : PairWebRateProvider<OfxSeriesInfo>, IDatedRateProvider, IRateProvider, IPairRateLoader, IHistoricalRateProvider, IDisposable
- Inheritance
-
OfxRateProvider
- Implements
- Inherited Members
- Extension Methods
Examples
using var ofx = new OfxRateProvider(new OfxRateProviderOptions());
await ofx.LoadPairAsync("USD", "AUD", new DateOnly(2023, 1, 1), new DateOnly(2023, 1, 31));
RateLookupResult aud = ofx.GetRate("USD", "AUD", new DateOnly(2023, 1, 3));
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 OFX identity and the OFX-specific exception text. OFX serves arbitrary pairs through its spot-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.
HttpClient ownership. The constructor that takes only options builds and owns an HttpClient configured with the options' UserAgent and HttpTimeout (the OFX 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
OfxRateProvider(OfxRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the OfxRateProvider class backed by an HttpClient the provider creates and owns, configured from the supplied options.
public OfxRateProvider(OfxRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
optionsOfxRateProviderOptionsThe provider options.
loggerILoggerThe logger that records downloads and on-demand network fetches. null selects a no-op logger.
timeProviderTimeProviderThe time source used to resolve the current instant for the undated lookup surface. null selects System.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- ArgumentException
Thrown when
optionsfails validation.
OfxRateProvider(HttpClient, OfxRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the OfxRateProvider class backed by the OFX endpoint, queried with the caller-supplied HTTP client. The caller owns the client's configuration and lifetime.
public OfxRateProvider(HttpClient httpClient, OfxRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
httpClientHttpClientThe HTTP client used to issue history requests.
optionsOfxRateProviderOptionsThe provider options.
loggerILoggerThe logger that records downloads and on-demand network fetches. null selects a no-op logger.
timeProviderTimeProviderThe time source used to resolve the current instant for the undated lookup surface. null selects System.
Exceptions
- ArgumentNullException
Thrown when
httpClientoroptionsis null.- ArgumentException
Thrown when
optionsfails validation.
Fields
ProviderName
The provider identifier stamped on every rate this provider produces.
public const string ProviderName = "OFX"
Field Value
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
fromIsoCodestringThe source-currency ISO code.
toIsoCodestringThe destination-currency ISO code.
dateDateOnlyThe requested date.
Returns
- string
The exception message.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |