/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.IO; using System.Collections.Generic; namespace QuantConnect.Data.UniverseSelection { /// /// Custom base data class used for /// public class ConstituentsUniverseData : BaseData { /// /// Initializes a new instance of the class /// public ConstituentsUniverseData() { DataType = MarketDataType.Auxiliary; } /// /// The end time of this data. /// public override DateTime EndTime { get { return Time + QuantConnect.Time.OneDay; } set { Time = value - QuantConnect.Time.OneDay; } } /// /// Return the URL string source of the file. This will be converted to a stream /// /// Configuration object /// Date of this source file /// true if we're in live mode, false for backtesting mode /// String URL of source file. public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { var universe = config.Symbol.ID.Symbol.Substring(config.MappedSymbol.LastIndexOf('-') + 1); if (isLiveMode) { date = date.AddDays(-1); } var path = Path.Combine(Globals.DataFolder, config.SecurityType.SecurityTypeToLower(), config.Market, "universes", config.Resolution.ResolutionToLower(), universe, $"{date:yyyyMMdd}.csv"); return new SubscriptionDataSource(path, SubscriptionTransportMedium.LocalFile, FileFormat.Csv); } /// /// 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 /// each time it is called. /// /// Subscription data config setup object /// Line of the source document /// Date of the requested data /// true if we're in live mode, false for backtesting mode /// Instance of the T:BaseData object generated by this line of the CSV public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { try { var csv = line.Split(','); var preselected = new ConstituentsUniverseData { Symbol = new Symbol(SecurityIdentifier.Parse(csv[1]), csv[0]), Time = isLiveMode ? date.AddDays(-1) : date }; return preselected; } catch { return null; } } /// /// Indicates that the data set is expected to be sparse /// /// Relies on the property value /// This is a method and not a property so that python /// custom data types can override it /// True if the data set represented by this type is expected to be sparse public override bool IsSparseData() { return true; } /// /// Indicates if there is support for mapping /// /// True indicates mapping should be used public override bool RequiresMapping() { return false; } /// /// Gets the default resolution for this data and security type /// /// This is a method and not a property so that python /// custom data types can override it public override Resolution DefaultResolution() { return Resolution.Daily; } /// /// Gets the supported resolution for this data and security type /// /// Relies on the property value /// This is a method and not a property so that python /// custom data types can override it public override List SupportedResolutions() { return DailyResolution; } } }