Lean  $LEAN_TAG$
UnlinkedData.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 unlinked (no mapping) and takes any ticker when calling AddData
27  /// </summary>
28  [ProtoContract(SkipConstructor = true)]
29  public class UnlinkedData : BaseData
30  {
31  /// <summary>
32  /// If true, we accept any ticker from the AddData call
33  /// </summary>
34  public static bool AnyTicker { get; set; }
35 
36  /// <summary>
37  /// Example data
38  /// </summary>
39  [ProtoMember(55)]
40  public string Ticker { get; set; }
41 
42  /// <summary>
43  /// Return the path string source of the file. This will be converted to a stream
44  /// </summary>
45  /// <param name="config">Configuration object</param>
46  /// <param name="date">Date of this source file</param>
47  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
48  /// <returns>String path of source file.</returns>
49  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
50  {
51  return new SubscriptionDataSource(
52  Path.Combine(
53  "TestData",
54  "unlinked",
55  AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv"
56  ),
58  FileFormat.Csv);
59  }
60 
61  /// <summary>
62  /// Creates UnlinkedData objects using the subscription data config setup as well as the date.
63  /// </summary>
64  /// <param name="config">Subscription data config setup object</param>
65  /// <param name="line">Line of the source document</param>
66  /// <param name="date">Date of the requested data</param>
67  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
68  /// <returns>Instance of the UnlinkedData object generated by this line of the CSV</returns>
69  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
70  {
71  return new UnlinkedData
72  {
73  Ticker = AnyTicker ? "ANY" : $"{config.Symbol.Value}",
74  Symbol = config.Symbol,
75  EndTime = date
76  };
77  }
78 
79  /// <summary>
80  /// Indicates whether the data source is sparse.
81  /// If false, it will disable missing file logging.
82  /// </summary>
83  /// <returns>true</returns>
84  public override bool IsSparseData()
85  {
86  return true;
87  }
88 
89  /// <summary>
90  /// Indicates whether the data source can undergo
91  /// rename events/is tied to equities.
92  /// </summary>
93  /// <returns>true</returns>
94  public override bool RequiresMapping()
95  {
96  return false;
97  }
98 
99  /// <summary>
100  /// Set the data time zone to UTC
101  /// </summary>
102  /// <returns>Time zone as UTC</returns>
103  public override DateTimeZone DataTimeZone()
104  {
105  return TimeZones.Utc;
106  }
107 
108  /// <summary>
109  /// Sets the default resolution to Second
110  /// </summary>
111  /// <returns>Resolution.Second</returns>
112  public override Resolution DefaultResolution()
113  {
114  return Resolution.Daily;
115  }
116 
117  /// <summary>
118  /// Gets a list of all the supported Resolutions
119  /// </summary>
120  /// <returns>All resolutions</returns>
121  public override List<Resolution> SupportedResolutions()
122  {
123  return DailyResolution;
124  }
125  }
126 }