Lean  $LEAN_TAG$
LinkedData.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 source that is linked (tickers that can have renames or be delisted)
27  /// </summary>
28  [ProtoContract(SkipConstructor = true)]
29  public class LinkedData : BaseData
30  {
31  /// <summary>
32  /// Example data
33  /// </summary>
34  [ProtoMember(55)]
35  public int Count { get; set; }
36 
37  /// <summary>
38  /// Return the URL string source of the file. This will be converted to a stream
39  /// </summary>
40  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
41  {
42  return new SubscriptionDataSource(
43  Path.Combine(
44  "TestData",
45  "linked",
46  $"{config.Symbol.Underlying.Value.ToLowerInvariant()}.csv"
47  ),
49  FileFormat.Csv);
50  }
51 
52  /// <summary>
53  /// 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
54  /// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
55  /// </summary>
56  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
57  {
58  return new LinkedData
59  {
60  Count = 10,
61  Symbol = config.Symbol,
62  EndTime = date
63  };
64  }
65 
66  /// <summary>
67  /// Indicates whether the data source is sparse.
68  /// If false, it will disable missing file logging.
69  /// </summary>
70  /// <returns>true</returns>
71  public override bool IsSparseData()
72  {
73  return true;
74  }
75 
76  /// <summary>
77  /// Indicates whether the data source can undergo
78  /// rename events/is tied to equities.
79  /// </summary>
80  /// <returns>true</returns>
81  public override bool RequiresMapping()
82  {
83  return true;
84  }
85 
86  /// <summary>
87  /// Set the data time zone to UTC
88  /// </summary>
89  /// <returns>Time zone as UTC</returns>
90  public override DateTimeZone DataTimeZone()
91  {
92  return TimeZones.Utc;
93  }
94 
95  /// <summary>
96  /// Sets the default resolution to Second
97  /// </summary>
98  /// <returns>Resolution.Second</returns>
99  public override Resolution DefaultResolution()
100  {
101  return Resolution.Daily;
102  }
103 
104  /// <summary>
105  /// Gets a list of all the supported Resolutions
106  /// </summary>
107  /// <returns>All resolutions</returns>
108  public override List<Resolution> SupportedResolutions()
109  {
110  return DailyResolution;
111  }
112  }
113 }