Lean
$LEAN_TAG$
BaseDataRequest.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
QuantConnect
.
Securities
;
18
using
System.Collections.Generic;
19
20
namespace
QuantConnect.Data
21
{
22
/// <summary>
23
/// Abstract sharing logic for data requests
24
/// </summary>
25
public
abstract
class
BaseDataRequest
26
{
27
private
readonly Lazy<DateTime> _localStartTime;
28
private
readonly Lazy<DateTime> _localEndTime;
29
30
/// <summary>
31
/// Gets the beginning of the requested time interval in UTC
32
/// </summary>
33
public
DateTime
StartTimeUtc
{
get
;
protected
set
; }
34
35
/// <summary>
36
/// Gets the end of the requested time interval in UTC
37
/// </summary>
38
public
DateTime
EndTimeUtc
{
get
;
protected
set
; }
39
40
/// <summary>
41
/// Gets the <see cref="StartTimeUtc"/> in the security's exchange time zone
42
/// </summary>
43
public
DateTime
StartTimeLocal
=> _localStartTime.Value;
44
45
/// <summary>
46
/// Gets the <see cref="EndTimeUtc"/> in the security's exchange time zone
47
/// </summary>
48
public
DateTime
EndTimeLocal
=> _localEndTime.Value;
49
50
/// <summary>
51
/// Gets the exchange hours used for processing fill forward requests
52
/// </summary>
53
public
SecurityExchangeHours
ExchangeHours
{
get
; }
54
55
/// <summary>
56
/// Gets the tradable days specified by this request, in the security's data time zone
57
/// </summary>
58
public
abstract
IEnumerable<DateTime>
TradableDaysInDataTimeZone
{
get
; }
59
60
/// <summary>
61
/// Gets true if this is a custom data request, false for normal QC data
62
/// </summary>
63
public
bool
IsCustomData
{
get
; }
64
65
/// <summary>
66
/// The data type of this request
67
/// </summary>
68
public
Type
DataType
{
get
;
set
; }
69
70
/// <summary>
71
/// Initializes the base data request
72
/// </summary>
73
/// <param name="startTimeUtc">The start time for this request,</param>
74
/// <param name="endTimeUtc">The start time for this request</param>
75
/// <param name="exchangeHours">The exchange hours for this request</param>
76
/// <param name="tickType">The tick type of this request</param>
77
/// <param name="isCustomData">True if this subscription is for custom data</param>
78
/// <param name="dataType">The data type of the output data</param>
79
protected
BaseDataRequest
(DateTime startTimeUtc,
80
DateTime endTimeUtc,
81
SecurityExchangeHours
exchangeHours,
82
TickType
tickType,
83
bool
isCustomData,
84
Type dataType)
85
{
86
DataType
= dataType;
87
IsCustomData
= isCustomData;
88
StartTimeUtc
= startTimeUtc;
89
EndTimeUtc
= endTimeUtc;
90
ExchangeHours
= exchangeHours;
91
92
// open interest data comes in once a day before market open,
93
// make the subscription start from midnight and use always open exchange
94
if
(tickType ==
TickType
.OpenInterest)
95
{
96
ExchangeHours
=
SecurityExchangeHours
.
AlwaysOpen
(
ExchangeHours
.
TimeZone
);
97
}
98
99
_localStartTime =
new
Lazy<DateTime>(() =>
StartTimeUtc
.ConvertFromUtc(
ExchangeHours
.
TimeZone
));
100
_localEndTime =
new
Lazy<DateTime>(() =>
EndTimeUtc
.ConvertFromUtc(
ExchangeHours
.
TimeZone
));
101
IsCustomData
= isCustomData;
102
}
103
}
104
}
Common
Data
BaseDataRequest.cs
Generated by
1.8.17