Lean  $LEAN_TAG$
HistoryRequest.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;
18 using NodaTime;
20 using System.Collections.Generic;
21 
22 namespace QuantConnect.Data
23 {
24  /// <summary>
25  /// Represents a request for historical data
26  /// </summary>
28  {
29  private Resolution? _fillForwardResolution;
30 
31  /// <summary>
32  /// Gets the symbol to request data for
33  /// </summary>
34  public Symbol Symbol { get; set; }
35 
36  /// <summary>
37  /// Gets the requested data resolution
38  /// </summary>
39  public Resolution Resolution { get; set; }
40 
41  /// <summary>
42  /// Gets the requested fill forward resolution, set to null for no fill forward behavior.
43  /// Will always return null when Resolution is set to Tick.
44  /// </summary>
46  {
47  get
48  {
49  return Resolution == Resolution.Tick ? null : _fillForwardResolution;
50  }
51  set
52  {
53  _fillForwardResolution = value;
54  }
55  }
56 
57  /// <summary>
58  /// Gets whether or not to include extended market hours data, set to false for only normal market hours
59  /// </summary>
60  public bool IncludeExtendedMarketHours { get; set; }
61 
62  /// <summary>
63  /// Gets the data type used to process the subscription request, this type must derive from BaseData
64  /// </summary>
65  public Type DataType { get; set; }
66 
67  /// <summary>
68  /// Gets the time zone of the time stamps on the raw input data
69  /// </summary>
70  public DateTimeZone DataTimeZone { get; set; }
71 
72  /// <summary>
73  /// TickType of the history request
74  /// </summary>
75  public TickType TickType { get; set; }
76 
77  /// <summary>
78  /// Gets true if this is a custom data request, false for normal QC data
79  /// </summary>
80  public bool IsCustomData { get; set; }
81 
82  /// <summary>
83  /// Gets the normalization mode used for this subscription
84  /// </summary>
86 
87  /// <summary>
88  /// Gets the data mapping mode used for this subscription
89  /// </summary>
90  public DataMappingMode DataMappingMode { get; set; }
91 
92  /// <summary>
93  /// The continuous contract desired offset from the current front month.
94  /// For example, 0 (default) will use the front month, 1 will use the back month contract
95  /// </summary>
96  public uint ContractDepthOffset { get; set; }
97 
98  /// <summary>
99  /// Gets the tradable days specified by this request, in the security's data time zone
100  /// </summary>
103  EndTimeLocal,
104  DataTimeZone,
106 
107  /// <summary>
108  /// Initializes a new instance of the <see cref="HistoryRequest"/> class from the specified parameters
109  /// </summary>
110  /// <param name="startTimeUtc">The start time for this request,</param>
111  /// <param name="endTimeUtc">The end time for this request</param>
112  /// <param name="dataType">The data type of the output data</param>
113  /// <param name="symbol">The symbol to request data for</param>
114  /// <param name="resolution">The requested data resolution</param>
115  /// <param name="exchangeHours">The exchange hours used in fill forward processing</param>
116  /// <param name="dataTimeZone">The time zone of the data</param>
117  /// <param name="fillForwardResolution">The requested fill forward resolution for this request</param>
118  /// <param name="includeExtendedMarketHours">True to include data from pre/post market hours</param>
119  /// <param name="isCustomData">True for custom user data, false for normal QC data</param>
120  /// <param name="dataNormalizationMode">Specifies normalization mode used for this subscription</param>
121  /// <param name="tickType">The tick type used to created the <see cref="SubscriptionDataConfig"/> for the retrieval of history data</param>
122  /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
123  /// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
124  /// For example, 0 will use the front month, 1 will use the back month contract</param>
125  public HistoryRequest(DateTime startTimeUtc,
126  DateTime endTimeUtc,
127  Type dataType,
128  Symbol symbol,
129  Resolution resolution,
130  SecurityExchangeHours exchangeHours,
131  DateTimeZone dataTimeZone,
132  Resolution? fillForwardResolution,
133  bool includeExtendedMarketHours,
134  bool isCustomData,
135  DataNormalizationMode dataNormalizationMode,
136  TickType tickType,
137  DataMappingMode dataMappingMode = DataMappingMode.OpenInterest,
138  uint contractDepthOffset = 0)
139  : base(startTimeUtc, endTimeUtc, exchangeHours, tickType)
140  {
141  Symbol = symbol;
142  DataTimeZone = dataTimeZone;
143  Resolution = resolution;
144  FillForwardResolution = fillForwardResolution;
145  IncludeExtendedMarketHours = includeExtendedMarketHours;
146  DataType = dataType;
147  IsCustomData = isCustomData;
148  DataNormalizationMode = dataNormalizationMode;
149  TickType = tickType;
150  DataMappingMode = dataMappingMode;
151  ContractDepthOffset = contractDepthOffset;
152  }
153 
154  /// <summary>
155  /// Initializes a new instance of the <see cref="HistoryRequest"/> class from the specified config and exchange hours
156  /// </summary>
157  /// <param name="config">The subscription data config used to initialize this request</param>
158  /// <param name="hours">The exchange hours used for fill forward processing</param>
159  /// <param name="startTimeUtc">The start time for this request,</param>
160  /// <param name="endTimeUtc">The end time for this request</param>
161  public HistoryRequest(SubscriptionDataConfig config, SecurityExchangeHours hours, DateTime startTimeUtc, DateTime endTimeUtc)
162  : this(startTimeUtc, endTimeUtc, config.Type, config.Symbol, config.Resolution,
163  hours, config.DataTimeZone, config.FillDataForward ? config.Resolution : (Resolution?)null,
164  config.ExtendedMarketHours, config.IsCustomData, config.DataNormalizationMode, config.TickType, config.DataMappingMode, config.ContractDepthOffset)
165  {
166  }
167 
168  /// <summary>
169  /// Initializes a new instance of the <see cref="HistoryRequest"/> class with new Symbol, StartTimeUtc, EndTimeUtc
170  /// </summary>
171  /// <param name="request">Represents a request for historical data</param>
172  /// <param name="newStartTimeUtc">The start time for this request</param>
173  /// <param name="newEndTimeUtc">The end time for this request</param>
174  public HistoryRequest(HistoryRequest request, Symbol newSymbol, DateTime newStartTimeUtc, DateTime newEndTimeUtc)
175  : this (newStartTimeUtc, newEndTimeUtc, request.DataType, newSymbol, request.Resolution, request.ExchangeHours, request.DataTimeZone, request.FillForwardResolution,
177  { }
178  }
179 }