/*
* 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
{
///
/// Represents the simplest DataConsolidator implementation, one that is defined
/// by a straight pass through of the data. No projection or aggregation is performed.
///
/// The type of data
public class IdentityDataConsolidator : DataConsolidator
where T : IBaseData
{
private static readonly bool IsTick = typeof(T) == typeof(Tick);
private T _last;
///
/// Stores the timestamp of the last processed data item.
///
private DateTime _lastTime;
///
/// Gets a clone of the data being currently consolidated
///
public override IBaseData WorkingData
{
get { return _last == null ? null : _last.Clone(); }
}
///
/// Gets the type produced by this consolidator
///
public override Type OutputType
{
get { return typeof(T); }
}
///
/// Updates this consolidator with the specified data
///
/// The new data for the consolidator
public override void Update(T data)
{
if (IsTick || _last == null || data.EndTime != _lastTime)
{
OnDataConsolidated(data);
_last = data;
_lastTime = data.EndTime;
}
}
///
/// Scans this consolidator to see if it should emit a bar due to time passing
///
/// The current time in the local time zone (same as )
public override void Scan(DateTime currentLocalTime)
{
}
///
/// Resets the consolidator
///
public override void Reset()
{
base.Reset();
_last = default(T);
}
}
}