public void EmitsData()
        {
            var algorithm = new AlgorithmStub(forex: new List <string> {
                "EURUSD"
            });

            // job is used to send into DataQueueHandler
            var job = new LiveNodePacket();
            // result handler is used due to dependency in SubscriptionDataReader
            var resultHandler = new BacktestingResultHandler();

            var lastTime         = DateTime.MinValue;
            var timeProvider     = new RealTimeProvider();
            var dataQueueHandler = new FuncDataQueueHandler(fdqh =>
            {
                var time = timeProvider.GetUtcNow().ConvertFromUtc(TimeZones.EasternStandard);
                if (time == lastTime)
                {
                    return(Enumerable.Empty <BaseData>());
                }
                lastTime = time;
                return(Enumerable.Range(0, 9).Select(x => new Tick(time.AddMilliseconds(x * 100), Symbols.EURUSD, 1.3m, 1.2m, 1.3m)));
            });

            var feed            = new TestableLiveTradingDataFeed(dataQueueHandler, timeProvider);
            var mapFileProvider = new LocalDiskMapFileProvider();

            feed.Initialize(algorithm, job, resultHandler, mapFileProvider, new LocalDiskFactorFileProvider(mapFileProvider));

            var feedThreadStarted = new ManualResetEvent(false);

            Task.Factory.StartNew(() =>
            {
                feedThreadStarted.Set();
                feed.Run();
            });

            // wait for feed.Run to actually begin
            feedThreadStarted.WaitOne();

            var emittedData = false;

            ConsumeBridge(feed, TimeSpan.FromSeconds(10), true, ts =>
            {
                if (ts.Slice.Count != 0)
                {
                    emittedData = true;
                    Console.WriteLine("HasData: " + ts.Slice.Bars[Symbols.EURUSD].EndTime);
                    Console.WriteLine();
                }
            });

            Assert.IsTrue(emittedData);
        }
 private static IEnumerable <BaseData> ProduceBenchmarkTicks(FuncDataQueueHandler fdqh, Count count)
 {
     for (int i = 0; i < 10000; i++)
     {
         foreach (var symbol in fdqh.Subscriptions)
         {
             count.Value++;
             yield return(new Tick {
                 Symbol = symbol
             });
         }
     }
 }
示例#3
0
        private static BaseDataExchange CreateExchange(ConcurrentQueue <BaseData> dataQueue)
        {
            var dataQueueHandler = new FuncDataQueueHandler(q =>
            {
                BaseData data;
                int count = 0;
                var list  = new List <BaseData>();
                while (++count < 10 && dataQueue.TryDequeue(out data))
                {
                    list.Add(data);
                }
                return(list);
            });
            var exchange = new BaseDataExchange("test");
            IEnumerator <BaseData> enumerator = GetNextTicksEnumerator(dataQueueHandler);
            var sym = Symbol.Create("data-queue-handler-symbol", SecurityType.Base, Market.USA);

            exchange.AddEnumerator(sym, enumerator, null, null);
            return(exchange);
        }