Search code examples
c#alpha-vantage

C# AlphaVantage.NET: How-to use Proxy


I want to use this library AlphaVantage.NET. I've tried the demo

string apiKey = "1"; // enter your API key here

var client = new AlphaVantageStocksClient(apiKey);

// retrieve daily time series for stocks of Apple Inc.:
StockTimeSeries timeSeries = await client.RequestDailyTimeSeriesAsync("AAPL", TimeSeriesSize.Compact, adjusted: false);
foreach (var dataPoint in timeSeries.DataPoints)
{
    Console.WriteLine($"{dataPoint.Time}: {dataPoint.ClosingPrice}");
}

// retrieve stocks batch quotes for Apple Inc. and Facebook Inc.:
ICollection<StockQuote> batchQuotes = await client.RequestBatchQuotesAsync(new[] { "AAPL", "FB" });
foreach (var stockQuote in batchQuotes)
{
    Console.WriteLine($"{stockQuote.Symbol}: {stockQuote.Price}");
}

But...is there any option to add a Proxy like in Using-WebClient? For example:

using (WebClient wc = new WebClient())
{
    IWebProxy proxy = WebRequest.GetSystemWebProxy();
    proxy.Credentials = CredentialCache.DefaultCredentials;

    wc.Proxy = proxy;
    var json = wc.DownloadString(@"https://www.alphavantage.co/query?function=TIME_SERIES_WEEKLY&symbol=BLDP&apikey=#############");
}

Sorry for my bad english :/


Solution

  • Unfortunately not.

    Looking at the source of the library, there's no way of intercepting/injecting the underlying http client being used. The client is private to the library and being new'ed up as a static in the Core project here: https://github.com/LutsenkoKirill/AlphaVantage.Net/blob/master/AlphaVantage.Net/src/AlphaVantage.Net.Core/AlphaVantageCoreClient.cs#L24