Пример #1
0
        public void WriteReadMinutes()
        {
            var      asset    = "EURUSD";
            var      interval = TimeInterval.Minute;
            var      logger   = new LogToMemory();
            var      storage  = CreateStorage <CandleTableEntity>(logger);
            var      repo     = new CandleHistoryRepository(storage);
            DateTime baseTime = new DateTime(2017, 03, 01, 0, 0, 0, DateTimeKind.Utc);

            var candlesIn = from i in Enumerable.Range(0, 60 * 24 * 3) // 3 days
                            select new FeedCandle()
            {
                DateTime = baseTime.AddMinutes(i), IsBuy = true, Open = i, Close = i, High = i, Low = i
            };

            repo.InsertOrMergeAsync(candlesIn, asset, interval).Wait();

            // Select for 1 hour
            var queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(asset, interval, true,
                                                                                      from: baseTime.AddHours(1),
                                                                                      to: baseTime.AddHours(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(60, queriedCandles.Count());

            Assert.True(queriedCandles.First().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1), IsBuy = true, Open = 60, Close = 60, High = 60, Low = 60
            }));
            Assert.True(queriedCandles.Last().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1).AddMinutes(59), IsBuy = true, Open = 119, Close = 119, High = 119, Low = 119
            }));

            // Select for 1 day
            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(asset, interval, true,
                                                                                  from: baseTime.AddDays(1),
                                                                                  to: baseTime.AddDays(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(60 * 24 * 1, queriedCandles.Count());

            // Read/write 1 candle
            new CandleHistoryRepository(storage).InsertOrMergeAsync(
                new FeedCandle()
            {
                DateTime = baseTime.AddHours(1), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 99
            }, asset, interval).Wait();

            var candle = new CandleHistoryRepository(storage).GetCandleAsync(asset, interval, true, baseTime.AddHours(1)).Result;

            Assert.True(candle.IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 60
            }));
        }
Пример #2
0
        public void WriteReadHours()
        {
            var      interval = TimeInterval.Hour;
            var      logger   = new LogToMemory();
            var      storage  = CreateStorage <CandleTableEntity>(logger);
            var      repo     = new CandleHistoryRepository(storage);
            DateTime baseTime = new DateTime(2017, 03, 01, 0, 0, 0, DateTimeKind.Utc);

            var candlesIn = from i in Enumerable.Range(0, 24 * 31 * 3) // 3 months
                            select new FeedCandle()
            {
                DateTime = baseTime.AddHours(i), Open = i, Close = i, High = i, Low = i
            };

            repo.InsertOrMergeAsync(candlesIn, PriceType.Bid, interval).Wait();

            // Select for 1 day
            var queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Bid, interval,
                                                                                      @from: baseTime.AddDays(1),
                                                                                      to: baseTime.AddDays(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(24, queriedCandles.Count());

            Assert.True(queriedCandles.First().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddDays(1), IsBuy = true, Open = 24, Close = 24, High = 24, Low = 24
            }));
            Assert.True(queriedCandles.Last().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddDays(1).AddHours(23), IsBuy = true, Open = 47, Close = 47, High = 47, Low = 47
            }));

            // Select for 1 month
            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Bid, interval,
                                                                                  @from: baseTime.AddMonths(1),
                                                                                  to: baseTime.AddMonths(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(24 * 30, queriedCandles.Count());

            // Read/write 1 candle
            new CandleHistoryRepository(storage).InsertOrMergeAsync(
                new FeedCandle()
            {
                DateTime = baseTime.AddDays(1), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 99
            }, PriceType.Bid, interval).Wait();

            var candle = new CandleHistoryRepository(storage).GetCandleAsync(PriceType.Bid, interval, baseTime.AddDays(1)).Result;

            Assert.True(candle.IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddDays(1), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 24
            }));
        }
