Lean  $LEAN_TAG$
IdentityDataConsolidator.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
18 
20 {
21  /// <summary>
22  /// Represents the simplest DataConsolidator implementation, one that is defined
23  /// by a straight pass through of the data. No projection or aggregation is performed.
24  /// </summary>
25  /// <typeparam name="T">The type of data</typeparam>
27  where T : IBaseData
28  {
29  private static readonly bool IsTick = typeof (T) == typeof (Tick);
30 
31  private T _last;
32 
33  /// <summary>
34  /// Gets a clone of the data being currently consolidated
35  /// </summary>
36  public override IBaseData WorkingData
37  {
38  get { return _last == null ? null : _last.Clone(); }
39  }
40 
41  /// <summary>
42  /// Gets the type produced by this consolidator
43  /// </summary>
44  public override Type OutputType
45  {
46  get { return typeof (T); }
47  }
48 
49  /// <summary>
50  /// Updates this consolidator with the specified data
51  /// </summary>
52  /// <param name="data">The new data for the consolidator</param>
53  public override void Update(T data)
54  {
55  if (IsTick || _last == null || _last.EndTime != data.EndTime)
56  {
57  OnDataConsolidated(data);
58  _last = data;
59  }
60  }
61 
62  /// <summary>
63  /// Scans this consolidator to see if it should emit a bar due to time passing
64  /// </summary>
65  /// <param name="currentLocalTime">The current time in the local time zone (same as <see cref="BaseData.Time"/>)</param>
66  public override void Scan(DateTime currentLocalTime)
67  {
68  }
69  }
70 }