Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Download Project in Lean #7975

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Common/DataDownloaderGetParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ public DataDownloaderGetParameters(Symbol symbol, Resolution resolution, DateTim
EndUtc = endUtc;
TickType = tickType ?? TickType.Trade;
}

/// <summary>
/// Returns a string representation of the <see cref="DataDownloaderGetParameters"/> object.
/// </summary>
/// <returns>A string representing the object's properties.</returns>
public override string ToString() => $"Symbol: {Symbol}, Resolution: {Resolution}, StartUtc: {StartUtc}, EndUtc: {EndUtc}, TickType: {TickType}";
}
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COPY ./Lean/Data/ /Lean/Data/
COPY ./Lean/Launcher/bin/Debug/ /Lean/Launcher/bin/Debug/
COPY ./Lean/Optimizer.Launcher/bin/Debug/ /Lean/Optimizer.Launcher/bin/Debug/
COPY ./Lean/Report/bin/Debug/ /Lean/Report/bin/Debug/
COPY ./Lean/DownloaderDataProvider/bin/Debug/ /Lean/DownloaderDataProvider/bin/Debug/

# Can override with '-w'
WORKDIR /Lean/Launcher/bin/Debug
Expand Down
145 changes: 145 additions & 0 deletions DownloaderDataProvider/DataDownloadConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* 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.Configuration;
using QuantConnect.DownloaderDataProvider.Launcher.Models.Constants;

namespace QuantConnect.DownloaderDataProvider.Launcher
{
/// <summary>
/// Represents the configuration for data download.
/// </summary>
public struct DataDownloadConfig
{
/// <summary>
/// The tick type as a string.
/// </summary>
private string _tickType;

/// <summary>
/// The security type as a string.
/// </summary>
private string _securityType;

/// <summary>
/// The resolution as a string.
/// </summary>
private string _resolution;

/// <summary>
/// The start date as a string.
/// </summary>
private string _startDate;

/// <summary>
/// The end date as a string.
/// </summary>
private string _endDate;

/// <summary>
/// Type of tick data to download.
/// </summary>
public TickType TickType { get => ParseEnum<TickType>(_tickType); }

/// <summary>
/// Type of security for which data is to be downloaded.
/// </summary>
public SecurityType SecurityType { get => ParseEnum<SecurityType>(_securityType); }

/// <summary>
/// Resolution of the downloaded data.
/// </summary>
public Resolution Resolution { get => ParseEnum<Resolution>(_resolution); }

/// <summary>
/// Start date for the data download.
/// </summary>
public DateTime StartDate { get => DateTime.ParseExact(_startDate, DateFormat.EightCharacter, CultureInfo.InvariantCulture); }

/// <summary>
/// End date for the data download.
/// </summary>
public DateTime EndDate { get => DateTime.ParseExact(_endDate, DateFormat.EightCharacter, CultureInfo.InvariantCulture); }

/// <summary>
/// Market name for which the data is to be downloaded.
/// </summary>
public string MarketName { get; }

/// <summary>
/// List of symbols for which data is to be downloaded.
/// </summary>
public List<Symbol> Symbols { get; } = new();

/// <summary>
/// Initializes a new instance of the <see cref="DataDownloadConfig"/> struct.
/// </summary>
/// <param name="parameters">Dictionary containing the parameters for data download.</param>
public DataDownloadConfig()
{
_tickType = Config.Get(DownloaderCommandArguments.CommandDataType).ToString() ?? string.Empty;
_securityType = Config.Get(DownloaderCommandArguments.CommandSecurityType).ToString() ?? string.Empty;
_resolution = Config.Get(DownloaderCommandArguments.CommandResolution).ToString() ?? string.Empty;

_startDate = Config.Get(DownloaderCommandArguments.CommandStartDate).ToString() ?? string.Empty;
_endDate = Config.Get(DownloaderCommandArguments.CommandEndDate).ToString() ?? string.Empty;

MarketName = Config.Get(DownloaderCommandArguments.CommandMarketName).ToString()?.ToLower() ?? Market.USA;

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<Dictionary<string, string>>(DownloaderCommandArguments.CommandTickers))!.Keys)
{
Symbols.Add(Symbol.Create(ticker, SecurityType, MarketName));
}
}