Пример #3
0
        public void WriteRead30Minutes()
        {
            var      interval = TimeInterval.Min30;
            var      logger   = new LogToMemory();
            var      storage  = CreateStorage <CandleTableEntity>(logger);
            var      repo     = new CandleHistoryRepository(storage);
            DateTime baseTime = new DateTime(2017, 03, 01, 0, 0, 0, DateTimeKind.Utc);

            var candlesIn = from i in Enumerable.Range(0, 2 * 24 * 3) // 3 days
                            select new FeedCandle()
            {
                DateTime = baseTime.AddMinutes(30 * i), Open = i, Close = i, High = i, Low = i
            };

            repo.InsertOrMergeAsync(candlesIn, PriceType.Mid, interval).Wait();

            // Select for 1 hour
            var queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Mid, interval,
                                                                                      @from: baseTime.AddHours(1),
                                                                                      to: baseTime.AddHours(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(2, queriedCandles.Count());

            Assert.True(queriedCandles.First().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1), Open = 2, Close = 2, High = 2, Low = 2
            }));
            Assert.True(queriedCandles.Last().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1).AddMinutes(30), Open = 3, Close = 3, High = 3, Low = 3
            }));

            // Select for 1 day
            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Mid, interval,
                                                                                  @from: baseTime.AddDays(1),
                                                                                  to: baseTime.AddDays(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(2 * 24, queriedCandles.Count());

            // Read/write 1 candle
            new CandleHistoryRepository(storage).InsertOrMergeAsync(
                new FeedCandle()
            {
                DateTime = baseTime.AddHours(1), Open = 99, Close = 99, High = 99, Low = 99
            }, PriceType.Mid, interval).Wait();

            var candle = new CandleHistoryRepository(storage).GetCandleAsync(PriceType.Mid, interval, baseTime.AddHours(1)).Result;

            Assert.True(candle.IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1), Open = 99, Close = 99, High = 99, Low = 2
            }));
        }
Пример #4
0
        public void WriteReadWeeks()
        {
            var      asset    = "EURUSD";
            var      interval = TimeInterval.Week;
            var      logger   = new LogToMemory();
            var      storage  = CreateStorage <CandleTableEntity>(logger);
            DateTime baseTime = new DateTime(2016, 12, 26, 0, 0, 0, DateTimeKind.Utc);

            var candlesIn = from i in Enumerable.Range(0, 54 * 3) // > 3 years
                            select new FeedCandle()
            {
                DateTime = baseTime.AddDays(7 * i), IsBuy = true, Open = i, Close = i, High = i, Low = i
            };

            new CandleHistoryRepository(storage).InsertOrMergeAsync(candlesIn, asset, interval).Wait();

            // Select for 1 month
            var queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(asset, interval, true,
                                                                                      from: baseTime,
                                                                                      to: baseTime.AddDays(28)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(4, queriedCandles.Count());

            Assert.True(queriedCandles.First().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime, IsBuy = true, Open = 0, Close = 0, High = 0, Low = 0
            }));
            Assert.True(queriedCandles.Last().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddDays(21), IsBuy = true, Open = 3, Close = 3, High = 3, Low = 3
            }));

            // Select for 1 year
            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(asset, interval, true,
                                                                                  from: new DateTime(2017, 12, 25),
                                                                                  to: new DateTime(2017, 12, 25).AddDays(364)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(52, queriedCandles.Count());

            // Read/write 1 candle
            new CandleHistoryRepository(storage).InsertOrMergeAsync(
                new FeedCandle()
            {
                DateTime = baseTime.AddDays(21), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 99
            }, asset, interval).Wait();

            var candle = new CandleHistoryRepository(storage).GetCandleAsync(asset, interval, true, baseTime.AddDays(21)).Result;

            Assert.True(candle.IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddDays(21), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 3
            }));
        }
