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 using QuantConnect.Util;
22 
23 namespace QuantConnect.Data
24 {
25  /// <summary>
26  /// Represents a request for historical data
27  /// </summary>
29  {
30  private Resolution? _fillForwardResolution;
31  private bool _includeExtendedMarketHours;
32 
33  /// <summary>
34  /// Gets the symbol to request data for
35  /// </summary>
36  public Symbol Symbol { get; set; }
37 
38  /// <summary>
39  /// Gets the requested data resolution
40  /// </summary>
41  public Resolution Resolution { get; set; }
42 
43  /// <summary>
44  /// Gets the requested fill forward resolution, set to null for no fill forward behavior.
45  /// Will always return null when Resolution is set to Tick.
46  /// </summary>
48  {
49  get
50  {
51  return Resolution == Resolution.Tick ? null : _fillForwardResolution;
52  }
53  set
54  {
55  _fillForwardResolution = value;
56  }
57  }
58 
59  /// <summary>
60  /// Gets whether or not to include extended market hours data, set to false for only normal market hours
61  /// </summary>
62  public bool IncludeExtendedMarketHours
63  {
64  get
65  {
66  return _includeExtendedMarketHours;
67  }
68  set
69  {
70  _includeExtendedMarketHours = value && LeanData.SupportsExtendedMarketHours(DataType);
71  }
72  }
73 
74  /// <summary>
75  /// Gets the time zone of the time stamps on the raw input data
76  /// </summary>
77  public DateTimeZone DataTimeZone { get; set; }
78 
79  /// <summary>
80  /// TickType of the history request
81  /// </summary>
82  public TickType TickType { get; set; }
83 
84  /// <summary>
85  /// Gets the normalization mode used for this subscription
86  /// </summary>
88 
89  /// <summary>
90  /// Gets the data mapping mode used for this subscription
91  /// </summary>
92  public DataMappingMode DataMappingMode { get; set; }
93 
94  /// <summary>
95  /// The continuous contract desired offset from the current front month.
96  /// For example, 0 (default) will use the front month, 1 will use the back month contract
97  /// </summary>
98  public uint ContractDepthOffset { get; set; }
99 
100  /// <summary>
101  /// Gets the tradable days specified by this request, in the security's data time zone
102  /// </summary>
105  EndTimeLocal,
106  DataTimeZone,
108 
109  /// <summary>
110  /// Initializes a new instance of the <see cref="HistoryRequest"/> class from the specified parameters
111  /// </summary>
112  /// <param name="startTimeUtc">The start time for this request,</param>
113  /// <param name="endTimeUtc">The end time for this request</param>
114  /// <param name="dataType">The data type of the output data</param>
115  /// <param name="symbol">The symbol to request data for</param>
116  /// <param name="resolution">The requested data resolution</param>
117  /// <param name="exchangeHours">The exchange hours used in fill forward processing</param>
118  /// <param name="dataTimeZone">The time zone of the data</param>
119  /// <param name="fillForwardResolution">The requested fill forward resolution for this request</param>
120  /// <param name="includeExtendedMarketHours">True to include data from pre/post market hours</param>
121  /// <param name="isCustomData">True for custom user data, false for normal QC data</param>
122  /// <param name="dataNormalizationMode">Specifies normalization mode used for this subscription</param>
123  /// <param name="tickType">The tick type used to created the <see cref="SubscriptionDataConfig"/> for the retrieval of history data</param>
124  /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
125  /// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
126  /// For example, 0 will use the front month, 1 will use the back month contract</param>
127  public HistoryRequest(DateTime startTimeUtc,
128  DateTime endTimeUtc,
129  Type dataType,
130  Symbol symbol,
131  Resolution resolution,
132  SecurityExchangeHours exchangeHours,
133  DateTimeZone dataTimeZone,
134  Resolution? fillForwardResolution,
135  bool includeExtendedMarketHours,
136  bool isCustomData,
137  DataNormalizationMode dataNormalizationMode,
138  TickType tickType,
139  DataMappingMode dataMappingMode = DataMappingMode.OpenInterest,
140  uint contractDepthOffset = 0)
141  : base(startTimeUtc, endTimeUtc, exchangeHours, tickType, isCustomData, dataType)
142  {
143  Symbol = symbol;
144  DataTimeZone = dataTimeZone;
145  Resolution = resolution;
146  FillForwardResolution = fillForwardResolution;
147  IncludeExtendedMarketHours = includeExtendedMarketHours;
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 }