Lean  $LEAN_TAG$
FutureUniverse.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.IO;
18 
20 {
21  /// <summary>
22  /// Represents a universe of futures data
23  /// </summary>
25  {
26  /// <summary>
27  /// Creates a new instance of the <see cref="FutureUniverse"/> class
28  /// </summary>
29  public FutureUniverse()
30  {
31  }
32 
33  /// <summary>
34  /// Creates a new instance of the <see cref="FutureUniverse"/> class
35  /// </summary>
36  public FutureUniverse(DateTime date, Symbol symbol, string csv)
37  : base(date, symbol, csv)
38  {
39  }
40 
41  /// <summary>
42  /// Creates a new instance of the <see cref="FutureUniverse"/> class as a copy of the given instance
43  /// </summary>
45  : base(other)
46  {
47  }
48 
49  /// <summary>
50  /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
51  /// each time it is called.
52  /// </summary>
53  /// <param name="config">Subscription data config setup object</param>
54  /// <param name="stream">Stream reader of the source document</param>
55  /// <param name="date">Date of the requested data</param>
56  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
57  /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
58  public override BaseData Reader(SubscriptionDataConfig config, StreamReader stream, DateTime date, bool isLiveMode)
59  {
60  if (TryRead(config, stream, date, out var symbol, out var remainingLine))
61  {
62  return new FutureUniverse(date, symbol, remainingLine);
63  }
64 
65  return null;
66  }
67 
68  /// <summary>
69  /// Creates a copy of the instance
70  /// </summary>
71  /// <returns>Clone of the instance</returns>
72  public override BaseData Clone()
73  {
74  return new FutureUniverse(this);
75  }
76 
77  /// <summary>
78  /// Gets the default resolution for this data and security type
79  /// </summary>
80  /// <remarks>This is a method and not a property so that python
81  /// custom data types can override it</remarks>
82  public override Resolution DefaultResolution()
83  {
84  return Resolution.Daily;
85  }
86 
87  /// <summary>
88  /// Implicit conversion into <see cref="Symbol"/>
89  /// </summary>
90  /// <param name="data">The option universe data to be converted</param>
91 #pragma warning disable CA2225 // Operator overloads have named alternates
92  public static implicit operator Symbol(FutureUniverse data)
93 #pragma warning restore CA2225 // Operator overloads have named alternates
94  {
95  return data.Symbol;
96  }
97 
98  /// <summary>
99  /// Gets the CSV string representation of this universe entry
100  /// </summary>
101  public static string ToCsv(Symbol symbol, decimal open, decimal high, decimal low, decimal close, decimal volume, decimal? openInterest)
102  {
103  return $"{symbol.ID},{symbol.Value},{open},{high},{low},{close},{volume},{openInterest}";
104  }
105 
106  /// <summary>
107  /// Gets the CSV header string for this universe entry
108  /// </summary>
109  public static string CsvHeader => "symbol_id,symbol_value,open,high,low,close,volume,open_interest";
110  }
111 }