Lean  $LEAN_TAG$
DataConsolidatorPythonWrapper.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;
17 using Python.Runtime;
18 using QuantConnect.Data;
20 
21 namespace QuantConnect.Python
22 {
23  /// <summary>
24  /// Provides an Data Consolidator that wraps a <see cref="PyObject"/> object that represents a custom Python consolidator
25  /// </summary>
27  {
28  internal PyObject Model => Instance;
29 
30  /// <summary>
31  /// Gets the most recently consolidated piece of data. This will be null if this consolidator
32  /// has not produced any data yet.
33  /// </summary>
34  public IBaseData Consolidated
35  {
36  get { return GetProperty<IBaseData>(nameof(Consolidated)); }
37  }
38 
39  /// <summary>
40  /// Gets a clone of the data being currently consolidated
41  /// </summary>
42  public IBaseData WorkingData
43  {
44  get { return GetProperty<IBaseData>(nameof(WorkingData)); }
45  }
46 
47  /// <summary>
48  /// Gets the type consumed by this consolidator
49  /// </summary>
50  public Type InputType
51  {
52  get { return GetProperty<Type>(nameof(InputType)); }
53  }
54 
55  /// <summary>
56  /// Gets the type produced by this consolidator
57  /// </summary>
58  public Type OutputType
59  {
60  get { return GetProperty<Type>(nameof(OutputType)); }
61  }
62 
63  /// <summary>
64  /// Event handler that fires when a new piece of data is produced
65  /// </summary>
67  {
68  add
69  {
70  var eventHandler = GetEvent(nameof(DataConsolidated));
71  eventHandler += value;
72  }
73  remove
74  {
75  var eventHandler = GetEvent(nameof(DataConsolidated));
76  eventHandler -= value;
77  }
78  }
79 
80  /// <summary>
81  /// Constructor for initialising the <see cref="DataConsolidatorPythonWrapper"/> class with wrapped <see cref="PyObject"/> object
82  /// </summary>
83  /// <param name="consolidator">Represents a custom python consolidator</param>
84  public DataConsolidatorPythonWrapper(PyObject consolidator)
85  : base(consolidator, true)
86  {
87  }
88 
89  /// <summary>
90  /// Scans this consolidator to see if it should emit a bar due to time passing
91  /// </summary>
92  /// <param name="currentLocalTime">The current time in the local time zone (same as <see cref="BaseData.Time"/>)</param>
93  public void Scan(DateTime currentLocalTime)
94  {
95  InvokeMethod(nameof(Scan), currentLocalTime);
96  }
97 
98  /// <summary>
99  /// Updates this consolidator with the specified data
100  /// </summary>
101  /// <param name="data">The new data for the consolidator</param>
102  public void Update(IBaseData data)
103  {
104  InvokeMethod(nameof(Update), data);
105  }
106 
107  /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
108  /// <filterpriority>2</filterpriority>
109  public void Dispose()
110  {
111  }
112  }
113 }