Lean  $LEAN_TAG$
SubscriptionRequest.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 System.Collections.Generic;
19 
21 {
22  /// <summary>
23  /// Defines the parameters required to add a subscription to a data feed.
24  /// </summary>
26  {
27  /// <summary>
28  /// Gets true if the subscription is a universe
29  /// </summary>
30  public bool IsUniverseSubscription { get; }
31 
32  /// <summary>
33  /// Gets the universe this subscription resides in
34  /// </summary>
35  public Universe Universe { get; }
36 
37  /// <summary>
38  /// Gets the security. This is the destination of data for non-internal subscriptions.
39  /// </summary>
40  public Security Security { get; }
41 
42  /// <summary>
43  /// Gets the subscription configuration. This defines how/where to read the data.
44  /// </summary>
46 
47  /// <summary>
48  /// Gets the tradable days specified by this request, in the security's data time zone
49  /// </summary>
50  public override IEnumerable<DateTime> TradableDaysInDataTimeZone => Time.EachTradeableDayInTimeZone(ExchangeHours,
55 
56  /// <summary>
57  /// Initializes a new instance of the <see cref="SubscriptionRequest"/> class
58  /// </summary>
59  public SubscriptionRequest(bool isUniverseSubscription,
60  Universe universe,
61  Security security,
62  SubscriptionDataConfig configuration,
63  DateTime startTimeUtc,
64  DateTime endTimeUtc)
65  : base(startTimeUtc, endTimeUtc, security.Exchange.Hours, configuration.TickType, configuration.IsCustomData, configuration.Type)
66  {
67  IsUniverseSubscription = isUniverseSubscription;
68  Universe = universe;
69  Security = security;
70  Configuration = configuration;
71 
72  // open interest data comes in once a day before market open,
73  // make the subscription start from midnight and use always open exchange
74  if (Configuration.TickType == TickType.OpenInterest)
75  {
76  StartTimeUtc = StartTimeUtc.ConvertFromUtc(ExchangeHours.TimeZone).Date.ConvertToUtc(ExchangeHours.TimeZone);
77  }
78  }
79 
80  /// <summary>
81  /// Initializes a new instance of the <see cref="SubscriptionRequest"/> class
82  /// </summary>
84  bool? isUniverseSubscription = null,
85  Universe universe = null,
86  Security security = null,
87  SubscriptionDataConfig configuration = null,
88  DateTime? startTimeUtc = null,
89  DateTime? endTimeUtc = null
90  )
91  : this(isUniverseSubscription ?? template.IsUniverseSubscription,
92  universe ?? template.Universe,
93  security ?? template.Security,
94  configuration ?? template.Configuration,
95  startTimeUtc ?? template.StartTimeUtc,
96  endTimeUtc ?? template.EndTimeUtc
97  )
98  {
99  }
100  }
101 }