public async System.Threading.Tasks.Task <List <DataBar> > GetHistoricalDataAsync(SecurityType securityType, string ticker, BarSize barSize, DateTime?endDate = null) { var client = new AlphaVantageStocksClient(Constants.AlphaVantageApiKey); var HistoricalBarCollection = new List <DataBar>(); StockTimeSeries timeSeries; switch (barSize) { case BarSize.DAY: timeSeries = await client.RequestDailyTimeSeriesAsync(ticker, TimeSeriesSize.Full, adjusted : false); break; case BarSize.WEEK: timeSeries = await client.RequestWeeklyTimeSeriesAsync(ticker, adjusted : false); break; case BarSize.MONTH: timeSeries = await client.RequestMonthlyTimeSeriesAsync(ticker, adjusted : false); break; default: timeSeries = await client.RequestIntradayTimeSeriesAsync(ticker, (IntradayInterval)barSize, TimeSeriesSize.Full); break; } ((List <StockDataPoint>)timeSeries.DataPoints).ForEach(bar => HistoricalBarCollection.Add(new DataBar(bar))); return(HistoricalBarCollection); }
public async Task RequestWeeklyTimeSeriesAsync_Adjusted_Test() { var client = new AlphaVantageStocksClient(ApiKey); var result = await client.RequestWeeklyTimeSeriesAsync(Symbol, adjusted : true); Assert.NotNull(result); Assert.Equal(TimeSeriesType.Weekly, result.Type); Assert.Equal(Symbol, result.Symbol); Assert.True(result.IsAdjusted); Assert.NotNull(result.DataPoints); Assert.True(result.DataPoints.All(p => p is StockAdjustedDataPoint)); }