public void HandlesRestApi()
        {
            var resolution = Resolution.Second;
            var algorithm  = new AlgorithmStub();

            algorithm.AddData <RestApiBaseData>("RestApi", resolution);
            var symbol = SymbolCache.GetSymbol("RestApi");
            FuncDataQueueHandler dqgh;
            var timeProvider = new ManualTimeProvider(new DateTime(2015, 10, 10, 16, 36, 0));
            var feed         = RunDataFeed(algorithm, out dqgh, null);

            var             count        = 0;
            var             receivedData = false;
            var             timeZone     = algorithm.Securities[symbol].Exchange.TimeZone;
            RestApiBaseData last         = null;

            var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));

            foreach (var ts in feed)
            {
                //timeProvider.AdvanceSeconds(0.5);

                if (!ts.Slice.ContainsKey(symbol))
                {
                    return;
                }

                count++;
                receivedData = true;
                var data = (RestApiBaseData)ts.Slice[symbol];
                var time = data.EndTime.ConvertToUtc(timeZone);
                Console.WriteLine(DateTime.UtcNow + ": Data time: " + time.ConvertFromUtc(TimeZones.NewYork) + Environment.NewLine);
                if (last != null)
                {
                    Assert.AreEqual(last.EndTime, data.EndTime.Subtract(resolution.ToTimeSpan()));
                }
                last = data;
            }

            // even though we're doing 10 seconds, give a little
            // leeway for slow internet traffic
            Assert.That(count, Is.GreaterThanOrEqualTo(8));
            Assert.IsTrue(receivedData);
            Assert.That(RestApiBaseData.ReaderCount, Is.LessThanOrEqualTo(30)); // we poll at 10x frequency

            Console.WriteLine("Count: " + count + " ReaderCount: " + RestApiBaseData.ReaderCount);
        }
Esempio n. 2
0
        public void HandlesRestApi()
        {
            var resolution = Resolution.Second;
            var symbol     = SymbolCache.GetSymbol("RestApi");
            FuncDataQueueHandler dqgh;
            var feed = RunDataFeed(out dqgh);

            _algorithm.AddData <RestApiBaseData>("RestApi", resolution);

            var             count        = 0;
            var             receivedData = false;
            var             timeZone     = _algorithm.Securities[symbol].Exchange.TimeZone;
            RestApiBaseData last         = null;

            var cancellationTokenSource = new CancellationTokenSource();

            foreach (var ts in _synchronizer.StreamData(cancellationTokenSource.Token))
            {
                if (!ts.Slice.ContainsKey(symbol))
                {
                    return;
                }

                count++;
                receivedData = true;
                var data = (RestApiBaseData)ts.Slice[symbol];
                var time = data.EndTime.ConvertToUtc(timeZone);
                ConsoleWriteLine(DateTime.UtcNow + ": Data time: " + time.ConvertFromUtc(TimeZones.NewYork) + Environment.NewLine);
                if (last != null)
                {
                    Assert.AreEqual(last.EndTime, data.EndTime.Subtract(resolution.ToTimeSpan()));
                }
                last = data;
            }

            feed.Exit();
            Assert.That(count, Is.GreaterThanOrEqualTo(8));
            Assert.IsTrue(receivedData);
            Assert.That(RestApiBaseData.ReaderCount, Is.LessThanOrEqualTo(30)); // we poll at 10x frequency

            Console.WriteLine("Count: " + count + " ReaderCount: " + RestApiBaseData.ReaderCount);
        }