XeRateProvider Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Xe.dll
- Package
- Bodu.Financial.ExchangeRates.Xe 0.7.1 (not published on nuget.org)
- Source
- XeRateProvider.cs
Serves XE.com exchange rates as ExchangeRate values, implementing the Bodu.Financial provider contracts over the XE charting-rates JSON service.
public sealed class XeRateProvider : PairWebRateProvider<XeSeriesInfo>, IDatedRateProvider, IRateProvider, IPairRateLoader, IHistoricalRateProvider, IDisposable
- Inheritance
-
XeRateProvider
- Implements
- Inherited Members
- Extension Methods
Examples
using var xe = new XeRateProvider(new XeRateProviderOptions());
await xe.LoadPairAsync("AUD", "USD", new DateOnly(2023, 1, 1), new DateOnly(2023, 1, 31));
RateLookupResult usd = xe.GetRate("AUD", "USD", 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 XE identity and the XE-specific exception text. XE serves arbitrary pairs through its charting-rates 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.
Authorization. The charting-rates endpoint requires an Authorization: Basic token that is
not published as a stable credential. The provider acquires it automatically by scanning the script chunks the XE
website publishes for the credential, caches it, and refreshes it when the endpoint rejects it. This depends on the
XE website's current structure and is inherently brittle.
Reliability - best-effort, not for production-critical sourcing. Because the provider reconstructs lazy-loaded script-chunk URLs from an unversioned public page to recover the token, any change to the XE website's markup or bundling can silently degrade it to empty results - a broken scraper is not distinguishable from "no rate for this pair" without an out-of-band health check. Treat this provider as best-effort: do not depend on it as a sole source for production-critical rates. Pair it with a stable primary feed (for example the ECB, Bank of England, or RBA providers) through the aggregating provider, or gate it behind your own availability check.
HttpClient ownership. The constructor that takes only options builds and owns an HttpClient configured with the options' UserAgent and HttpTimeout, 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
XeRateProvider(XeRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the XeRateProvider class backed by an HttpClient the provider creates and owns, configured from the supplied options.
public XeRateProvider(XeRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
optionsXeRateProviderOptionsThe 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.
XeRateProvider(HttpClient, XeRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the XeRateProvider class backed by the XE endpoint, queried with the caller-supplied HTTP client. The caller owns the client's configuration and lifetime.
public XeRateProvider(HttpClient httpClient, XeRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
httpClientHttpClientThe HTTP client used to issue charting-rates and token-acquisition requests.
optionsXeRateProviderOptionsThe 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 = "XE"
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 |