Пример #5
0
        public void WriteReadDays()
        {
            var      asset    = "EURUSD";
            var      interval = TimeInterval.Day;
            var      logger   = new LogToMemory();
            var      storage  = CreateStorage <CandleTableEntity>(logger);
            DateTime baseTime = new DateTime(2017, 03, 01, 0, 0, 0, DateTimeKind.Utc);

            var candlesIn = from i in Enumerable.Range(0, 31 * 12 * 3) // > 3 years
                            select new FeedCandle()
            {
                DateTime = baseTime.AddDays(i), IsBuy = true, Open = i, Close = i, High = i, Low = i
            };

            new CandleHistoryRepository(storage).InsertOrMergeAsync(candlesIn, asset, interval).Wait();

            // Select for 1 month
            var queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(asset, interval, true,
                                                                                      from: baseTime.AddMonths(1),
                                                                                      to: baseTime.AddMonths(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(30, queriedCandles.Count());

            Assert.True(queriedCandles.First().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddMonths(1), IsBuy = true, Open = 31, Close = 31, High = 31, Low = 31
            }));
            Assert.True(queriedCandles.Last().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddMonths(1).AddDays(29), IsBuy = true, Open = 60, Close = 60, High = 60, Low = 60
            }));

            // Select for 1 year
            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(asset, interval, true,
                                                                                  from: baseTime.AddYears(1),
                                                                                  to: baseTime.AddYears(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(365, queriedCandles.Count());

            // Read/write 1 candle
            new CandleHistoryRepository(storage).InsertOrMergeAsync(
                new FeedCandle()
            {
                DateTime = baseTime.AddMonths(1), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 99
            }, asset, interval).Wait();

            var candle = new CandleHistoryRepository(storage).GetCandleAsync(asset, interval, true, baseTime.AddMonths(1)).Result;

            Assert.True(candle.IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddMonths(1), IsBuy = true, Open = 99, Close = 99, High = 99, Low = 31
            }));
        }
Пример #6
0
        public void WriteReadSeconds()
        {
            var      interval = TimeInterval.Sec;
            var      logger   = new LogToMemory();
            var      storage  = CreateStorage <CandleTableEntity>(logger);
            DateTime baseTime = new DateTime(2017, 03, 01, 0, 0, 0, DateTimeKind.Utc);

            var candlesIn = from i in Enumerable.Range(0, 3600 * 3) // 3 hours
                            select new FeedCandle()
            {
                DateTime = baseTime.AddSeconds(i), Open = i, Close = i, High = i, Low = i
            };

            new CandleHistoryRepository(storage).InsertOrMergeAsync(candlesIn, PriceType.Ask, interval).Wait();

            // Select for 1 minute

            var queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Ask, interval,
                                                                                      @from: baseTime.AddHours(1).AddMinutes(1),
                                                                                      to: baseTime.AddHours(1).AddMinutes(2)).Result;

            Assert.NotNull(queriedCandles);
            Assert.Equal(60, queriedCandles.Count());

            Assert.True(queriedCandles.First().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1).AddMinutes(1), Open = 3660, Close = 3660, High = 3660, Low = 3660
            }));
            Assert.True(queriedCandles.Last().IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddHours(1).AddMinutes(1).AddSeconds(59), Open = 3719, Close = 3719, High = 3719, Low = 3719
            }));

            // Select for 1 hour

            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Ask, interval,
                                                                                  @from: baseTime.AddHours(1),
                                                                                  to: baseTime.AddHours(2)).Result;
            Assert.NotNull(queriedCandles);
            Assert.Equal(3600, queriedCandles.Count());

            // Select for 2 hours

            queriedCandles = new CandleHistoryRepository(storage).GetCandlesAsync(PriceType.Ask, interval,
                                                                                  @from: baseTime,
                                                                                  to: baseTime.AddHours(2)).Result;
            Assert.NotNull(queriedCandles);
            Assert.Equal(7200, queriedCandles.Count());

            //  Read / write 1 candle
            new CandleHistoryRepository(storage).InsertOrMergeAsync(
                new FeedCandle()
            {
                DateTime = baseTime.AddMinutes(1), Open = 99, Close = 99, High = 99, Low = 99
            }, PriceType.Ask, interval).Wait();

            var candle = new CandleHistoryRepository(storage).GetCandleAsync(PriceType.Ask, interval, baseTime.AddMinutes(1)).Result;

            Assert.True(candle.IsEqual(
                            new FeedCandle()
            {
                DateTime = baseTime.AddMinutes(1), Open = 99, Close = 99, High = 99, Low = 60
            }));
        }