/// <summary>
/// Returns a string representation of the <see cref="DataDownloadConfig"/> struct.
/// </summary>
/// <returns>A string representation of the <see cref="DataDownloadConfig"/> struct.</returns>
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()))}";
}

/// <summary>
/// Parses a string value to an enum of type <typeparamref name="TEnum"/>.
/// </summary>
/// <typeparam name="TEnum">The enum type to parse to.</typeparam>
/// <param name="value">The string value to parse.</param>
/// <returns>The parsed enum value.</returns>
private TEnum ParseEnum<TEnum>(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;
}
}
}
55 changes: 55 additions & 0 deletions DownloaderDataProvider/DownloaderDataProviderArgumentParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 QuantConnect.Configuration;
using McMaster.Extensions.CommandLineUtils;
using QuantConnect.DownloaderDataProvider.Launcher.Models.Constants;

namespace QuantConnect.DownloaderDataProvider.Launcher;

public static class DownloaderDataProviderArgumentParser
{
private const string ApplicationName = "QuantConnect.DownloaderDataProvider.exe";
private const string ApplicationDescription = "Welcome to Lean Downloader Data Provider! 🚀 Easily download historical data from various sources with our user-friendly application. Start exploring financial data effortlessly!";
private const string ApplicationHelpText = "Hm...";

private static readonly List<CommandLineOption> Options = new List<CommandLineOption>
{
new CommandLineOption(DownloaderCommandArguments.CommandDownloaderDataDownloader, CommandOptionType.SingleValue),
new CommandLineOption(DownloaderCommandArguments.CommandDataType, CommandOptionType.SingleValue),
new CommandLineOption(DownloaderCommandArguments.CommandTickers, CommandOptionType.MultipleValue),
new CommandLineOption(DownloaderCommandArguments.CommandSecurityType, CommandOptionType.SingleValue),
new CommandLineOption(DownloaderCommandArguments.CommandMarketName, CommandOptionType.SingleValue),
new CommandLineOption(DownloaderCommandArguments.CommandResolution, CommandOptionType.SingleValue),
new CommandLineOption(DownloaderCommandArguments.CommandStartDate, CommandOptionType.SingleValue),
new CommandLineOption(DownloaderCommandArguments.CommandEndDate, CommandOptionType.SingleValue)
};

/// <summary>
/// Parses the command-line arguments and returns a dictionary containing parsed values.
/// </summary>
/// <param name="args">An array of command-line arguments.</param>
/// <returns>A dictionary containing parsed values from the command-line arguments.</returns>
/// <remarks>
/// The <paramref name="args"/> parameter should contain the command-line arguments to be parsed.
/// The method uses the ApplicationParser class to parse the arguments based on the ApplicationName,
/// ApplicationDescription, ApplicationHelpText, and Options properties.
/// </remarks>
public static Dictionary<string, object> ParseArguments(string[] args)
{
return ApplicationParser.Parse(ApplicationName, ApplicationDescription, ApplicationHelpText, args, Options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

namespace QuantConnect.DownloaderDataProvider.Launcher.Models.Constants
{
public sealed class DownloaderCommandArguments
{
public const string CommandDownloaderDataDownloader = "data-downloader";

public const string CommandDataType = "data-type";

public const string CommandTickers = "tickers";

public const string CommandSecurityType = "security-type";

public const string CommandMarketName = "market";

public const string CommandResolution = "resolution";

public const string CommandStartDate = "start-date";

public const string CommandEndDate = "end-date";
}
}
Loading
Loading