Lean  $LEAN_TAG$
UnlinkedDataTradeBar.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;
23 
25 {
26  /// <summary>
27  /// Data source that is unlinked (no mapping) and takes any ticker when calling AddData
28  /// </summary>
29  [ProtoContract(SkipConstructor = true)]
31  {
32  /// <summary>
33  /// If true, we accept any ticker from the AddData call
34  /// </summary>
35  public static bool AnyTicker { get; set; }
36 
37  public UnlinkedDataTradeBar()
38  {
39  DataType = MarketDataType.Base;
40  Period = TimeSpan.FromDays(1);
41  }
42 
43  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
44  {
45  return new SubscriptionDataSource(
46  Path.Combine(
47  "TestData",
48  "unlinkedtradebar",
49  AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv"
50  ),
52  FileFormat.Csv);
53  }
54 
55  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
56  {
57  return new UnlinkedDataTradeBar
58  {
59  Open = 1m,
60  High = 2m,
61  Low = 1m,
62  Close = 1.5m,
63  Volume = 0m,
64 
65  Symbol = config.Symbol,
66  EndTime = date
67  };
68  }
69 
70  /// <summary>
71  /// Indicates whether the data source is sparse.
72  /// If false, it will disable missing file logging.
73  /// </summary>
74  /// <returns>true</returns>
75  public override bool IsSparseData()
76  {
77  return true;
78  }
79 
80  /// <summary>
81  /// Indicates whether the data source can undergo
82  /// rename events/is tied to equities.
83  /// </summary>
84  /// <returns>true</returns>
85  public override bool RequiresMapping()
86  {
87  return false;
88  }
89 
90  /// <summary>
91  /// Set the data time zone to UTC
92  /// </summary>
93  /// <returns>Time zone as UTC</returns>
94  public override DateTimeZone DataTimeZone()
95  {
96  return TimeZones.Utc;
97  }
98 
99  /// <summary>
100  /// Sets the default resolution to Second
101  /// </summary>
102  /// <returns>Resolution.Second</returns>
103  public override Resolution DefaultResolution()
104  {
105  return Resolution.Daily;
106  }
107 
108  /// <summary>
109  /// Gets a list of all the supported Resolutions
110  /// </summary>
111  /// <returns>All resolutions</returns>
112  public override List<Resolution> SupportedResolutions()
113  {
114  return DailyResolution;
115  }
116  }
117 }