예제 #1
0
        public async Task Run(SimulationOptions options)
        {
            var trades = await _storage.GetTrades(options.Asset, options.DateFrom, options.DateTo);

            //TODO:solve this to array
            await perioder.Periodify(trades.ToArray(), options.DateFrom, options.DateTo, options.PeriodLength,
                                     internalOnPeriod);

            async Task internalOnPeriod(DateTime periodDate, Trade trade)
            {
                _buffer.AddFirst(trade);

                if (_buffer.Count > BUFFER_LENGTH)
                {
                    _buffer.RemoveLast();
                }

                await OnPeriod(periodDate, trade);
            }
        }
예제 #2
0
        public async Task Should_Return_Latest_Trade_From_Period_When_All_Data_Match_In_One_Period()
        {
            //arrange
            int      periodLength = 10;
            DateTime periodStart  = new DateTime(2018, 10, 10, 10, 10, 0);
            DateTime periodEnd    = periodStart.AddMinutes(periodLength);

            var expected = new Trade()
            {
                Date = periodStart.AddMinutes(3), Rate = 1
            };

            Trade[] trades = new Trade[3]
            {
                new Trade()
                {
                    Date = periodStart.AddMinutes(1), Rate = 14
                },
                new Trade()
                {
                    Date = periodStart.AddMinutes(2), Rate = 122
                },
                expected
            };

            Perioder perioder          = new Perioder();
            int      numberOfexecution = 0;

            //act
            await perioder.Periodify(trades, periodStart, periodEnd, periodLength, OnPeriod);

            //assert
            Assert.Equal(1, numberOfexecution);

            Task OnPeriod(DateTime periodDate, Trade obj)
            {
                Assert.Equal(expected, obj);
                return(Task.FromResult(numberOfexecution++));
            }
        }
예제 #3
0
 public decimal Do()
 {
     _perioder.Periodify(_input, _startDate, _endDate, 5, (date, trade) => Task.FromResult(0)).Wait();
     return(2);
 }
예제 #4
0
        public async Task Should_Return_Latest_Trade_From_Period_For_Each_Period()
        {
            //arrange
            int      periodLength = 10;
            DateTime periodStart  = new DateTime(2018, 10, 10, 10, 10, 0);
            DateTime periodEnd    = periodStart.AddMinutes(3 * periodLength);


            Trade[] trades =
            {
                new Trade()
                {
                    Date = periodStart.AddMinutes(1), Rate = 14
                },
                new Trade()
                {
                    Date = periodStart.AddMinutes(4), Rate = 122
                },
                new Trade()
                {
                    Date = periodStart.AddMinutes(8), Rate = 1
                },
                //p
                new Trade()
                {
                    Date = periodStart.AddMinutes(12), Rate = 2
                },
                new Trade()
                {
                    Date = periodStart.AddMinutes(13), Rate = 3
                },
                new Trade()
                {
                    Date = periodStart.AddMinutes(14), Rate = 4
                },
                //p
                new Trade()
                {
                    Date = periodStart.AddMinutes(21), Rate = 5
                },
                new Trade()
                {
                    Date = periodStart.AddMinutes(22), Rate = 6
                }
            };

            Trade[] expectedOnPeriod =
            {
                new Trade()
                {
                    Date = periodStart.AddMinutes(8), Rate = 1
                },
                //p
                new Trade()
                {
                    Date = periodStart.AddMinutes(14), Rate = 4
                },
                //p
                new Trade()
                {
                    Date = periodStart.AddMinutes(22), Rate = 6
                }
            };

            Perioder perioder          = new Perioder();
            int      numberOfexecution = 0;

            //act
            await perioder.Periodify(trades, periodStart, periodEnd, periodLength, OnPeriod);

            //assert
            Assert.Equal(3, numberOfexecution);

            Task OnPeriod(DateTime periodDate, Trade obj)
            {
                numberOfexecution++;
                Assert.Equal(expectedOnPeriod[numberOfexecution - 1], obj);
                return(Task.FromResult(2));
            }
        }