RbaRateProvider Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Rba.dll
- Package
- Bodu.Financial.ExchangeRates.Rba 0.7.1
- Source
- RbaRateProvider.cs
Serves Reserve Bank of Australia historical exchange rates as ExchangeRate values, implementing the
Bodu.Financial provider contracts over data downloaded from the RBA's published .xls files.
public sealed class RbaRateProvider : WebRateProvider, IDatedRateProvider, IRateProvider, IPairRateLoader, IHistoricalRateProvider, IDisposable
- Inheritance
-
RbaRateProvider
- Implements
- Inherited Members
- Extension Methods
Examples
using var rba = new RbaRateProvider(new RbaRateProviderOptions());
await rba.LoadRangeAsync(new DateOnly(2023, 1, 1), new DateOnly(2026, 6, 30));
RateLookupResult aud = rba.GetRate("AUD", "USD", new DateOnly(2023, 1, 3));
// aud.Rate.Provider == RbaRateProvider.ProviderName; the reverse direction (USD->AUD) is inverted.
Remarks
The provider derives from WebRateProvider, which supplies the in-memory accumulator, the immutable
snapshot, the full synchronous and asynchronous lookup matrix, and ownership of the HttpClient when
this provider creates one. Loading is era-based: each era is a published .xls file covering a span of dates,
and a range load fetches every era overlapping the requested window. Use PreloadAsync(CancellationToken),
LoadEraAsync(RbaEraWorkbook, CancellationToken), or LoadRangeAsync(DateOnly, DateOnly, CancellationToken) to warm the store.
HttpClient ownership. The constructor that takes only options builds and owns an HttpClient configured from UserAgent and HttpTimeout, disposing it with the provider. The constructor that takes an HttpClient uses the caller-supplied client as-is; this is the path the dependency-injection package uses.
Logging. When an ILogger is supplied (directly or through the dependency-injection
package) the provider records: the start of an era download (Debug), a completed download
with its observation count (Information), each ingested observation (
Information), and a failed download (Warning, then re-thrown). Every
level is configurable through the corresponding *LogLevel property on RbaRateProviderOptions;
omitting the logger selects Instance, so logging is opt-in and free when unused.
Constructors
RbaRateProvider(RbaRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the RbaRateProvider class backed by an HttpClient the provider creates and owns, configured from the supplied options.
public RbaRateProvider(RbaRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
optionsRbaRateProviderOptionsThe provider options.
loggerILoggertimeProviderTimeProvider
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- ArgumentException
Thrown when
optionsfails validation.
RbaRateProvider(HttpClient, RbaRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the RbaRateProvider class backed by the RBA .xls files,
downloaded with the caller-supplied HTTP client. The caller owns the client's configuration and lifetime.
public RbaRateProvider(HttpClient httpClient, RbaRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
httpClientHttpClientThe HTTP client used to download era files.
optionsRbaRateProviderOptionsThe provider options.
loggerILoggertimeProviderTimeProvider
Exceptions
- ArgumentNullException
Thrown when
httpClientoroptionsis null.- ArgumentException
Thrown when
optionsfails validation.
Fields
BaseCurrency
The base currency the RBA quotes against.
public const CurrencyCode BaseCurrency = AUD
Field Value
ProviderName
The provider identifier stamped on every rate this provider produces.
public const string ProviderName = "RBA"
Field Value
Properties
AllowSynchronousNetworkAccess
Gets a value indicating whether a synchronous lookup may block to fetch a missing window on demand.
protected override bool AllowSynchronousNetworkAccess { get; }
Property Value
Remarks
When enabled, the synchronous getters block on the async fetch, which can deadlock if invoked on a thread carrying a captured SynchronizationContext (classic ASP.NET, a WPF/WinForms UI thread). The synchronous path guards against this by throwing InvalidOperationException when Current is non-null; enable this only for code that calls the getters from a thread-pool thread (or use the asynchronous API).
DefaultLookback
Gets the look-back window used when a single-rate lookup must fetch on demand; the provider fetches the window ending on the requested date and spanning this duration.
protected override TimeSpan DefaultLookback { get; }
Property Value
- TimeSpan
The look-back window.
HistoryAvailability
Gets the history depth this provider advertises: how far back it can serve rates.
public override RateHistoryAvailability HistoryAvailability { get; }
Property Value
- RateHistoryAvailability
The advertised availability; the base reports Unbounded. A derived type whose feed publishes only a bounded window overrides this to declare it.
Remarks
ProviderId
Gets the provider identifier stamped on every rate this provider produces.
protected override string ProviderId { get; }
Property Value
- string
The provider identifier.
Methods
EnsureLoadedAsync(CurrencyPair, DateOnly, DateOnly, CancellationToken)
Ensures the inclusive window for a pair has been fetched and accumulated, idempotently. Implementations perform their own coverage check, request coalescing, fetch, and accumulation (via AddObservations(IEnumerable<ExchangeRate>, DateTimeOffset?) and RebuildSnapshot() under SyncRoot).
protected override ValueTask EnsureLoadedAsync(CurrencyPair pair, DateOnly startDate, DateOnly endDate, CancellationToken cancellationToken)
Parameters
pairCurrencyPairThe currency pair to ensure data for. Feeds that fetch by range, feed, or file may ignore it.
startDateDateOnlyThe inclusive start of the window.
endDateDateOnlyThe inclusive end of the window.
cancellationTokenCancellationTokenA token to observe while awaiting the fetch.
Returns
- ValueTask
A task that completes when the window has been loaded.
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.
GetAvailablePairs()
Gets the currency pairs discovered across the eras loaded so far.
public IReadOnlyCollection<RbaSeriesInfo> GetAvailablePairs()
Returns
- IReadOnlyCollection<RbaSeriesInfo>
A snapshot of the discovered series, one per currency pair.
IsLoaded(CurrencyPair, DateOnly, DateOnly)
Reports whether the inclusive window for a pair has already been fetched, so the synchronous lookup path can skip a redundant blocking fetch.
protected override bool IsLoaded(CurrencyPair pair, DateOnly startDate, DateOnly endDate)
Parameters
pairCurrencyPairThe currency pair to test.
startDateDateOnlyThe inclusive start of the window.
endDateDateOnlyThe inclusive end of the window.
Returns
LoadEraAsync(RbaEraWorkbook, CancellationToken)
Downloads and loads a single era, if it has not already been loaded.
public Task LoadEraAsync(RbaEraWorkbook era, CancellationToken cancellationToken = default)
Parameters
eraRbaEraWorkbookThe era to load.
cancellationTokenCancellationTokenA token to observe while awaiting the load.
Returns
- Task
A task that completes when the era has been loaded.
Exceptions
- ArgumentNullException
Thrown when
erais null.
LoadRangeAsync(DateOnly, DateOnly, CancellationToken)
Downloads and loads every era whose coverage overlaps the inclusive date range.
public Task LoadRangeAsync(DateOnly startDate, DateOnly endDate, CancellationToken cancellationToken = default)
Parameters
startDateDateOnlyThe inclusive start of the range.
endDateDateOnlyThe inclusive end of the range.
cancellationTokenCancellationTokenA token to observe while awaiting the loads.
Returns
- Task
A task that completes when the overlapping eras have been loaded.
Exceptions
- ArgumentException
Thrown when
endDateprecedesstartDate.
OnObservationIngested(ExchangeRate)
Called once per observation as it is ingested, for derived-type diagnostics. The default does nothing.
protected override void OnObservationIngested(ExchangeRate rate)
Parameters
rateExchangeRateThe observation being ingested.
PreloadAsync(CancellationToken)
Downloads and loads every era in the configured catalogue.
public Task PreloadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token to observe while awaiting the loads.
Returns
- Task
A task that completes when every era has been loaded.
ValidateRangeRequest(string, string, DateOnly, DateOnly)
Validates a range request against feed-specific preconditions before any fetch is attempted. The default does nothing; derived types may override to reject unsupported pairs (for example, a single-issuer feed that quotes only against one base currency).
protected override void ValidateRangeRequest(string fromIsoCode, string toIsoCode, DateOnly startDate, DateOnly endDate)
Parameters
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |