Lean  $LEAN_TAG$
HistoryProviderBase.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 System.Collections.Generic;
18 using NodaTime;
20 
21 namespace QuantConnect.Data
22 {
23  /// <summary>
24  /// Provides a base type for all history providers
25  /// </summary>
26  public abstract class HistoryProviderBase : IHistoryProvider
27  {
28  /// <summary>
29  /// Event fired when an invalid configuration has been detected
30  /// </summary>
31  public event EventHandler<InvalidConfigurationDetectedEventArgs> InvalidConfigurationDetected;
32 
33  /// <summary>
34  /// Event fired when the numerical precision in the factor file has been limited
35  /// </summary>
36  public event EventHandler<NumericalPrecisionLimitedEventArgs> NumericalPrecisionLimited;
37 
38  /// <summary>
39  /// Event fired when the start date has been limited
40  /// </summary>
41  public event EventHandler<StartDateLimitedEventArgs> StartDateLimited;
42 
43  /// <summary>
44  /// Event fired when there was an error downloading a remote file
45  /// </summary>
46  public event EventHandler<DownloadFailedEventArgs> DownloadFailed;
47 
48  /// <summary>
49  /// Event fired when there was an error reading the data
50  /// </summary>
51  public event EventHandler<ReaderErrorDetectedEventArgs> ReaderErrorDetected;
52 
53  /// <summary>
54  /// Gets the total number of data points emitted by this history provider
55  /// </summary>
56  public abstract int DataPointCount { get; }
57 
58  /// <summary>
59  /// Initializes this history provider to work for the specified job
60  /// </summary>
61  /// <param name="parameters">The initialization parameters</param>
62  public abstract void Initialize(HistoryProviderInitializeParameters parameters);
63 
64  /// <summary>
65  /// Gets the history for the requested securities
66  /// </summary>
67  /// <param name="requests">The historical data requests</param>
68  /// <param name="sliceTimeZone">The time zone used when time stamping the slice instances</param>
69  /// <returns>An enumerable of the slices of data covering the span specified in each request</returns>
70  public abstract IEnumerable<Slice> GetHistory(IEnumerable<HistoryRequest> requests, DateTimeZone sliceTimeZone);
71 
72  /// <summary>
73  /// Event invocator for the <see cref="InvalidConfigurationDetected"/> event
74  /// </summary>
75  /// <param name="e">Event arguments for the <see cref="InvalidConfigurationDetected"/> event</param>
77  {
78  InvalidConfigurationDetected?.Invoke(this, e);
79  }
80 
81  /// <summary>
82  /// Event invocator for the <see cref="NumericalPrecisionLimited"/> event
83  /// </summary>
84  /// <param name="e">Event arguments for the <see cref="NumericalPrecisionLimited"/> event</param>
86  {
87  NumericalPrecisionLimited?.Invoke(this, e);
88  }
89 
90  /// <summary>
91  /// Event invocator for the <see cref="DownloadFailed"/> event
92  /// </summary>
93  /// <param name="e">Event arguments for the <see cref="DownloadFailed"/> event</param>
94  protected virtual void OnDownloadFailed(DownloadFailedEventArgs e)
95  {
96  DownloadFailed?.Invoke(this, e);
97  }
98 
99  /// <summary>
100  /// Event invocator for the <see cref="ReaderErrorDetected"/> event
101  /// </summary>
102  /// <param name="e">Event arguments for the <see cref="ReaderErrorDetected"/> event</param>
104  {
105  ReaderErrorDetected?.Invoke(this, e);
106  }
107 
108  /// <summary>
109  /// Event invocator for the <see cref="StartDateLimited"/> event
110  /// </summary>
111  /// <param name="e">Event arguments for the <see cref="StartDateLimited"/> event</param>
113  {
114  StartDateLimited?.Invoke(this, e);
115  }
116  }
117 }