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  /// <summary>
27  /// Initializes a new instance of the <see cref="ZipEntryName"/> class
28  /// </summary>
29  public ZipEntryName()
30  {
31  DataType = MarketDataType.Auxiliary;
32  }
33 
34  /// <summary>
35  /// Indicates whether this contains data that should be stored in the security cache
36  /// </summary>
37  /// <returns>Whether this contains data that should be stored in the security cache</returns>
38  public override bool ShouldCacheToSecurity()
39  {
40  return false;
41  }
42 
43  /// <summary>
44  /// 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
45  /// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
46  /// </summary>
47  /// <param name="config">Subscription data config setup object</param>
48  /// <param name="line">Line of the source document</param>
49  /// <param name="date">Date of the requested data</param>
50  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
51  /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
52  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
53  {
54  var symbol = LeanData.ReadSymbolFromZipEntry(config.Symbol, config.Resolution, line);
55  return new ZipEntryName {Time = date, Symbol = symbol};
56  }
57 
58  /// <summary>
59  /// Return the URL string source of the file. This will be converted to a stream
60  /// </summary>
61  /// <param name="config">Configuration object</param>
62  /// <param name="date">Date of this source file</param>
63  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
64  /// <returns>String URL of source file.</returns>
65  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
66  {
67  if (isLiveMode)
68  {
69  return new SubscriptionDataSource(string.Empty, SubscriptionTransportMedium.LocalFile);
70  }
71 
72  var source = LeanData.GenerateZipFilePath(Globals.DataFolder, config.Symbol, date, config.Resolution, config.TickType);
73  return new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile, FileFormat.ZipEntryName);
74  }
75  }
76 }