Lean  $LEAN_TAG$
CustomUniverse.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;
18 using System.Linq;
19 using QuantConnect.Data;
23 
25 {
26  /// <summary>
27  /// Defines a universe as a set of dynamically set symbols.
28  /// </summary>
30  {
31  /// <summary>
32  /// Creates a new instance of the <see cref="CustomUniverse"/>
33  /// </summary>
34  public CustomUniverse(SubscriptionDataConfig configuration,
35  UniverseSettings universeSettings,
36  TimeSpan interval,
37  Func<DateTime, IEnumerable<string>> selector)
38  : base(configuration, universeSettings, interval, selector)
39  {
40  }
41 
42  /// <summary>
43  /// Gets the subscription requests to be added for the specified security
44  /// </summary>
45  /// <param name="security">The security to get subscriptions for</param>
46  /// <param name="currentTimeUtc">The current time in utc. This is the frontier time of the algorithm</param>
47  /// <param name="maximumEndTimeUtc">The max end time</param>
48  /// <param name="subscriptionService">Instance which implements <see cref="ISubscriptionDataConfigService"/> interface</param>
49  /// <returns>All subscriptions required by this security</returns>
50  public override IEnumerable<SubscriptionRequest> GetSubscriptionRequests(Security security, DateTime currentTimeUtc, DateTime maximumEndTimeUtc,
51  ISubscriptionDataConfigService subscriptionService)
52  {
53  // CustomUniverse will return any existing SDC for the symbol, else will create new, using universe settings.
54  var existingSubscriptionDataConfigs = subscriptionService.GetSubscriptionDataConfigs(security.Symbol);
55 
56  if (existingSubscriptionDataConfigs.Any())
57  {
58  return existingSubscriptionDataConfigs.Select(
59  config => new SubscriptionRequest(isUniverseSubscription: false,
60  universe: this,
61  security: security,
62  configuration: config,
63  startTimeUtc: currentTimeUtc,
64  endTimeUtc: maximumEndTimeUtc));
65  }
66  return base.GetSubscriptionRequests(security, currentTimeUtc, maximumEndTimeUtc, subscriptionService);
67  }
68  }
69 }