Table of Contents

Class AlphaVantageClient

Namespace
Tudormobile.AlphaVantage
Assembly
Tudormobile.AlphaVantageAPI.dll

Provides methods for accessing financial data from the Alpha Vantage API.

public class AlphaVantageClient : IAlphaVantageClient
Inheritance
AlphaVantageClient
Implements
Inherited Members
Extension Methods

Remarks

Use this client to retrieve stock quotes, time series data, and other financial information from Alpha Vantage. An API key from Alpha Vantage is required to use most features.

Constructors

AlphaVantageClient(IHttpClientFactory, string, ILogger<AlphaVantageClient>)

Initializes a new instance of the AlphaVantageClient class using the specified HTTP client factory, API key, and logger.

public AlphaVantageClient(IHttpClientFactory httpClientFactory, string apiKey, ILogger<AlphaVantageClient> logger)

Parameters

httpClientFactory IHttpClientFactory

The factory used to create HTTP client instances for sending requests to the Alpha Vantage API. Cannot be null.

apiKey string

The API key used to authenticate requests to the Alpha Vantage service. Cannot be null or empty.

logger ILogger<AlphaVantageClient>

The logger used to record diagnostic and operational information for the AlphaVantageClient. Cannot be null.

AlphaVantageClient(string, HttpClient, ILogger?)

Initializes a new instance of the AlphaVantageClient class using the specified API key.

public AlphaVantageClient(string apiKey, HttpClient httpClient, ILogger? logger = null)

Parameters

apiKey string

The API key used to authenticate requests to the Alpha Vantage service. Cannot be null or empty.

httpClient HttpClient

The HttpClient instance used to make HTTP requests to the Alpha Vantage API.

logger ILogger

Optional logger instance for logging diagnostic information. If null, a NullLogger will be used.

Methods

GetJsonDocumentAsync(AlphaVantageFunction, IDictionary<string, string>, CancellationToken)

Asynchronously retrieves a JSON document from the Alpha Vantage API using the specified function and query parameters.

public Task<JsonDocument> GetJsonDocumentAsync(AlphaVantageFunction function, IDictionary<string, string> queryParameters, CancellationToken cancellationToken = default)

Parameters

function AlphaVantageFunction

The Alpha Vantage function to invoke when constructing the API request.

queryParameters IDictionary<string, string>

A dictionary containing the query parameters to include in the API request. 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 data returned by the Alpha Vantage API.

Remarks

The caller is responsible for disposing the returned JsonDocument. The method throws if the HTTP request fails or if the response cannot be parsed as JSON.

Exceptions

ArgumentException

Thrown if queryParameters is null or contains no entries.

GetJsonDocumentAsync(AlphaVantageFunction, string, CancellationToken)

Asynchronously retrieves and parses a JSON document for the specified Alpha Vantage function and symbol.

public Task<JsonDocument> GetJsonDocumentAsync(AlphaVantageFunction function, string symbol, CancellationToken cancellationToken = default)

Parameters

function AlphaVantageFunction

The Alpha Vantage function to query. Determines the type of data to retrieve.

symbol string

The symbol representing the financial instrument to query. Cannot be null or empty.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<JsonDocument>

A task that represents the asynchronous operation. The task result contains a JsonDocument representing the parsed JSON response.

GetJsonStringAsync(AlphaVantageFunction, IDictionary<string, string>, CancellationToken)

Asynchronously retrieves the raw JSON response from the Alpha Vantage API for the specified function and query parameters.

public Task<string> GetJsonStringAsync(AlphaVantageFunction function, IDictionary<string, string> queryParameters, CancellationToken cancellationToken = default)

Parameters

function AlphaVantageFunction

The Alpha Vantage function to query. Determines the type of data returned by the API.

queryParameters IDictionary<string, string>

A dictionary of query parameters to include in the API request. Cannot be null or empty.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<string>

A task that represents the asynchronous operation. The task result contains the JSON response as a string.

GetJsonStringAsync(AlphaVantageFunction, string, CancellationToken)

Asynchronously retrieves the raw JSON response from the Alpha Vantage API for the specified function and symbol.

public Task<string> GetJsonStringAsync(AlphaVantageFunction function, string symbol, CancellationToken cancellationToken = default)

Parameters

function AlphaVantageFunction

The Alpha Vantage function to query. Determines the type of data returned by the API.

symbol string

The symbol representing the financial instrument to query. Cannot be null or empty.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<string>

A task that represents the asynchronous operation. The task result contains the JSON response as a string.