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  /// <summary>
38  /// Creates a new instance of an UnlinkedTradeBar
39  /// </summary>
41  {
42  DataType = MarketDataType.Base;
43  Period = TimeSpan.FromDays(1);
44  }
45 
46  /// <summary>
47  /// Get Source for Custom Data File
48  /// >> What source file location would you prefer for each type of usage:
49  /// </summary>
50  /// <param name="config">Configuration object</param>
51  /// <param name="date">Date of this source request if source spread across multiple files</param>
52  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
53  /// <returns>String source location of the file</returns>
54  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
55  {
56  return new SubscriptionDataSource(
57  Path.Combine(
58  "TestData",
59  "unlinkedtradebar",
60  AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv"
61  ),
63  FileFormat.Csv);
64  }
65 
66  /// <summary>
67  /// Fetch the data from the storage and feed it line by line into the engine.
68  /// </summary>
69  /// <param name="config">Symbols, Resolution, DataType, </param>
70  /// <param name="line">Line from the data file requested</param>
71  /// <param name="date">Date of this reader request</param>
72  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
73  /// <returns>Enumerable iterator for returning each line of the required data.</returns>
74  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
75  {
76  return new UnlinkedDataTradeBar
77  {
78  Open = 1m,
79  High = 2m,
80  Low = 1m,
81  Close = 1.5m,
82  Volume = 0m,
83 
84  Symbol = config.Symbol,
85  EndTime = date
86  };
87  }
88 
89  /// <summary>
90  /// Indicates whether the data source is sparse.
91  /// If false, it will disable missing file logging.
92  /// </summary>
93  /// <returns>true</returns>
94  public override bool IsSparseData()
95  {
96  return true;
97  }
98 
99  /// <summary>
100  /// Indicates whether the data source can undergo
101  /// rename events/is tied to equities.
102  /// </summary>
103  /// <returns>true</returns>
104  public override bool RequiresMapping()
105  {
106  return false;
107  }
108 
109  /// <summary>
110  /// Set the data time zone to UTC
111  /// </summary>
112  /// <returns>Time zone as UTC</returns>
113  public override DateTimeZone DataTimeZone()
114  {
115  return TimeZones.Utc;
116  }
117 
118  /// <summary>
119  /// Sets the default resolution to Second
120  /// </summary>
121  /// <returns>Resolution.Second</returns>
122  public override Resolution DefaultResolution()
123  {
124  return Resolution.Daily;
125  }
126 
127  /// <summary>
128  /// Gets a list of all the supported Resolutions
129  /// </summary>
130  /// <returns>All resolutions</returns>
131  public override List<Resolution> SupportedResolutions()
132  {
133  return DailyResolution;
134  }
135  }
136 }