/* * 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 NodaTime; using QuantConnect.Data; using System; using System.Collections.Generic; using System.IO; using ProtoBuf; namespace QuantConnect.Data.Custom.IconicTypes { /// /// Data source that is unlinked (no mapping) and takes any ticker when calling AddData /// [ProtoContract(SkipConstructor = true)] public class UnlinkedData : BaseData { /// /// If true, we accept any ticker from the AddData call /// public static bool AnyTicker { get; set; } /// /// Example data /// [ProtoMember(55)] public string Ticker { get; set; } /// /// Return the path 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 path of source file. public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { return new SubscriptionDataSource( Path.Combine( "TestData", "unlinked", AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv" ), SubscriptionTransportMedium.LocalFile, FileFormat.Csv); } /// /// Creates UnlinkedData objects using the subscription data config setup as well as the date. /// /// 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 UnlinkedData object generated by this line of the CSV public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { return new UnlinkedData { Ticker = AnyTicker ? "ANY" : $"{config.Symbol.Value}", Symbol = config.Symbol, EndTime = date }; } /// /// Indicates whether the data source is sparse. /// If false, it will disable missing file logging. /// /// true public override bool IsSparseData() { return true; } /// /// Indicates whether the data source can undergo /// rename events/is tied to equities. /// /// true public override bool RequiresMapping() { return false; } /// /// Set the data time zone to UTC /// /// Time zone as UTC public override DateTimeZone DataTimeZone() { return TimeZones.Utc; } /// /// Sets the default resolution to Second /// /// Resolution.Second public override Resolution DefaultResolution() { return Resolution.Daily; } /// /// Gets a list of all the supported Resolutions /// /// All resolutions public override List SupportedResolutions() { return DailyResolution; } } }