Lean  $LEAN_TAG$
IndexedLinkedData.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 NodaTime;
17 using QuantConnect.Data;
18 using System;
19 using System.Collections.Generic;
20 using System.IO;
21 using ProtoBuf;
22 
24 {
25  /// <summary>
26  /// Data type that is indexed, i.e. a file that points to another file containing the contents
27  /// we're looking for in a Symbol.
28  /// </summary>
29  [ProtoContract(SkipConstructor = true)]
31  {
32  /// <summary>
33  /// Example data property
34  /// </summary>
35  [ProtoMember(55)]
36  public int Count { get; set; }
37 
38  /// <summary>
39  /// Determines the actual source from an index contained within a ticker folder
40  /// </summary>
41  /// <param name="config">Subscription configuration</param>
42  /// <param name="date">Date</param>
43  /// <param name="index">File to load data from</param>
44  /// <param name="isLiveMode">Is live mode</param>
45  /// <returns>SubscriptionDataSource pointing to the article</returns>
46  public override SubscriptionDataSource GetSourceForAnIndex(SubscriptionDataConfig config, DateTime date, string index, bool isLiveMode)
47  {
48  return new SubscriptionDataSource(
49  Path.Combine("TestData",
50  "indexlinked",
51  "content",
52  $"{date.ToStringInvariant(DateFormat.EightCharacter)}.zip#{index}"
53  ),
55  FileFormat.Csv
56  );
57  }
58 
59  /// <summary>
60  /// Gets the source of the index file
61  /// </summary>
62  /// <param name="config">Configuration object</param>
63  /// <param name="date">Date of this source file</param>
64  /// <param name="isLiveMode">Is live mode</param>
65  /// <returns>SubscriptionDataSource indicating where data is located and how it's stored</returns>
66  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
67  {
68  return new SubscriptionDataSource(
69  Path.Combine(
70  "TestData",
71  "indexlinked",
72  config.Symbol.Value.ToLowerInvariant(),
73  $"{date.ToStringInvariant(DateFormat.EightCharacter)}.csv"
74  ),
76  FileFormat.Index
77  );
78  }
79 
80  /// <summary>
81  /// Creates an instance from a line of JSON containing article information read from the `content` directory
82  /// </summary>
83  /// <param name="config">Subscription configuration</param>
84  /// <param name="line">Line of data</param>
85  /// <param name="date">Date</param>
86  /// <param name="isLiveMode">Is live mode</param>
87  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
88  {
89  return new IndexedLinkedData
90  {
91  Count = 10,
92  Symbol = config.Symbol,
93  EndTime = date
94  };
95  }
96 
97  /// <summary>
98  /// Indicates whether the data source is sparse.
99  /// If false, it will disable missing file logging.
100  /// </summary>
101  /// <returns>true</returns>
102  public override bool IsSparseData()
103  {
104  return true;
105  }
106 
107  /// <summary>
108  /// Indicates whether the data source can undergo
109  /// rename events/is tied to equities.
110  /// </summary>
111  /// <returns>true</returns>
112  public override bool RequiresMapping()
113  {
114  return true;
115  }
116 
117  /// <summary>
118  /// Set the data time zone to UTC
119  /// </summary>
120  /// <returns>Time zone as UTC</returns>
121  public override DateTimeZone DataTimeZone()
122  {
123  return TimeZones.Utc;
124  }
125 
126  /// <summary>
127  /// Sets the default resolution to Second
128  /// </summary>
129  /// <returns>Resolution.Second</returns>
130  public override Resolution DefaultResolution()
131  {
132  return Resolution.Daily;
133  }
134 
135  /// <summary>
136  /// Gets a list of all the supported Resolutions
137  /// </summary>
138  /// <returns>All resolutions</returns>
139  public override List<Resolution> SupportedResolutions()
140  {
141  return DailyResolution;
142  }
143  }
144 }