public void SequentialConsolidatorAcceptsSubTypesForSecondInputType() { var first = new IdentityDataConsolidator <TradeBar>(); var second = new IdentityDataConsolidator <BaseData>(); var sequential = new SequentialConsolidator(first, second); bool firstFired = false; bool secondFired = false; bool sequentialFired = false; first.DataConsolidated += (sender, consolidated) => { firstFired = true; }; second.DataConsolidated += (sender, consolidated) => { secondFired = true; }; sequential.DataConsolidated += (sender, consolidated) => { sequentialFired = true; }; sequential.Update(new TradeBar()); Assert.IsTrue(firstFired); Assert.IsTrue(secondFired); Assert.IsTrue(sequentialFired); }
public void SequentialConsolidatorsFiresAllEvents() { var first = new IdentityDataConsolidator<BaseData>(); var second = new IdentityDataConsolidator<BaseData>(); var sequential = new SequentialConsolidator(first, second); bool firstFired = false; bool secondFired = false; bool sequentialFired = false; first.DataConsolidated += (sender, consolidated) => { firstFired = true; }; second.DataConsolidated += (sender, consolidated) => { secondFired = true; }; sequential.DataConsolidated += (sender, consolidated) => { sequentialFired = true; }; sequential.Update(new TradeBar()); Assert.IsTrue(firstFired); Assert.IsTrue(secondFired); Assert.IsTrue(sequentialFired); }
public void SequentialConsolidatorAcceptsSubTypesForSecondInputType() { var first = new IdentityDataConsolidator<TradeBar>(); var second = new IdentityDataConsolidator<BaseData>(); var sequential = new SequentialConsolidator(first, second); bool firstFired = false; bool secondFired = false; bool sequentialFired = false; first.DataConsolidated += (sender, consolidated) => { firstFired = true; }; second.DataConsolidated += (sender, consolidated) => { secondFired = true; }; sequential.DataConsolidated += (sender, consolidated) => { sequentialFired = true; }; sequential.Update(new TradeBar()); Assert.IsTrue(firstFired); Assert.IsTrue(secondFired); Assert.IsTrue(sequentialFired); }
public void SequentialConsolidatorsFiresAllEvents() { var first = new IdentityDataConsolidator <BaseData>(); var second = new IdentityDataConsolidator <BaseData>(); var sequential = new SequentialConsolidator(first, second); bool firstFired = false; bool secondFired = false; bool sequentialFired = false; first.DataConsolidated += (sender, consolidated) => { firstFired = true; }; second.DataConsolidated += (sender, consolidated) => { secondFired = true; }; sequential.DataConsolidated += (sender, consolidated) => { sequentialFired = true; }; sequential.Update(new TradeBar()); Assert.IsTrue(firstFired); Assert.IsTrue(secondFired); Assert.IsTrue(sequentialFired); }
public void ThrowsOnDataOfWrongType() { Assert.Throws <ArgumentNullException>(() => { var identity = new IdentityDataConsolidator <Tick>(); identity.Update(new TradeBar()); }); }
/// <summary> /// Add new subscription to current <see cref="IDataAggregator"/> instance /// </summary> /// <param name="dataConfig">defines the parameters to subscribe to a data feed</param> /// <param name="newDataAvailableHandler">handler to be fired on new data available</param> /// <returns>The new enumerator for this subscription request</returns> public IEnumerator <BaseData> Add(SubscriptionDataConfig dataConfig, EventHandler newDataAvailableHandler) { IDataConsolidator consolidator; var period = dataConfig.Resolution.ToTimeSpan(); var isPeriodBased = false; switch (dataConfig.Type.Name) { case nameof(QuoteBar): isPeriodBased = dataConfig.Resolution != Resolution.Tick; consolidator = new TickQuoteBarConsolidator(period); break; case nameof(TradeBar): isPeriodBased = dataConfig.Resolution != Resolution.Tick; consolidator = new TickConsolidator(period); break; case nameof(OpenInterest): isPeriodBased = dataConfig.Resolution != Resolution.Tick; consolidator = new OpenInterestConsolidator(period); break; case nameof(Tick): consolidator = FilteredIdentityDataConsolidator.ForTickType(dataConfig.TickType); break; case nameof(Split): consolidator = new IdentityDataConsolidator <Split>(); break; case nameof(Dividend): consolidator = new IdentityDataConsolidator <Dividend>(); break; default: // streaming custom data subscriptions can pass right through consolidator = new FilteredIdentityDataConsolidator <BaseData>(data => data.GetType() == dataConfig.Type); break; } var enumerator = new ScannableEnumerator <BaseData>(consolidator, dataConfig.ExchangeTimeZone, TimeProvider, newDataAvailableHandler, isPeriodBased); _enumerators.AddOrUpdate( dataConfig.Symbol.ID, new List <KeyValuePair <SubscriptionDataConfig, ScannableEnumerator <BaseData> > > { new KeyValuePair <SubscriptionDataConfig, ScannableEnumerator <BaseData> >(dataConfig, enumerator) }, (k, v) => { return(v.Concat(new[] { new KeyValuePair <SubscriptionDataConfig, ScannableEnumerator <BaseData> >(dataConfig, enumerator) }).ToList()); }); return(enumerator); }
public void RemoveConsolidatorClearsEventHandlers() { bool eventHandlerFired = false; var algorithm = new QCAlgorithm(); var security = algorithm.AddEquity("SPY"); var consolidator = new IdentityDataConsolidator <BaseData>(); consolidator.DataConsolidated += (sender, consolidated) => eventHandlerFired = true; security.Subscriptions.First().Consolidators.Add(consolidator); algorithm.SubscriptionManager.RemoveConsolidator(security.Symbol, consolidator); consolidator.Update(new Tick()); Assert.IsFalse(eventHandlerFired); }
public void ReturnsTheSameObjectReference() { var identity = new IdentityDataConsolidator<Tick>(); var tick = new Tick(); int count = 0; identity.DataConsolidated += (sender, data) => { Assert.IsTrue(ReferenceEquals(tick, data)); count++; }; identity.Update(tick); Assert.AreEqual(1, count); }
public void ReturnsTheSameObjectReference() { var identity = new IdentityDataConsolidator <Tick>(); var tick = new Tick(); int count = 0; identity.DataConsolidated += (sender, data) => { Assert.IsTrue(ReferenceEquals(tick, data)); count++; }; identity.Update(tick); Assert.AreEqual(1, count); }
public void AcceptsTickDataWithSameTimestamps() { var reference = new DateTime(2015, 09, 23); var identity = new IdentityDataConsolidator<Tick>(); int count = 0; identity.DataConsolidated += (sender, data) => { count++; }; var tradeBar = new Tick { EndTime = reference }; identity.Update(tradeBar); tradeBar = (Tick)tradeBar.Clone(); identity.Update(tradeBar); Assert.AreEqual(2, count); }
public void AcceptsTickDataWithSameTimestamps() { var reference = new DateTime(2015, 09, 23); var identity = new IdentityDataConsolidator <Tick>(); int count = 0; identity.DataConsolidated += (sender, data) => { count++; }; var tradeBar = new Tick { EndTime = reference }; identity.Update(tradeBar); tradeBar = (Tick)tradeBar.Clone(); identity.Update(tradeBar); Assert.AreEqual(2, count); }
public void ThrowsOnDataOfWrongType() { var identity = new IdentityDataConsolidator<Tick>(); identity.Update(new TradeBar()); }
public void ThrowsOnDataOfWrongType() { var identity = new IdentityDataConsolidator <Tick>(); identity.Update(new TradeBar()); }