Lean  $LEAN_TAG$
FuturesChainUniverse.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 System;
18 using System.Collections.Generic;
19 using System.Linq;
22 
24 {
25  /// <summary>
26  /// Defines a universe for a single futures chain
27  /// </summary>
29  {
30  /// <summary>
31  /// True if this universe filter can run async in the data stack
32  /// </summary>
33  public override bool Asynchronous
34  {
35  get
36  {
37  if (UniverseSettings.Asynchronous.HasValue)
38  {
39  return UniverseSettings.Asynchronous.Value;
40  }
41  return Future.ContractFilter.Asynchronous;
42  }
43  }
44 
45  /// <summary>
46  /// Initializes a new instance of the <see cref="FuturesChainUniverse"/> class
47  /// </summary>
48  /// <param name="future">The canonical future chain security</param>
49  /// <param name="universeSettings">The universe settings to be used for new subscriptions</param>
51  UniverseSettings universeSettings)
52  : base(future.SubscriptionDataConfig)
53  {
54  Future = future;
55  UniverseSettings = universeSettings;
56  }
57 
58  /// <summary>
59  /// The canonical future chain security
60  /// </summary>
61  public Future Future { get; }
62 
63  /// <summary>
64  /// Gets the settings used for subscriptons added for this universe
65  /// </summary>
66  public override UniverseSettings UniverseSettings
67  {
68  set
69  {
70  if (value != null)
71  {
72  // make sure data mode is raw
74  }
75  }
76  }
77 
78  /// <summary>
79  /// Performs universe selection using the data specified
80  /// </summary>
81  /// <param name="utcTime">The current utc time</param>
82  /// <param name="data">The symbols to remain in the universe</param>
83  /// <returns>The data that passes the filter</returns>
84  public override IEnumerable<Symbol> SelectSymbols(DateTime utcTime, BaseDataCollection data)
85  {
86  var localEndTime = utcTime.ConvertFromUtc(Future.Exchange.TimeZone);
87  var availableContracts = data.Data.Cast<FutureUniverse>().ToList();
88  var results = Future.ContractFilter.Filter(new FutureFilterUniverse(availableContracts, localEndTime));
89 
90  return results.Select(x => x.Symbol);
91  }
92  }
93 }