public void HandlesCoarseFundamentalData() { var algorithm = new AlgorithmStub(); Symbol symbol = CoarseFundamental.CreateUniverseSymbol(Market.USA); algorithm.SetUniverse(new FuncUniverse( new SubscriptionDataConfig(typeof(CoarseFundamental), symbol, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, false), new SubscriptionSettings(Resolution.Second, 1, true, false), coarse => coarse.Take(10).Select(x => x.Symbol) )); var lck = new object(); BaseDataCollection list = null; const int coarseDataPointCount = 100000; var timer = new Timer(state => { var currentTime = DateTime.UtcNow.ConvertFromUtc(TimeZones.NewYork); Console.WriteLine(currentTime + ": timer.Elapsed"); lock (state) { list = new BaseDataCollection { Symbol = symbol }; list.Data.AddRange(Enumerable.Range(0, coarseDataPointCount).Select(x => new CoarseFundamental { Symbol = SymbolCache.GetSymbol(x.ToString()), Time = currentTime - Time.OneDay, // hard-coded coarse period of one day })); } }, lck, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(500)); bool yieldedUniverseData = false; var feed = RunDataFeed(algorithm, fdqh => { lock (lck) { if (list != null) { try { var tmp = list; return(new List <BaseData> { tmp }); } finally { list = null; yieldedUniverseData = true; } } } return(Enumerable.Empty <BaseData>()); }); Assert.IsTrue(feed.Subscriptions.Any(x => x.IsUniverseSelectionSubscription)); var universeSelectionHadAllData = false; feed.UniverseSelection += (sender, args) => { universeSelectionHadAllData = args.Data.Count == coarseDataPointCount; Console.WriteLine(DateTime.UtcNow.ConvertFromUtc(TimeZones.NewYork).ToString("o") + ": Fired universe selection. Count: " + args.Data.Count); return(SecurityChanges.None); }; ConsumeBridge(feed, TimeSpan.FromSeconds(5), ts => { }); Assert.IsTrue(yieldedUniverseData); Assert.IsTrue(universeSelectionHadAllData); }
public void HandlesCoarseFundamentalData() { var algorithm = new AlgorithmStub(); Symbol symbol = "qc-universe-coarse-usa"; algorithm.SetUniverse(new FuncUniverse( new SubscriptionDataConfig(typeof(CoarseFundamental), SecurityType.Base, symbol, Resolution.Daily, "usa", TimeZones.NewYork, false, false, false), new SubscriptionSettings(Resolution.Second, 1, true, false), coarse => coarse.Take(10).Select(x => x.Symbol) )); var lck = new object(); BaseDataCollection list = null; const int coarseDataPointCount = 100000; var timer = new Timer(state => { var currentTime = DateTime.UtcNow.ConvertFromUtc(TimeZones.NewYork); Console.WriteLine(currentTime + ": timer.Elapsed"); lock (state) { list = new BaseDataCollection {Symbol = symbol}; list.Data.AddRange(Enumerable.Range(0, coarseDataPointCount).Select(x => new CoarseFundamental { Symbol = x.ToString(), Time = currentTime - Time.OneDay, // hard-coded coarse period of one day })); } }, lck, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(500)); bool yieldedUniverseData = false; var feed = RunDataFeed(algorithm, fdqh => { lock (lck) { if (list != null) try { var tmp = list; return new List<BaseData> { tmp }; } finally { list = null; yieldedUniverseData = true; } } return Enumerable.Empty<BaseData>(); }); Assert.IsTrue(feed.Subscriptions.Any(x => x.IsUniverseSelectionSubscription)); var universeSelectionHadAllData = false; feed.UniverseSelection += (sender, args) => { universeSelectionHadAllData = args.Data.Count == coarseDataPointCount; Console.WriteLine(DateTime.UtcNow.ConvertFromUtc(TimeZones.NewYork).ToString("o") + ": Fired universe selection. Count: " + args.Data.Count); }; ConsumeBridge(feed, TimeSpan.FromSeconds(5), ts => { }); Assert.IsTrue(yieldedUniverseData); Assert.IsTrue(universeSelectionHadAllData); }