IDatedRateProvider Interface
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.0.0
- Source
- IDatedRateProvider.cs
Defines the contract for an exchange-rate provider that resolves dated and latest lookups and returns metadata describing how each rate was selected, over symmetric synchronous and asynchronous surfaces.
public interface IDatedRateProvider
- Extension Methods
Remarks
Implementations are expected to validate their string and option arguments and throw rather than return failure when inputs are invalid. The distinction between GetRate(string, string, DateOnly, RateLookupOptions?) and TryGetRate(string, string, DateOnly, RateLookupOptions?, out RateLookupResult) is reserved for the case where no rate is available for an otherwise valid request: the former throws KeyNotFoundException, the latter returns false without allocating.
Implementations must accept a null options argument and substitute
Exact (or, for the undated latest surface, an implementation-defined most-recent
policy) so callers can opt into the documented safe default by omission.
Every getter returns the same element type - a single RateLookupResult for the point lookups, and an IEnumerable<T> of them for the range lookups. The synchronous getters and the asynchronous getters resolve identical results; the asynchronous surface exists because an implementation backed by a remote feed may fetch on demand, and the synchronous surface may block to do so (or serve only already-loaded data, at the implementation's discretion).
using Bodu.Financial;
IDatedRateProvider provider = new FixedDatedRateProvider(new[]
{
new ExchangeRate(CurrencyCode.USD, CurrencyCode.EUR, new DateOnly(2024, 3, 1), 0.92m, "ECB"),
});
// TryGetRate signals a missing rate without throwing; GetRate throws KeyNotFoundException.
var date = new DateOnly(2024, 3, 1);
if (provider.TryGetRate("USD", "EUR", date, RateLookupOptions.Exact, out var result))
{
decimal rate = result.Rate.Rate; // 0.92
}
Methods
GetRate(string, string, RateLookupOptions?)
Resolves the most recent available exchange rate from fromIsoCode to
toIsoCode under options, throwing if no rate is available.
RateLookupResult GetRate(string fromIsoCode, string toIsoCode, RateLookupOptions? options = null)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
optionsRateLookupOptionsThe lookup rules to apply. null selects the implementation's default most-recent policy.
Returns
- RateLookupResult
The resolved RateLookupResult.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
optionsis invalid.- KeyNotFoundException
Thrown if no rate is available for the request.
GetRate(string, string, DateOnly, RateLookupOptions?)
Resolves the exchange rate from fromIsoCode to toIsoCode on
date under options, throwing if no rate is available.
RateLookupResult GetRate(string fromIsoCode, string toIsoCode, DateOnly date, RateLookupOptions? options = null)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
dateDateOnlyThe calendar date for which a rate is required.
optionsRateLookupOptionsThe lookup rules to apply, including date-resolution policy and tolerance. null is treated as Exact.
Returns
- RateLookupResult
The resolved RateLookupResult.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
optionsis invalid (for example, Exact with non-zero tolerance).- ArgumentOutOfRangeException
Thrown if
optionscontains a negative tolerance or an undefined enum value.- KeyNotFoundException
Thrown if no rate is available for the request under the supplied options.
GetRateAsync(string, string, RateLookupOptions?, CancellationToken)
Asynchronously resolves the most recent available exchange rate from fromIsoCode to
toIsoCode under options, throwing if no rate is available.
ValueTask<RateLookupResult> GetRateAsync(string fromIsoCode, string toIsoCode, RateLookupOptions? options = null, CancellationToken cancellationToken = default)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
optionsRateLookupOptionsThe lookup rules to apply. null selects the implementation's default most-recent policy.
cancellationTokenCancellationTokenA token to observe while awaiting the operation.
Returns
- ValueTask<RateLookupResult>
A task that yields the resolved RateLookupResult.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
optionsis invalid.- KeyNotFoundException
Thrown if no rate is available for the request.
GetRateAsync(string, string, DateOnly, RateLookupOptions?, CancellationToken)
Asynchronously resolves the exchange rate from fromIsoCode to toIsoCode
on date under options, throwing if no rate is available.
ValueTask<RateLookupResult> GetRateAsync(string fromIsoCode, string toIsoCode, DateOnly date, RateLookupOptions? options = null, CancellationToken cancellationToken = default)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
dateDateOnlyThe calendar date for which a rate is required.
optionsRateLookupOptionsThe lookup rules to apply, including date-resolution policy and tolerance. null is treated as Exact.
cancellationTokenCancellationTokenA token to observe while awaiting the operation.
Returns
- ValueTask<RateLookupResult>
A task that yields the resolved RateLookupResult.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
optionsis invalid.- ArgumentOutOfRangeException
Thrown if
optionscontains a negative tolerance or an undefined enum value.- KeyNotFoundException
Thrown if no rate is available for the request under the supplied options.
GetRates(string, string, DateOnly, DateOnly)
Returns every available rate from fromIsoCode to toIsoCode whose
observation date falls within the inclusive range startDate to endDate.
RateRangeResult GetRates(string fromIsoCode, string toIsoCode, DateOnly startDate, DateOnly endDate)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
startDateDateOnlyThe inclusive start of the range.
endDateDateOnlyThe inclusive end of the range.
Returns
- RateRangeResult
An RateRangeResult carrying the rates in the range ordered by date, the requested window, and the observed span; the result is empty when no rates are available.
Remarks
The lookup is range-based and does not apply a date-resolution policy: it returns the observations that exist within the window rather than resolving a single date. An implementation backed by a remote feed may block to fetch on demand, or serve only already-loaded data; use GetRatesAsync(string, string, DateOnly, DateOnly, CancellationToken) to fetch without blocking.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
endDateprecedesstartDate.
GetRatesAsync(string, string, DateOnly, DateOnly, CancellationToken)
Asynchronously returns every available rate from fromIsoCode to
toIsoCode whose observation date falls within the inclusive range
startDate to endDate.
ValueTask<RateRangeResult> GetRatesAsync(string fromIsoCode, string toIsoCode, DateOnly startDate, DateOnly endDate, CancellationToken cancellationToken = default)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
startDateDateOnlyThe inclusive start of the range.
endDateDateOnlyThe inclusive end of the range.
cancellationTokenCancellationTokenA token to observe while awaiting the operation.
Returns
- ValueTask<RateRangeResult>
A task that yields an RateRangeResult carrying the rates in the range ordered by date, the requested window, and the observed span; the result is empty when no rates are available.
Remarks
The lookup is range-based and does not apply a date-resolution policy: it returns the observations that exist within the window rather than resolving a single date. Implementations backed by a remote feed may fetch on demand, which is why the method is asynchronous.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
endDateprecedesstartDate.
TryGetRate(string, string, DateOnly, RateLookupOptions?, out RateLookupResult)
Attempts to resolve the exchange rate from fromIsoCode to toIsoCode on
date under options, returning a flag indicating whether a rate was
found.
bool TryGetRate(string fromIsoCode, string toIsoCode, DateOnly date, RateLookupOptions? options, out RateLookupResult result)
Parameters
fromIsoCodestringThe source-currency ISO-style code.
toIsoCodestringThe destination-currency ISO-style code.
dateDateOnlyThe calendar date for which a rate is required.
optionsRateLookupOptionsThe lookup rules to apply, including date-resolution policy and tolerance. null is treated as Exact.
resultRateLookupResultWhen this method returns true, contains the resolved RateLookupResult; otherwise, contains default.
Returns
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code, or if
optionsis invalid.- ArgumentOutOfRangeException
Thrown if
optionscontains a negative tolerance or an undefined enum value.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |