Table of Contents

Class AlphaVantageClientExtensions

Namespace
Tudormobile.AlphaVantage.Extensions
Assembly
Tudormobile.AlphaVantageAPI.dll

Provides extension methods for working with instances of IAlphaVantageClient.

public static class AlphaVantageClientExtensions
Inheritance
AlphaVantageClientExtensions
Inherited Members

Remarks

This class contains static methods that extend the functionality of IAlphaVantageClient implementations, enabling fluent configuration and builder patterns. These extensions are intended to simplify client setup and integration scenarios.

The code uses the newer C# extension method syntax with the 'extension' keyword for better readability and conciseness.

Methods

DividendsJsonAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves the dividend history for the specified symbol in JSON format.

public static Task<JsonDocument> DividendsJsonAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The ticker symbol of the security for which to retrieve dividend data. Cannot be null or empty.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

Task<JsonDocument>

A task that represents the asynchronous operation. The task result contains a JsonDocument with the dividend data for the specified symbol.

EarningsEstimatesJsonAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves the raw earnings estimates data for the specified symbol in JSON format.

public static Task<JsonDocument> EarningsEstimatesJsonAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The ticker symbol of the security for which to retrieve earnings estimates. Cannot be null or empty.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

Task<JsonDocument>

A task that represents the asynchronous operation. The task result contains a JsonDocument with the earnings estimates data for the specified symbol.

Remarks

The returned JsonDocument contains the unprocessed response from the data provider. Callers are responsible for parsing and disposing of the JsonDocument. This method does not perform any validation or transformation of the JSON data.

GetBuilder()

Creates a new builder for configuring and constructing an instance of an Alpha Vantage client.

public static IAlphaVantageClientBuilder GetBuilder()

Returns

IAlphaVantageClientBuilder

An IBuilder<T> that can be used to configure and build an IAlphaVantageClient instance.

GetDailyTimeSeriesAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves and parses daily time series data for the specified stock symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<TimeSeries>> GetDailyTimeSeriesAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve daily time series data for.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<AlphaVantageResponse<TimeSeries>>

A Task<TResult> containing either the parsed TimeSeries data with daily interval or error information.

Remarks

This method calls the Alpha Vantage Daily Time Series API and parses the JSON response into a strongly-typed TimeSeries object with Daily interval. If the API returns an error or the data cannot be parsed, the response will contain an error message in the ErrorMessage property.

GetDividendsAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves and parses the dividend history for the specified symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<Dividends>> GetDividendsAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The ticker symbol of the security for which to retrieve dividend data. Cannot be null or empty.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

Task<AlphaVantageResponse<Dividends>>

A task that represents the asynchronous operation. The task result contains an AlphaVantageResponse<T> with the dividend data for the specified symbol, or an error message if the data is not available.

GetEarningsEstimatesAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves and parses the earnings estimates data for the specified symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<EarningsEstimates>> GetEarningsEstimatesAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The ticker symbol of the security for which to retrieve earnings estimates. Cannot be null or empty.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

Task<AlphaVantageResponse<EarningsEstimates>>

A task that represents the asynchronous operation. The task result contains an AlphaVantageResponse<T> with the earnings estimates data for the specified symbol, or an error message if the data is not available.

Remarks

This method calls the Alpha Vantage Earnings Estimates API and parses the JSON response into a strongly-typed EarningsEstimates object. If the API returns an error or the data cannot be parsed, the response will contain an error message in the ErrorMessage property.

GetGlobalQuoteAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves and parses the global quote data for the specified stock symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<GlobalQuote>> GetGlobalQuoteAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve the global quote for.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<AlphaVantageResponse<GlobalQuote>>

A Task<TResult> containing either the parsed GetGlobalQuoteAsync(IAlphaVantageClient, string, CancellationToken) data or error information.

Remarks

This method calls the Alpha Vantage Global Quote API and parses the JSON response into a strongly-typed GetGlobalQuoteAsync(IAlphaVantageClient, string, CancellationToken) object. If the API returns an error or the data cannot be parsed, the response will contain an error message in the ErrorMessage property.

