Lean  $LEAN_TAG$
NullDataFeed.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 
17 using System;
21 using QuantConnect.Packets;
22 
24 {
25  /// <summary>
26  /// Null data feed implementation. <seealso cref="DataManager"/>
27  /// </summary>
28  public class NullDataFeed : IDataFeed
29  {
30  /// <summary>
31  /// Allows specifying if this implementation should throw always or not
32  /// </summary>
33  public bool ShouldThrow { get; set; } = true;
34 
35  /// <inheritdoc />
36  public bool IsActive
37  {
38  get
39  {
40  if (!ShouldThrow)
41  {
42  return true;
43  }
44  throw new NotImplementedException("Unexpected usage of null data feed implementation.");
45  }
46  }
47 
48  /// <inheritdoc />
49  public void Initialize(
50  IAlgorithm algorithm,
52  IResultHandler resultHandler,
53  IMapFileProvider mapFileProvider,
54  IFactorFileProvider factorFileProvider,
55  IDataProvider dataProvider,
56  IDataFeedSubscriptionManager subscriptionManager,
57  IDataFeedTimeProvider dataFeedTimeProvider,
58  IDataChannelProvider dataChannelProvider
59  )
60  {
61  if (!ShouldThrow)
62  {
63  return;
64  }
65  throw new NotImplementedException("Unexpected usage of null data feed implementation.");
66  }
67 
68  /// <inheritdoc />
70  {
71  if (!ShouldThrow)
72  {
73  return null;
74  }
75  throw new NotImplementedException("Unexpected usage of null data feed implementation.");
76  }
77 
78  /// <inheritdoc />
79  public void RemoveSubscription(Subscription subscription)
80  {
81  if (!ShouldThrow)
82  {
83  return;
84  }
85  throw new NotImplementedException("Unexpected usage of null data feed implementation.");
86  }
87 
88  /// <inheritdoc />
89  public void Exit()
90  {
91  if (!ShouldThrow)
92  {
93  return;
94  }
95  throw new NotImplementedException("Unexpected usage of null data feed implementation.");
96  }
97  }
98 }