public void EmptyReturnedIfEmptyCollectionPassed() { IEnumerable <QuoteExt> quotes = new QuoteExt[0]; var generator = new CandleGenerator(); var candles = generator.Generate(quotes, TimeInterval.Sec, PriceType.Ask); Assert.NotNull(candles); Assert.Equal(0, candles.Count()); }
public void CandlesAreGrouped() { DateTime dt = new DateTime(2017, 1, 1); var generator = new CandleGenerator(); var quotes = new QuoteExt[] { new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 1.1, Timestamp = dt, PriceType = PriceType.Bid }, new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 0.8, Timestamp = dt, PriceType = PriceType.Bid } }; var candles = generator.Generate(quotes, TimeInterval.Sec, PriceType.Bid); Assert.Equal(1, candles.Count()); quotes = new QuoteExt[] { new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 1.1, Timestamp = dt.AddMinutes(2).AddSeconds(1), PriceType = PriceType.Bid }, new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 0.8, Timestamp = dt.AddMinutes(2).AddSeconds(8), PriceType = PriceType.Bid } }; candles = generator.Generate(quotes, TimeInterval.Minute, PriceType.Bid); Assert.Equal(1, candles.Count()); quotes = new QuoteExt[] { new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 1.1, Timestamp = dt.AddHours(1).AddMinutes(1), PriceType = PriceType.Bid }, new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 0.8, Timestamp = dt.AddHours(2).AddMinutes(8), PriceType = PriceType.Bid } }; candles = generator.Generate(quotes, TimeInterval.Hour, PriceType.Bid); Assert.Equal(2, candles.Count()); quotes = new QuoteExt[] { new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 1.1, Timestamp = dt.AddDays(1).AddHours(1), PriceType = PriceType.Bid }, new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 0.8, Timestamp = dt.AddDays(2).AddHours(8), PriceType = PriceType.Bid } }; candles = generator.Generate(quotes, TimeInterval.Day, PriceType.Bid); Assert.Equal(2, candles.Count()); quotes = new QuoteExt[] { new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 1.1, Timestamp = dt.AddMonths(-2).AddDays(1), PriceType = PriceType.Bid }, new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 0.8, Timestamp = dt.AddMonths(-1).AddDays(8), PriceType = PriceType.Bid } }; candles = generator.Generate(quotes, TimeInterval.Month, PriceType.Bid); Assert.Equal(2, candles.Count()); quotes = new QuoteExt[] { new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 1.1, Timestamp = dt.AddMonths(1).AddDays(1), PriceType = PriceType.Bid }, new QuoteExt { AssetPair = "BTCUSD", IsBuy = true, Price = 0.8, Timestamp = dt.AddMonths(2).AddDays(8), PriceType = PriceType.Bid } }; candles = generator.Generate(quotes, TimeInterval.Month, PriceType.Bid); Assert.Equal(2, candles.Count()); }