Lean
$LEAN_TAG$
BaseScheduleRules.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
NodaTime;
18
using
QuantConnect
.
Securities
;
19
20
namespace
QuantConnect.Scheduling
21
{
22
/// <summary>
23
/// Base rule scheduler
24
/// </summary>
25
public
class
BaseScheduleRules
26
{
27
/// <summary>
28
/// The algorithm's default time zone
29
/// </summary>
30
protected
DateTimeZone
TimeZone
{
get
;
set
; }
31
32
/// <summary>
33
/// The security manager
34
/// </summary>
35
protected
SecurityManager
Securities
{
get
;
set
; }
36
37
/// <summary>
38
/// The market hours database instance to use
39
/// </summary>
40
protected
MarketHoursDatabase
MarketHoursDatabase
{
get
;
set
; }
41
42
/// <summary>
43
/// Initializes a new instance of the <see cref="TimeRules"/> helper class
44
/// </summary>
45
/// <param name="securities">The security manager</param>
46
/// <param name="timeZone">The algorithm's default time zone</param>
47
/// <param name="marketHoursDatabase">The market hours database instance to use</param>
48
public
BaseScheduleRules
(
SecurityManager
securities, DateTimeZone timeZone,
MarketHoursDatabase
marketHoursDatabase)
49
{
50
Securities
= securities;
51
TimeZone
= timeZone;
52
MarketHoursDatabase
= marketHoursDatabase;
53
}
54
55
/// <summary>
56
/// Helper method to fetch the security exchange hours
57
/// </summary>
58
protected
SecurityExchangeHours
GetSecurityExchangeHours
(
Symbol
symbol)
59
{
60
if
(!
Securities
.
TryGetValue
(symbol, out var security))
61
{
62
return
MarketHoursDatabase
.
GetEntry
(symbol.
ID
.
Market
, symbol, symbol.
SecurityType
).
ExchangeHours
;
63
}
64
return
security.Exchange.Hours;
65
}
66
}
67
}
Common
Scheduling
BaseScheduleRules.cs
Generated by
1.8.17