Lean  $LEAN_TAG$
ZipEntryName.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 QuantConnect.Util;
18 
20 {
21  /// <summary>
22  /// Defines a data type that just produces data points from the zip entry names in a zip file
23  /// </summary>
24  public class ZipEntryName : BaseData
25  {
26  private DateTime _endTime;
27 
28  /// <summary>
29  /// Initializes a new instance of the <see cref="ZipEntryName"/> class
30  /// </summary>
31  public ZipEntryName()
32  {
33  DataType = MarketDataType.Auxiliary;
34  }
35 
36  /// <summary>
37  /// Gets or sets the end time of this data
38  /// </summary>
39  public override DateTime EndTime
40  {
41  get
42  {
43  if (_endTime == default)
44  {
45  // to be user friendly let's return Time if not set, like BaseData does
46  return Time;
47  }
48  return _endTime;
49  }
50  set
51  {
52  _endTime = value;
53  }
54  }
55 
56  /// <summary>
57  /// Indicates whether this contains data that should be stored in the security cache
58  /// </summary>
59  /// <returns>Whether this contains data that should be stored in the security cache</returns>
60  public override bool ShouldCacheToSecurity()
61  {
62  return false;
63  }
64 
65  /// <summary>
66  /// 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
67  /// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
68  /// </summary>
69  /// <param name="config">Subscription data config setup object</param>
70  /// <param name="line">Line of the source document</param>
71  /// <param name="date">Date of the requested data</param>
72  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
73  /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
74  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
75  {
76  var symbol = LeanData.ReadSymbolFromZipEntry(config.Symbol, config.Resolution, line);
77  return new ZipEntryName {Time = date, Symbol = symbol};
78  }
79 
80  /// <summary>
81  /// Return the URL string source of the file. This will be converted to a stream
82  /// </summary>
83  /// <param name="config">Configuration object</param>
84  /// <param name="date">Date of this source file</param>
85  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
86  /// <returns>String URL of source file.</returns>
87  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
88  {
89  if (isLiveMode)
90  {
91  return new SubscriptionDataSource(string.Empty, SubscriptionTransportMedium.LocalFile);
92  }
93 
94  var source = LeanData.GenerateZipFilePath(Globals.DataFolder, config.Symbol, date, config.Resolution, config.TickType);
95  return new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile, FileFormat.ZipEntryName);
96  }
97  }
98 }