FredRateProvider Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Fred.dll
- Package
- Bodu.Financial.ExchangeRates.Fred 0.7.1
- Source
- FredRateProvider.cs
Serves FRED (Federal Reserve Bank of St. Louis) exchange rates as ExchangeRate values, implementing the Bodu.Financial provider contracts over the FRED series-observations JSON REST endpoint.
public sealed class FredRateProvider : PairWebRateProvider<FredSeriesInfo>, IDatedRateProvider, IRateProvider, IPairRateLoader, IHistoricalRateProvider, IDisposable
- Inheritance
-
FredRateProvider
- Implements
- Inherited Members
- Extension Methods
Examples
using var fred = new FredRateProvider(new FredRateProviderOptions { ApiKey = "…" });
await fred.LoadPairAsync("EUR", "USD", new DateOnly(2023, 1, 1), new DateOnly(2023, 1, 31));
RateLookupResult usd = fred.GetRate("EUR", "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 FRED identity and exception text. A pair is fetched by resolving it to a single FRED series through SeriesMap and reading that series' observations. Use LoadPairAsync(string, string, DateOnly, DateOnly, CancellationToken) to warm a pair's in-memory store.
Per-series mapping. FRED publishes each foreign-exchange rate as an independent time series quoted in a fixed direction. A pair with no mapped series yields no data rather than a fetch; the reverse of a mapped pair is served by the base class's inverse-lookup fallback. Add mappings through SeriesMap to support additional pairs.
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; this is the path the dependency-injection package uses.
Constructors
FredRateProvider(FredRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the FredRateProvider class backed by an HttpClient the provider creates and owns, configured from the supplied options.
public FredRateProvider(FredRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
optionsFredRateProviderOptionsThe 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.
FredRateProvider(HttpClient, FredRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the FredRateProvider class backed by the FRED endpoint, queried with the caller-supplied HTTP client. The caller owns the client's configuration and lifetime.
public FredRateProvider(HttpClient httpClient, FredRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
httpClientHttpClientThe HTTP client used to issue requests.
optionsFredRateProviderOptionsThe 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 = "FRED"
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 |