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
/// Initializes the base data request
62
/// </summary>
63
/// <param name="startTimeUtc">The start time for this request,</param>
64
/// <param name="endTimeUtc">The start time for this request</param>
65
/// <param name="exchangeHours">The exchange hours for this request</param>
66
/// <param name="tickType">The tick type of this request</param>
67
protected
BaseDataRequest
(DateTime startTimeUtc,
68
DateTime endTimeUtc,
69
SecurityExchangeHours
exchangeHours,
70
TickType
tickType)
71
{
72
StartTimeUtc
= startTimeUtc;
73
EndTimeUtc
= endTimeUtc;
74
ExchangeHours
= exchangeHours;
75
76
// open interest data comes in once a day before market open,
77
// make the subscription start from midnight and use always open exchange
78
if
(tickType ==
TickType
.OpenInterest)
79
{
80
ExchangeHours
=
SecurityExchangeHours
.
AlwaysOpen
(
ExchangeHours
.
TimeZone
);
81
}
82
83
_localStartTime =
new
Lazy<DateTime>(() =>
StartTimeUtc
.ConvertFromUtc(
ExchangeHours
.
TimeZone
));
84
_localEndTime =
new
Lazy<DateTime>(() =>
EndTimeUtc
.ConvertFromUtc(
ExchangeHours
.
TimeZone
));
85
}
86
}
87
}
Common
Data
BaseDataRequest.cs
Generated by
1.8.17