YahooRateProvider Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Yahoo.dll
- Package
- Bodu.Financial.ExchangeRates.Yahoo 0.7.1
- Source
- YahooRateProvider.cs
Serves Yahoo Finance exchange rates as ExchangeRate values, implementing the Bodu.Financial provider
contracts over the Yahoo Finance v8/finance/chart JSON REST service.
public sealed class YahooRateProvider : PairWebRateProvider<YahooSeriesInfo>, IDatedRateProvider, IRateProvider, IPairRateLoader, IHistoricalRateProvider, IDisposable
- Inheritance
-
YahooRateProvider
- Implements
- Inherited Members
- Extension Methods
Examples
using var yahoo = new YahooRateProvider(new YahooRateProviderOptions());
await yahoo.LoadPairAsync("AUD", "USD", new DateOnly(2023, 1, 1), new DateOnly(2023, 1, 31));
RateLookupResult aud = yahoo.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 Yahoo identity, the ticker-based log label, and the
Yahoo-specific exception text. Yahoo serves arbitrary pairs through the {FROM}{TO}=X ticker convention, 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 Yahoo endpoint answers requests without a recognizable user
agent with 429 Too Many Requests), 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
YahooRateProvider(YahooRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the YahooRateProvider class backed by an HttpClient the provider creates and owns, configured from the supplied options.
public YahooRateProvider(YahooRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
optionsYahooRateProviderOptionsThe provider options.
loggerILoggerThe logger that records chart 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.
YahooRateProvider(HttpClient, YahooRateProviderOptions, ILogger?, TimeProvider?)
Initializes a new instance of the YahooRateProvider class backed by the Yahoo Finance chart endpoint, queried with the caller-supplied HTTP client. The caller owns the client's configuration and lifetime.
public YahooRateProvider(HttpClient httpClient, YahooRateProviderOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
httpClientHttpClientThe HTTP client used to issue chart requests.
optionsYahooRateProviderOptionsThe provider options.
loggerILoggerThe logger that records chart 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 = "Yahoo"
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
FormatPairForLog(CurrencyPair)
Formats the label used for a pair in the download log messages. The default returns the FROM/TO ISO-code
pair; a derived type may override it to log a feed-specific identifier such as a ticker.
protected override string FormatPairForLog(CurrencyPair pair)
Parameters
pairCurrencyPairThe pair being logged.
Returns
- string
The label to log.
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 |