public void SingleScheduledEventFires_ScanPastEvents()
        {
            var realTimeHandler = new BacktestingRealTimeHandler();
            var algo            = new TestAlgorithm();

            algo.SubscriptionManager.SetDataManager(new DataManagerStub(algo));
            algo.AddEquity("SPY");
            algo.SetStartDate(2019, 1, 1);
            algo.SetDateTime(new DateTime(2019, 1, 1));
            algo.SetEndDate(2020, 1, 1);
            realTimeHandler.Setup(algo,
                                  new AlgorithmNodePacket(PacketType.AlgorithmNode),
                                  new BacktestingResultHandler(),
                                  null,
                                  null);

            realTimeHandler.ScanPastEvents(DateTime.UtcNow);
            Assert.IsTrue(algo.OnEndOfDayFired);
        }
Exemple #2
0
        public void ScanPastEvents(bool oneStep)
        {
            var realTimeHandler = new BacktestingRealTimeHandler();

            realTimeHandler.Setup(new AlgorithmStub(),
                                  new AlgorithmNodePacket(PacketType.AlgorithmNode)
            {
                Language = Language.CSharp
            },
                                  _resultHandler,
                                  null,
                                  new TestTimeLimitManager());

            var date = new DateTime(2020, 1, 1);

            var count   = 0;
            var asserts = 0;

            realTimeHandler.Add(new ScheduledEvent("1",
                                                   new List <DateTime> {
                date, date.AddMinutes(10)
            },
                                                   (s, time) =>
            {
                count++;
                if (count == 1)
                {
                    asserts++;
                    Assert.AreEqual(date, time);
                }
                else if (count == 4)
                {
                    asserts++;
                    Assert.AreEqual(date.AddMinutes(10), time);
                }
            }));

            realTimeHandler.Add(new ScheduledEvent("2",
                                                   new List <DateTime> {
                date.AddMinutes(1), date.AddMinutes(2)
            },
                                                   (s, time) =>
            {
                count++;
                if (count == 2)
                {
                    asserts++;
                    Assert.AreEqual(date.AddMinutes(1), time);
                }
                else if (count == 3)
                {
                    asserts++;
                    Assert.AreEqual(date.AddMinutes(2), time);
                }
            }));

            if (oneStep)
            {
                realTimeHandler.ScanPastEvents(date.AddDays(1));
            }
            else
            {
                realTimeHandler.ScanPastEvents(date.AddMilliseconds(1));
                realTimeHandler.ScanPastEvents(date.AddMinutes(1).AddMilliseconds(1));
                realTimeHandler.ScanPastEvents(date.AddMinutes(2).AddMilliseconds(1));
                realTimeHandler.ScanPastEvents(date.AddMinutes(10).AddMilliseconds(1));
            }
            realTimeHandler.Exit();
            Assert.AreEqual(4, count);
            Assert.AreEqual(4, asserts);
        }