/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using QuantConnect.Data.Market; namespace QuantConnect.Data.Consolidators { /// /// Provides an implementation of that preserve the input /// data unmodified. The input data is filtering by the specified predicate function /// /// The type of data public class FilteredIdentityDataConsolidator : IdentityDataConsolidator where T : IBaseData { private readonly Func _predicate; /// /// Initializes a new instance of the class /// /// The predicate function, returning true to accept data and false to reject data public FilteredIdentityDataConsolidator(Func predicate) { this._predicate = predicate; } /// /// Updates this consolidator with the specified data /// /// The new data for the consolidator public override void Update(T data) { // only permit data that passes our predicate function to be passed through if (_predicate(data)) { base.Update(data); } } } /// /// Provides factory methods for creating instances of /// public static class FilteredIdentityDataConsolidator { /// /// Creates a new instance of that filters ticks /// based on the specified /// /// The tick type of data to accept /// A new that filters based on the provided tick type public static FilteredIdentityDataConsolidator ForTickType(TickType tickType) { return new FilteredIdentityDataConsolidator(tick => tick.TickType == tickType); } } }