GetGlobalQuotesAsync(IAlphaVantageClient, IEnumerable<string>, CancellationToken)

Retrieves global quote data for multiple stock symbols concurrently.

public static Task<IDictionary<string, AlphaVantageResponse<GlobalQuote>>> GetGlobalQuotesAsync(this IAlphaVantageClient client, IEnumerable<string> symbols, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbols IEnumerable<string>

An enumerable collection of stock symbols to retrieve global quotes for.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IDictionary<string, AlphaVantageResponse<GlobalQuote>>>

A Task<TResult> containing a dictionary where keys are stock symbols and values are the corresponding AlphaVantageResponse<T> data.

Remarks

This method executes multiple API calls concurrently to fetch global quote data for all provided symbols. Each symbol's result is returned as a separate AlphaVantageResponse<T> in the dictionary, allowing individual error handling per symbol. Failed requests will have error information in their respective ErrorMessage property.

Warning: This method does not implement rate limiting. If your Alpha Vantage API key has rate limits, you are responsible for throttling calls. Consider using Polly or a similar library to implement rate limiting at the application level.

GetMonthlyTimeSeriesAsync(IAlphaVantageClient, string, bool, CancellationToken)

Retrieves and parses monthly time series data for the specified stock symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<TimeSeries>> GetMonthlyTimeSeriesAsync(this IAlphaVantageClient client, string symbol, bool adjusted = false, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve monthly time series data for.

adjusted bool

If true, returns adjusted monthly data that accounts for stock splits and dividends; otherwise, returns unadjusted monthly data. Default is false.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<AlphaVantageResponse<TimeSeries>>

A Task<TResult> containing either the parsed TimeSeries data with monthly interval or error information.

Remarks

This method calls the Alpha Vantage Monthly Time Series API and parses the JSON response into a strongly-typed TimeSeries object with Monthly interval. If the API returns an error or the data cannot be parsed, the response will contain an error message in the ErrorMessage property.

GetTreasuryYieldAsync(IAlphaVantageClient, TreasuryYieldInterval?, TreasuryYieldMaturity?, CancellationToken)

Retrieves and parses the U.S. Treasury yield data for the specified symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<TreasuryYield>> GetTreasuryYieldAsync(this IAlphaVantageClient client, TreasuryYieldInterval? interval = TreasuryYieldInterval.Monthly, TreasuryYieldMaturity? maturity = TreasuryYieldMaturity._10Year, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
interval TreasuryYieldInterval?

The interval for the Treasury yield data. Default is monthly.

maturity TreasuryYieldMaturity?

The maturity for the Treasury yield data. Default is 10-year.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

Task<AlphaVantageResponse<TreasuryYield>>

A task that represents the asynchronous operation. The task result contains an AlphaVantageResponse<T> with the Treasury yield data for the specified symbol, or an error message if the data is not available.

Remarks

This method calls the Alpha Vantage Treasury Yield API and parses the JSON response into a strongly-typed TreasuryYield object. If the API returns an error or the data cannot be parsed, the response will contain an error message in the ErrorMessage property.

GetWeeklyTimeSeriesAsync(IAlphaVantageClient, string, bool, CancellationToken)

Retrieves and parses weekly time series data for the specified stock symbol into a strongly-typed response.

public static Task<AlphaVantageResponse<TimeSeries>> GetWeeklyTimeSeriesAsync(this IAlphaVantageClient client, string symbol, bool adjusted = false, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve weekly time series data for.

adjusted bool

If true, returns adjusted weekly data that accounts for stock splits and dividends; otherwise, returns unadjusted weekly data. Default is false.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<AlphaVantageResponse<TimeSeries>>

A Task<TResult> containing either the parsed TimeSeries data with weekly interval or error information.

Remarks

This method calls the Alpha Vantage Weekly Time Series API and parses the JSON response into a strongly-typed TimeSeries object with Weekly interval. If the API returns an error or the data cannot be parsed, the response will contain an error message in the ErrorMessage property.

GlobalQuoteJsonAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves the latest global quote information for the specified stock symbol.

public static Task<JsonDocument> GlobalQuoteJsonAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve the global quote for.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<JsonDocument>

A Task<TResult> containing the global quote data including price, volume, and trading information.

SymbolSearchAsync(IAlphaVantageClient, string, MatchTypes, Regions, CancellationToken)

Searches for financial symbols that match the specified keywords using the Alpha Vantage API.

public static Task<AlphaVantageResponse<SymbolMatches>> SymbolSearchAsync(this IAlphaVantageClient client, string keywords, SymbolMatch.MatchTypes matchType = MatchTypes.Any, SymbolMatch.Regions region = Regions.Any, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
keywords string

The keywords to search for. Typically a company name, ticker symbol, or related term. Cannot be null or empty.

matchType SymbolMatch.MatchTypes

The type of match to perform when searching for symbols. Specifies whether to match any, exact, or partial results. Defaults to Any.

region SymbolMatch.Regions

The region to filter symbol search results by. Specifies the geographic area for the search. Defaults to Any.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<AlphaVantageResponse<SymbolMatches>>

A task that represents the asynchronous operation. The task result contains an AlphaVantageResponse<T> with the matching symbols, or an error message if no results are found.

Remarks

The search results may vary depending on the keywords, match type, and region specified. If no matching symbols are found, the response will contain an error message. This method is asynchronous and should be awaited.

SymbolSearchJsonAsync(IAlphaVantageClient, string, CancellationToken)

Searches for stock symbols matching the specified keywords.

public static Task<JsonDocument> SymbolSearchJsonAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The search keywords to find matching stock symbols.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<JsonDocument>

A Task<TResult> containing the symbol search results with matching stock symbols and company information.

TimeSeriesDailyJsonAsync(IAlphaVantageClient, string, CancellationToken)

Retrieves daily time series data for the specified stock symbol.

public static Task<JsonDocument> TimeSeriesDailyJsonAsync(this IAlphaVantageClient client, string symbol, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve daily time series data for.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<JsonDocument>

A Task<TResult> containing the daily time series data.

TimeSeriesMonthlyJsonAsync(IAlphaVantageClient, string, bool, CancellationToken)

Retrieves monthly time series data for the specified stock symbol.

public static Task<JsonDocument> TimeSeriesMonthlyJsonAsync(this IAlphaVantageClient client, string symbol, bool adjusted = false, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve monthly time series data for.

adjusted bool

If true, returns adjusted monthly data; otherwise, returns unadjusted monthly data. Default is false.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<JsonDocument>

A Task<TResult> containing the monthly time series data.

TimeSeriesWeeklyJsonAsync(IAlphaVantageClient, string, bool, CancellationToken)

Retrieves weekly time series data for the specified stock symbol.

public static Task<JsonDocument> TimeSeriesWeeklyJsonAsync(this IAlphaVantageClient client, string symbol, bool adjusted = false, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
symbol string

The stock symbol to retrieve weekly time series data for.

adjusted bool

If true, returns adjusted weekly data; otherwise, returns unadjusted weekly data. Default is false.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<JsonDocument>

A Task<TResult> containing the weekly time series data.

TreasuryYieldJsonAsync(IAlphaVantageClient, TreasuryYieldInterval?, TreasuryYieldMaturity?, CancellationToken)

Retrieves the U.S. Treasury yield data for the specified symbol as a JSON document.

public static Task<JsonDocument> TreasuryYieldJsonAsync(this IAlphaVantageClient client, TreasuryYieldInterval? interval = TreasuryYieldInterval.Monthly, TreasuryYieldMaturity? maturity = TreasuryYieldMaturity._10Year, CancellationToken cancellationToken = default)

Parameters

client IAlphaVantageClient
interval TreasuryYieldInterval?

The interval for the Treasury yield data. Default is monthly.

maturity TreasuryYieldMaturity?

The maturity for the Treasury yield data. Default is 10-year.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

Task<JsonDocument>

A task that represents the asynchronous operation. The task result contains a JsonDocument with the Treasury yield data for the specified symbol.

Remarks

The returned JSON document contains the raw data as provided by the Alpha Vantage API. The caller is responsible for parsing and disposing of the JsonDocument.