/* * 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.Globalization; using QuantConnect.Logging; using QuantConnect.Brokerages; using QuantConnect.Configuration; using QuantConnect.DownloaderDataProvider.Launcher.Models.Constants; namespace QuantConnect.DownloaderDataProvider.Launcher { /// /// Represents the configuration for data download. /// public struct DataDownloadConfig { /// /// Type of tick data to download. /// public TickType TickType { get; } /// /// Type of security for which data is to be downloaded. /// public SecurityType SecurityType { get; } /// /// Resolution of the downloaded data. /// public Resolution Resolution { get; } /// /// Start date for the data download. /// public DateTime StartDate { get; } /// /// End date for the data download. /// public DateTime EndDate { get; } /// /// Market name for which the data is to be downloaded. /// public string MarketName { get; } /// /// List of symbols for which data is to be downloaded. /// public List Symbols { get; } = new(); /// /// Initializes a new instance of the struct. /// /// Dictionary containing the parameters for data download. public DataDownloadConfig() { TickType = ParseEnum(Config.Get(DownloaderCommandArguments.CommandDataType).ToString()); SecurityType = ParseEnum(Config.Get(DownloaderCommandArguments.CommandSecurityType).ToString()); Resolution = ParseEnum(Config.Get(DownloaderCommandArguments.CommandResolution).ToString()); StartDate = DateTime.ParseExact(Config.Get(DownloaderCommandArguments.CommandStartDate).ToString(), DateFormat.EightCharacter, CultureInfo.InvariantCulture); EndDate = DateTime.ParseExact(Config.Get(DownloaderCommandArguments.CommandEndDate).ToString(), DateFormat.EightCharacter, CultureInfo.InvariantCulture); #pragma warning disable CA1308 // class Market keeps all name in lowercase MarketName = Config.Get(DownloaderCommandArguments.CommandMarketName).ToString().ToLower(CultureInfo.InvariantCulture); #pragma warning restore CA1308 if (string.IsNullOrEmpty(MarketName)) { MarketName = DefaultBrokerageModel.DefaultMarketMap[SecurityType]; Log.Trace($"{nameof(DataDownloadConfig)}: Default market '{MarketName}' applied for SecurityType '{SecurityType}'"); } if (!Market.SupportedMarkets().Contains(MarketName)) { throw new ArgumentException($"The specified market '{MarketName}' is not supported. Supported markets are: {string.Join(", ", Market.SupportedMarkets())}."); } foreach (var ticker in (Config.GetValue>(DownloaderCommandArguments.CommandTickers))!.Keys) { Symbols.Add(Symbol.Create(ticker, SecurityType, MarketName)); } } /// /// Initializes a new instance of the class with the specified parameters. /// /// The type of tick data to be downloaded. /// The type of security for which data is being downloaded. /// The resolution of the data being downloaded. /// The start date for the data download range. /// The end date for the data download range. /// The name of the market from which the data is being downloaded. /// A list of symbols for which data is being downloaded. public DataDownloadConfig(TickType tickType, SecurityType securityType, Resolution resolution, DateTime startDate, DateTime endDate, string market, List symbols) { TickType = tickType; SecurityType = securityType; Resolution = resolution; StartDate = startDate; EndDate = endDate; MarketName = market; Symbols = symbols; } /// /// Returns a string representation of the struct. /// /// A string representation of the struct. public override string ToString() { return $"TickType: {TickType}, " + $"SecurityType: {SecurityType}, " + $"Resolution: {Resolution}, " + $"StartDate: {StartDate:yyyyMMdd}, " + $"EndDate: {EndDate:yyyyMMdd}, " + $"MarketName: {MarketName}, " + $"Symbols: {string.Join(", ", Symbols.Select(s => s.ToString()))}"; } /// /// Parses a string value to an enum of type . /// /// The enum type to parse to. /// The string value to parse. /// The parsed enum value. private static TEnum ParseEnum(string value) where TEnum : struct, Enum { if (!Enum.TryParse(value, true, out TEnum result) || !Enum.IsDefined(typeof(TEnum), result)) { throw new ArgumentException($"Invalid {typeof(TEnum).Name} specified. Please provide a valid {typeof(TEnum).Name}."); } return result; } } }