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 time zone of the time stamps on the raw input data
64  /// </summary>
65  public DateTimeZone DataTimeZone { get; set; }
66 
67  /// <summary>
68  /// TickType of the history request
69  /// </summary>
70  public TickType TickType { get; set; }
71 
72  /// <summary>
73  /// Gets the normalization mode used for this subscription
74  /// </summary>
76 
77  /// <summary>
78  /// Gets the data mapping mode used for this subscription
79  /// </summary>
80  public DataMappingMode DataMappingMode { get; set; }
81 
82  /// <summary>
83  /// The continuous contract desired offset from the current front month.
84  /// For example, 0 (default) will use the front month, 1 will use the back month contract
85  /// </summary>
86  public uint ContractDepthOffset { get; set; }
87 
88  /// <summary>
89  /// Gets the tradable days specified by this request, in the security's data time zone
90  /// </summary>
91  public override IEnumerable<DateTime> TradableDaysInDataTimeZone => Time.EachTradeableDayInTimeZone(ExchangeHours,
96 
97  /// <summary>
98  /// Initializes a new instance of the <see cref="HistoryRequest"/> class from the specified parameters
99  /// </summary>
100  /// <param name="startTimeUtc">The start time for this request,</param>
101  /// <param name="endTimeUtc">The end time for this request</param>
102  /// <param name="dataType">The data type of the output data</param>
103  /// <param name="symbol">The symbol to request data for</param>
104  /// <param name="resolution">The requested data resolution</param>
105  /// <param name="exchangeHours">The exchange hours used in fill forward processing</param>
106  /// <param name="dataTimeZone">The time zone of the data</param>
107  /// <param name="fillForwardResolution">The requested fill forward resolution for this request</param>
108  /// <param name="includeExtendedMarketHours">True to include data from pre/post market hours</param>
109  /// <param name="isCustomData">True for custom user data, false for normal QC data</param>
110  /// <param name="dataNormalizationMode">Specifies normalization mode used for this subscription</param>
111  /// <param name="tickType">The tick type used to created the <see cref="SubscriptionDataConfig"/> for the retrieval of history data</param>
112  /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
113  /// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
114  /// For example, 0 will use the front month, 1 will use the back month contract</param>
115  public HistoryRequest(DateTime startTimeUtc,
116  DateTime endTimeUtc,
117  Type dataType,
118  Symbol symbol,
119  Resolution resolution,
120  SecurityExchangeHours exchangeHours,
121  DateTimeZone dataTimeZone,
122  Resolution? fillForwardResolution,
123  bool includeExtendedMarketHours,
124  bool isCustomData,
125  DataNormalizationMode dataNormalizationMode,
126  TickType tickType,
127  DataMappingMode dataMappingMode = DataMappingMode.OpenInterest,
128  uint contractDepthOffset = 0)
129  : base(startTimeUtc, endTimeUtc, exchangeHours, tickType, isCustomData, dataType)
130  {
131  Symbol = symbol;
132  DataTimeZone = dataTimeZone;
133  Resolution = resolution;
134  FillForwardResolution = fillForwardResolution;
135  IncludeExtendedMarketHours = includeExtendedMarketHours;
136  DataNormalizationMode = dataNormalizationMode;
137  TickType = tickType;
138  DataMappingMode = dataMappingMode;
139  ContractDepthOffset = contractDepthOffset;
140  }
141 
142  /// <summary>
143  /// Initializes a new instance of the <see cref="HistoryRequest"/> class from the specified config and exchange hours
144  /// </summary>
145  /// <param name="config">The subscription data config used to initialize this request</param>
146  /// <param name="hours">The exchange hours used for fill forward processing</param>
147  /// <param name="startTimeUtc">The start time for this request,</param>
148  /// <param name="endTimeUtc">The end time for this request</param>
149  public HistoryRequest(SubscriptionDataConfig config, SecurityExchangeHours hours, DateTime startTimeUtc, DateTime endTimeUtc)
150  : this(startTimeUtc, endTimeUtc, config.Type, config.Symbol, config.Resolution,
151  hours, config.DataTimeZone, config.FillDataForward ? config.Resolution : (Resolution?)null,
152  config.ExtendedMarketHours, config.IsCustomData, config.DataNormalizationMode, config.TickType, config.DataMappingMode, config.ContractDepthOffset)
153  {
154  }
155 
156  /// <summary>
157  /// Initializes a new instance of the <see cref="HistoryRequest"/> class with new Symbol, StartTimeUtc, EndTimeUtc
158  /// </summary>
159  /// <param name="request">Represents a request for historical data</param>
160  /// <param name="newStartTimeUtc">The start time for this request</param>
161  /// <param name="newEndTimeUtc">The end time for this request</param>
162  public HistoryRequest(HistoryRequest request, Symbol newSymbol, DateTime newStartTimeUtc, DateTime newEndTimeUtc)
163  : this (newStartTimeUtc, newEndTimeUtc, request.DataType, newSymbol, request.Resolution, request.ExchangeHours, request.DataTimeZone, request.FillForwardResolution,
165  { }
166  }
167 }