/// <summary> /// Imports the async. endTime stock history inclusive /// </summary> /// <returns>The async.</returns> /// <param name="symbol">Symbol.</param> /// <param name="startTime">Start time.</param> /// <param name="endTime">End time.</param> /// <param name="period">Period.</param> /// <param name="token">Token.</param> public async Task <IList <Core.Candle> > ImportAsync(string symbol, DateTime?startTime = default(DateTime?), DateTime?endTime = default(DateTime?), PeriodOption period = PeriodOption.Daily, CancellationToken token = default(CancellationToken)) { if (period != PeriodOption.Daily && period != PeriodOption.Monthly && period != PeriodOption.Weekly) { throw new ArgumentException("This importer only supports daily, weekly & monthly data"); } var candles = await Stooq.GetHistoricalAsync(symbol, PeriodMap[period], startTime, endTime, SkipOption.None, false, token); return(candles.Select(c => new Core.Candle(c.DateTime, c.Open, c.High, c.Low, c.Close, c.Volume)).OrderBy(c => c.DateTime).ToList()); }
public void PeriodTest() { const decimal open = 2251.57m; Enum.GetValues(typeof(Period)).Cast <Period>().Except(new Period[] { Period.Yearly }).ToList().ForEach(p => { var candle = Stooq.GetHistoricalAsync("^SPX", p, new DateTime(2017, 1, 3), ascending: true).Result.First(); Assert.Equal(candle.Open, open); Thread.Sleep(1000); }); }
public void EodTest() { var candles = Stooq.GetHistoricalAsync("aapl.us", Period.Daily, new DateTime(2017, 1, 3), ascending: true).Result; var candle = candles.First(); Assert.Equal(candle.DateTime, new DateTime(2017, 1, 3)); Assert.Equal(112.67m, candle.Open); Assert.Equal(113.19m, candle.High); Assert.Equal(111.65m, candle.Low); Assert.Equal(113.01m, candle.Close); Assert.Equal(28_509_939, candle.Volume); }
public void IndexEodTest() { var candles = Stooq.GetHistoricalAsync("^SPX", Period.Daily, new DateTime(2017, 1, 3), ascending: true).Result; var candle = candles.First(); Assert.Equal(candle.DateTime, new DateTime(2017, 1, 3)); Assert.Equal(2251.57m, candle.Open); Assert.Equal(2263.88m, candle.High); Assert.Equal(2245.13m, candle.Low); Assert.Equal(2257.83m, candle.Close); Assert.Equal(644_640_832, candle.Volume); }
public void EodTest() { var candles = Stooq.GetHistoricalAsync("aapl.us", Period.Daily, new DateTime(2017, 1, 3), ascending: true).Result; var candle = candles.First(); Assert.Equal(candle.DateTime, new DateTime(2017, 1, 3)); Assert.Equal(110.36m, candle.Open); Assert.Equal(110.88m, candle.High); Assert.Equal(109.35m, candle.Low); Assert.Equal(110.7m, candle.Close); Assert.Equal(29_108_191, candle.Volume); }
public void EodTest() { var candles = Stooq.GetHistoricalAsync("aapl.us", Period.Daily, new DateTime(2017, 1, 3), ascending: true).Result; var candle = candles.First(); Assert.Equal(candle.DateTime, new DateTime(2017, 1, 3)); Assert.Equal(candle.Open, 114.83m); Assert.Equal(candle.High, 115.35m); Assert.Equal(candle.Low, 113.79m); Assert.Equal(candle.Close, 115.17m); Assert.Equal(candle.Volume, 27_975_430); }
public void DateTimeTest() { // Bug: Stooq returns empty csv if start date < the particular date, no candle can be retrieved in this case // var candle = Stooq.GetHistoricalAsync("^SPX", Period.Daily, ascending: true).Result; // Assert.Equal(candle.First().DateTime, new DateTime(1789, 5, 1)); //Thread.Sleep(1000); var candle2 = Stooq.GetHistoricalAsync("^SPX", Period.Daily, new DateTime(2017, 1, 3), ascending: true).Result; Assert.Equal(candle2.First().DateTime, new DateTime(2017, 1, 3)); Thread.Sleep(1000); var candle3 = Stooq.GetHistoricalAsync("^SPX", Period.Daily, new DateTime(2017, 1, 3), new DateTime(2017, 2, 3), ascending: true).Result; Assert.Equal(candle3.First().DateTime, new DateTime(2017, 1, 3)); Assert.Equal(candle3.Last().DateTime, new DateTime(2017, 2, 3)); Thread.Sleep(1000); // Bug: Stooq returns empty csv if start date < the particular date, no candle can be retrieved in this case //var candle4 = Stooq.GetHistoricalAsync("^SPX", Period.Daily, endTime: new DateTime(2017, 2, 3), ascending: true).Result; //Assert.Equal(candle4.Last().DateTime, new DateTime(2017, 2, 3)); }