chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Command Line application parser
|
||||
/// </summary>
|
||||
public static class ApplicationParser
|
||||
{
|
||||
/// <summary>
|
||||
/// This function will parse args based on options and will show application name, version, help
|
||||
/// </summary>
|
||||
/// <param name="applicationName">The application name to be shown</param>
|
||||
/// <param name="applicationDescription">The application description to be shown</param>
|
||||
/// <param name="applicationHelpText">The application help text</param>
|
||||
/// <param name="args">The command line arguments</param>
|
||||
/// <param name="options">The applications command line available options</param>
|
||||
/// <param name="noArgsShowHelp">To show help when no command line arguments were provided</param>
|
||||
/// <returns>The user provided options. Key is option name</returns>
|
||||
public static Dictionary<string, object> Parse(string applicationName, string applicationDescription, string applicationHelpText,
|
||||
string[] args, List<CommandLineOption> options, bool noArgsShowHelp = false)
|
||||
{
|
||||
var application = new CommandLineApplication
|
||||
{
|
||||
Name = applicationName,
|
||||
Description = applicationDescription,
|
||||
ExtendedHelpText = applicationHelpText
|
||||
};
|
||||
|
||||
application.HelpOption("-?|-h|--help");
|
||||
|
||||
// This is a helper/shortcut method to display version info - it is creating a regular Option, with some defaults.
|
||||
// The default help text is "Show version Information"
|
||||
application.VersionOption("-v|-V|--version",
|
||||
() =>
|
||||
$"Version {Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");
|
||||
|
||||
var optionsObject = new Dictionary<string, object>();
|
||||
|
||||
var listOfOptions = new List<CommandOption>();
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
listOfOptions.Add(application.Option($"--{option.Name}", option.Description, option.Type));
|
||||
}
|
||||
|
||||
application.OnExecute(() =>
|
||||
{
|
||||
foreach (var commandOption in listOfOptions.Where(option => option.HasValue()))
|
||||
{
|
||||
var optionKey = commandOption.Template.Replace("--", "");
|
||||
var matchingOption = options.Find(o => o.Name == optionKey);
|
||||
switch (matchingOption.Type)
|
||||
{
|
||||
// Booleans
|
||||
case CommandOptionType.NoValue:
|
||||
optionsObject[optionKey] = true;
|
||||
break;
|
||||
|
||||
// Strings and numbers
|
||||
case CommandOptionType.SingleValue:
|
||||
optionsObject[optionKey] = commandOption.Value();
|
||||
break;
|
||||
|
||||
// Parsing nested objects
|
||||
case CommandOptionType.MultipleValue:
|
||||
var keyValuePairs = commandOption.Value().Split(',');
|
||||
var subDictionary = new Dictionary<string, string>();
|
||||
foreach (var keyValuePair in keyValuePairs)
|
||||
{
|
||||
var subKeys = keyValuePair.Split(':');
|
||||
subDictionary[subKeys[0]] = subKeys.Length > 1 ? subKeys[1] : "";
|
||||
}
|
||||
|
||||
optionsObject[optionKey] = subDictionary;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
application.Execute(args);
|
||||
if (noArgsShowHelp && args.Length == 0)
|
||||
{
|
||||
application.ShowHelp();
|
||||
}
|
||||
return optionsObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints a message advising the user to use the --help parameter for more information
|
||||
/// </summary>
|
||||
public static void PrintMessageAndExit(int exitCode = 0, string message = "")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
Console.WriteLine("\n" + message);
|
||||
}
|
||||
Console.WriteLine("\nUse the '--help' parameter for more information");
|
||||
Console.WriteLine("Press any key to quit");
|
||||
Console.ReadLine();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parameter object from the given parameter (if it exists)
|
||||
/// </summary>
|
||||
public static string GetParameterOrExit(IReadOnlyDictionary<string, object> optionsObject, string parameter)
|
||||
{
|
||||
if (!optionsObject.ContainsKey(parameter))
|
||||
{
|
||||
PrintMessageAndExit(1, "ERROR: REQUIRED parameter --" + parameter + "= is missing");
|
||||
}
|
||||
return optionsObject[parameter].ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parameter object from the given parameter. If it does not exists, it returns a default parameter object
|
||||
/// </summary>
|
||||
public static string GetParameterOrDefault(IReadOnlyDictionary<string, object> optionsObject, string parameter, string defaultValue)
|
||||
{
|
||||
object value;
|
||||
if (!optionsObject.TryGetValue(parameter, out value))
|
||||
{
|
||||
Console.WriteLine($"'{parameter}' was not specified. Using default value: '{defaultValue}'");
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Auxiliary class to keep information about a specific command line option
|
||||
/// </summary>
|
||||
public class CommandLineOption
|
||||
{
|
||||
/// <summary>
|
||||
/// Command line option type
|
||||
/// </summary>
|
||||
public CommandOptionType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command line option description
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command line option name
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command line option constructor
|
||||
/// </summary>
|
||||
public CommandLineOption(string name, CommandOptionType type, string description = "")
|
||||
{
|
||||
Type = type;
|
||||
Description = description;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using QuantConnect.Logging;
|
||||
using static System.FormattableString;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration class loads the required external setup variables to launch the Lean engine.
|
||||
/// </summary>
|
||||
public static class Config
|
||||
{
|
||||
//Location of the configuration file.
|
||||
private static string ConfigurationFileName = "config.json";
|
||||
|
||||
/// <summary>
|
||||
/// Set configuration file on-fly
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
public static void SetConfigurationFile(string fileName)
|
||||
{
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
Log.Trace(Invariant($"Using {fileName} as configuration file"));
|
||||
ConfigurationFileName = fileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(Invariant($"Configuration file {fileName} does not exist, using {ConfigurationFileName}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge CLI arguments with configuration file + load custom config file via CLI arg
|
||||
/// </summary>
|
||||
/// <param name="cliArguments"></param>
|
||||
public static void MergeCommandLineArgumentsWithConfiguration(Dictionary<string, object> cliArguments)
|
||||
{
|
||||
if (cliArguments.ContainsKey("config"))
|
||||
{
|
||||
SetConfigurationFile(cliArguments["config"] as string);
|
||||
Reset();
|
||||
}
|
||||
|
||||
var jsonArguments = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cliArguments));
|
||||
|
||||
Settings.Value.Merge(jsonArguments, new JsonMergeSettings
|
||||
{
|
||||
MergeArrayHandling = MergeArrayHandling.Union
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the config settings to their default values.
|
||||
/// Called in regression tests where multiple algorithms are run sequentially,
|
||||
/// and we need to guarantee that every test starts with the same configuration.
|
||||
/// </summary>
|
||||
public static void Reset()
|
||||
{
|
||||
Settings = new Lazy<JObject>(ConfigFactory);
|
||||
}
|
||||
|
||||
private static Lazy<JObject> Settings = new Lazy<JObject>(ConfigFactory);
|
||||
|
||||
private static JObject ConfigFactory()
|
||||
{
|
||||
// initialize settings inside a lazy for free thread-safe, one-time initialization
|
||||
if (!File.Exists(ConfigurationFileName))
|
||||
{
|
||||
return new JObject
|
||||
{
|
||||
{"algorithm-type-name", "BasicTemplateAlgorithm"},
|
||||
{"live-mode", false},
|
||||
{"data-folder", "../../../Data/"},
|
||||
{"messaging-handler", "QuantConnect.Messaging.Messaging"},
|
||||
{"job-queue-handler", "QuantConnect.Queues.JobQueue"},
|
||||
{"api-handler", "QuantConnect.Api.Api"},
|
||||
{"setup-handler", "QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler"},
|
||||
{"result-handler", "QuantConnect.Lean.Engine.Results.BacktestingResultHandler"},
|
||||
{"data-feed-handler", "QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed"},
|
||||
{"real-time-handler", "QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler"},
|
||||
{"transaction-handler", "QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler"}
|
||||
};
|
||||
}
|
||||
|
||||
return JObject.Parse(File.ReadAllText(ConfigurationFileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently selected environment. If sub-environments are defined,
|
||||
/// they'll be returned as {env1}.{env2}
|
||||
/// </summary>
|
||||
/// <returns>The fully qualified currently selected environment</returns>
|
||||
public static string GetEnvironment()
|
||||
{
|
||||
var environments = new List<string>();
|
||||
JToken currentEnvironment = Settings.Value;
|
||||
var env = currentEnvironment["environment"];
|
||||
while (currentEnvironment != null && env != null)
|
||||
{
|
||||
var currentEnv = env.Value<string>();
|
||||
environments.Add(currentEnv);
|
||||
var moreEnvironments = currentEnvironment["environments"];
|
||||
if (moreEnvironments == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
currentEnvironment = moreEnvironments[currentEnv];
|
||||
env = currentEnvironment["environment"];
|
||||
}
|
||||
return string.Join(".", environments);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the matching config setting from the file searching for this key.
|
||||
/// </summary>
|
||||
/// <param name="key">String key value we're seaching for in the config file.</param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns>String value of the configuration setting or empty string if nothing found.</returns>
|
||||
public static string Get(string key, string defaultValue = "")
|
||||
{
|
||||
// special case environment requests
|
||||
if (key == "environment") return GetEnvironment();
|
||||
|
||||
var token = GetToken(Settings.Value, key);
|
||||
if (token == null)
|
||||
{
|
||||
if (Log.DebuggingEnabled)
|
||||
{
|
||||
Log.Debug(Invariant($"Config.Get(): Configuration key not found. Key: {key} - Using default value: {defaultValue}"));
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
return token.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying JToken for the specified key
|
||||
/// </summary>
|
||||
public static JToken GetToken(string key)
|
||||
{
|
||||
return GetToken(Settings.Value, key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a configuration value. This is really only used to help testing. The key heye can be
|
||||
/// specified as {environment}.key to set a value on a specific environment
|
||||
/// </summary>
|
||||
/// <param name="key">The key to be set</param>
|
||||
/// <param name="value">The new value</param>
|
||||
public static void Set(string key, dynamic value)
|
||||
{
|
||||
JToken environment = Settings.Value;
|
||||
while (key.Contains('.', StringComparison.InvariantCulture))
|
||||
{
|
||||
var envName = key.Substring(0, key.IndexOf(".", StringComparison.InvariantCulture));
|
||||
key = key.Substring(key.IndexOf(".", StringComparison.InvariantCulture) + 1);
|
||||
var environments = environment["environments"];
|
||||
if (environments == null)
|
||||
{
|
||||
environment["environments"] = environments = new JObject();
|
||||
}
|
||||
environment = environments[envName];
|
||||
}
|
||||
environment[key] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a boolean value configuration setting by a configuration key.
|
||||
/// </summary>
|
||||
/// <param name="key">String value of the configuration key.</param>
|
||||
/// <param name="defaultValue">The default value to use if not found in configuration</param>
|
||||
/// <returns>Boolean value of the config setting.</returns>
|
||||
public static bool GetBool(string key, bool defaultValue = false)
|
||||
{
|
||||
return GetValue(key, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the int value of a config string.
|
||||
/// </summary>
|
||||
/// <param name="key">Search key from the config file</param>
|
||||
/// <param name="defaultValue">The default value to use if not found in configuration</param>
|
||||
/// <returns>Int value of the config setting.</returns>
|
||||
public static int GetInt(string key, int defaultValue = 0)
|
||||
{
|
||||
return GetValue(key, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the double value of a config string.
|
||||
/// </summary>
|
||||
/// <param name="key">Search key from the config file</param>
|
||||
/// <param name="defaultValue">The default value to use if not found in configuration</param>
|
||||
/// <returns>Double value of the config setting.</returns>
|
||||
public static double GetDouble(string key, double defaultValue = 0.0)
|
||||
{
|
||||
return GetValue(key, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value from configuration and converts it to the requested type, assigning a default if
|
||||
/// the configuration is null or empty
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The requested type</typeparam>
|
||||
/// <param name="key">Search key from the config file</param>
|
||||
/// <param name="defaultValue">The default value to use if not found in configuration</param>
|
||||
/// <returns>Converted value of the config setting.</returns>
|
||||
public static T GetValue<T>(string key, T defaultValue = default(T))
|
||||
{
|
||||
// special case environment requests
|
||||
if (key == "environment" && typeof(T) == typeof(string)) return (T)(object)GetEnvironment();
|
||||
|
||||
var token = GetToken(Settings.Value, key);
|
||||
if (token == null)
|
||||
{
|
||||
var defaultValueString = defaultValue is IConvertible
|
||||
? ((IConvertible)defaultValue).ToString(CultureInfo.InvariantCulture)
|
||||
: defaultValue is IFormattable
|
||||
? ((IFormattable)defaultValue).ToString(null, CultureInfo.InvariantCulture)
|
||||
: Invariant($"{defaultValue}");
|
||||
|
||||
if (Log.DebuggingEnabled)
|
||||
{
|
||||
Log.Debug(Invariant($"Config.GetValue(): {key} - Using default value: {defaultValueString}"));
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
var type = typeof(T);
|
||||
string value;
|
||||
try
|
||||
{
|
||||
value = token.Value<string>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
value = token.ToString();
|
||||
}
|
||||
|
||||
if (type.IsEnum)
|
||||
{
|
||||
return (T)Enum.Parse(type, value, true);
|
||||
}
|
||||
|
||||
if (typeof(IConvertible).IsAssignableFrom(type))
|
||||
{
|
||||
return (T)Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
// try and find a static parse method
|
||||
try
|
||||
{
|
||||
var parse = type.GetMethod("Parse", new[] { typeof(string) });
|
||||
if (parse != null)
|
||||
{
|
||||
var result = parse.Invoke(null, new object[] { value });
|
||||
return (T)result;
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Trace(Invariant($"Config.GetValue<{typeof(T).Name}>({key},{defaultValue}): Failed to parse: {value}. Using default value."));
|
||||
Log.Error(err);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(value);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Trace(Invariant($"Config.GetValue<{typeof(T).Name}>({key},{defaultValue}): Failed to JSON deserialize: {value}. Using default value."));
|
||||
Log.Error(err);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find the specified key and parse it as a T, using
|
||||
/// default(T) if unable to locate the key or unable to parse it
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The desired output type</typeparam>
|
||||
/// <param name="key">The configuration key</param>
|
||||
/// <param name="value">The output value. If the key is found and parsed successfully, it will be the parsed value, else default(T).</param>
|
||||
/// <returns>True on successful parse or if they key is not found. False only when key is found but fails to parse.</returns>
|
||||
public static bool TryGetValue<T>(string key, out T value)
|
||||
{
|
||||
return TryGetValue(key, default(T), out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find the specified key and parse it as a T, using
|
||||
/// defaultValue if unable to locate the key or unable to parse it
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The desired output type</typeparam>
|
||||
/// <param name="key">The configuration key</param>
|
||||
/// <param name="defaultValue">The default value to use on key not found or unsuccessful parse</param>
|
||||
/// <param name="value">The output value. If the key is found and parsed successfully, it will be the parsed value, else defaultValue.</param>
|
||||
/// <returns>True on successful parse or if they key is not found and using defaultValue. False only when key is found but fails to parse.</returns>
|
||||
public static bool TryGetValue<T>(string key, T defaultValue, out T value)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = GetValue(key, defaultValue);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
value = defaultValue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write the contents of the serialized configuration back to the disk.
|
||||
/// </summary>
|
||||
public static void Write(string targetPath = null)
|
||||
{
|
||||
if (!Settings.IsValueCreated) return;
|
||||
var serialized = JsonConvert.SerializeObject(Settings.Value, Formatting.Indented);
|
||||
|
||||
var taget = ConfigurationFileName;
|
||||
if (!string.IsNullOrEmpty(targetPath))
|
||||
{
|
||||
taget = Path.Combine(targetPath, ConfigurationFileName);
|
||||
}
|
||||
File.WriteAllText(taget, serialized);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flattens the jobject with respect to the selected environment and then
|
||||
/// removes the 'environments' node
|
||||
/// </summary>
|
||||
/// <param name="overrideEnvironment">The environment to use</param>
|
||||
/// <returns>The flattened JObject</returns>
|
||||
public static JObject Flatten(string overrideEnvironment)
|
||||
{
|
||||
return Flatten(Settings.Value, overrideEnvironment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flattens the jobject with respect to the selected environment and then
|
||||
/// removes the 'environments' node
|
||||
/// </summary>
|
||||
/// <param name="config">The configuration represented as a JObject</param>
|
||||
/// <param name="overrideEnvironment">The environment to use</param>
|
||||
/// <returns>The flattened JObject</returns>
|
||||
public static JObject Flatten(JObject config, string overrideEnvironment)
|
||||
{
|
||||
var clone = (JObject)config.DeepClone();
|
||||
|
||||
// remove the environment declaration
|
||||
var environmentProperty = clone.Property("environment");
|
||||
if (environmentProperty != null) environmentProperty.Remove();
|
||||
|
||||
if (!string.IsNullOrEmpty(overrideEnvironment))
|
||||
{
|
||||
var environmentSections = overrideEnvironment.Split('.');
|
||||
|
||||
for (int i = 0; i < environmentSections.Length; i++)
|
||||
{
|
||||
var env = string.Join(".environments.", environmentSections.Where((x, j) => j <= i));
|
||||
|
||||
var environments = config["environments"];
|
||||
if (!(environments is JObject)) continue;
|
||||
|
||||
var settings = ((JObject)environments).SelectToken(env);
|
||||
if (settings == null) continue;
|
||||
|
||||
// copy values for the selected environment to the root
|
||||
foreach (var token in settings)
|
||||
{
|
||||
var path = Path.GetExtension(token.Path);
|
||||
var dot = path.IndexOf(".", StringComparison.InvariantCulture);
|
||||
if (dot != -1) path = path.Substring(dot + 1);
|
||||
|
||||
// remove if already exists on clone
|
||||
var jProperty = clone.Property(path);
|
||||
if (jProperty != null) jProperty.Remove();
|
||||
|
||||
var value = (token is JProperty ? ((JProperty)token).Value : token).ToString();
|
||||
clone.Add(path, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove all environments
|
||||
var environmentsProperty = clone.Property("environments");
|
||||
environmentsProperty?.Remove();
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
private static JToken GetToken(JToken settings, string key)
|
||||
{
|
||||
return GetToken(settings, key, settings.SelectToken(key));
|
||||
}
|
||||
|
||||
private static JToken GetToken(JToken settings, string key, JToken current)
|
||||
{
|
||||
var environmentSetting = settings.SelectToken("environment");
|
||||
if (environmentSetting != null)
|
||||
{
|
||||
var environmentSettingValue = environmentSetting.Value<string>();
|
||||
if (!string.IsNullOrWhiteSpace(environmentSettingValue))
|
||||
{
|
||||
var environment = settings.SelectToken("environments." + environmentSettingValue);
|
||||
if (environment != null)
|
||||
{
|
||||
var setting = environment.SelectToken(key);
|
||||
if (setting != null)
|
||||
{
|
||||
current = setting;
|
||||
}
|
||||
// allows nesting of environments, live.tradier, live.interactive, ect...
|
||||
return GetToken(environment, key, current);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (current == null)
|
||||
{
|
||||
return settings.SelectToken(key);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Command Line arguments parser for Lean configuration
|
||||
/// </summary>
|
||||
public static class LeanArgumentParser
|
||||
{
|
||||
private const string ApplicationName = "Lean Platform";
|
||||
|
||||
private const string ApplicationDescription =
|
||||
"Lean Engine is an open-source algorithmic trading engine built for easy strategy research, backtesting and live trading. We integrate with common data providers and brokerages so you can quickly deploy algorithmic trading strategies.";
|
||||
|
||||
private const string ApplicationHelpText =
|
||||
"If you are looking for help, please go to https://www.quantconnect.com/lean/docs";
|
||||
|
||||
private static readonly List<CommandLineOption> Options = new List<CommandLineOption>
|
||||
{
|
||||
// the location of the configuration to use
|
||||
new CommandLineOption("config", CommandOptionType.SingleValue),
|
||||
|
||||
// true will close lean console automatically without waiting for input
|
||||
new CommandLineOption("close-automatically", CommandOptionType.SingleValue),
|
||||
|
||||
// the result destination folder this algorithm should use for logging and result.json
|
||||
new CommandLineOption("results-destination-folder", CommandOptionType.SingleValue),
|
||||
|
||||
// the algorithm name
|
||||
new CommandLineOption("backtest-name", CommandOptionType.SingleValue),
|
||||
|
||||
// the unique algorithm id
|
||||
new CommandLineOption("algorithm-id", CommandOptionType.SingleValue),
|
||||
|
||||
// the unique optimization id
|
||||
new CommandLineOption("optimization-id", CommandOptionType.SingleValue),
|
||||
|
||||
// Options grabbed from json file
|
||||
new CommandLineOption("environment", CommandOptionType.SingleValue),
|
||||
|
||||
// algorithm class selector
|
||||
new CommandLineOption("algorithm-type-name", CommandOptionType.SingleValue),
|
||||
|
||||
// Algorithm language selector - options CSharp, Python
|
||||
new CommandLineOption("algorithm-language", CommandOptionType.SingleValue),
|
||||
|
||||
//Physical DLL location
|
||||
new CommandLineOption("algorithm-location", CommandOptionType.SingleValue),
|
||||
|
||||
//Research notebook
|
||||
new CommandLineOption("composer-dll-directory", CommandOptionType.SingleValue),
|
||||
|
||||
// engine
|
||||
new CommandLineOption("data-folder", CommandOptionType.SingleValue),
|
||||
|
||||
// handlers
|
||||
new CommandLineOption("log-handler", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("messaging-handler", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("job-queue-handler", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("api-handler", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("map-file-provider", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("factor-file-provider", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("data-provider", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("alpha-handler", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("history-provider", CommandOptionType.SingleValue),
|
||||
|
||||
// limits on number of symbols to allow
|
||||
new CommandLineOption("symbol-minute-limit", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("symbol-second-limit", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("symbol-tick-limit", CommandOptionType.SingleValue),
|
||||
|
||||
// if one uses true in following token, market hours will remain open all hours and all days.
|
||||
// if one uses false will make lean operate only during regular market hours.
|
||||
new CommandLineOption("force-exchange-always-open", CommandOptionType.NoValue),
|
||||
|
||||
// save list of transactions to the specified csv file
|
||||
new CommandLineOption("transaction-log", CommandOptionType.SingleValue),
|
||||
|
||||
// To get your api access token go to quantconnect.com/account
|
||||
new CommandLineOption("job-user-id", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("api-access-token", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("job-organization-id", CommandOptionType.SingleValue),
|
||||
|
||||
// live data configuration
|
||||
new CommandLineOption("live-data-url", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("live-data-port", CommandOptionType.SingleValue),
|
||||
|
||||
// interactive brokers configuration
|
||||
new CommandLineOption("ib-account", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-user-name", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-password", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-host", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-port", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-agent-description", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-tws-dir", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("ib-trading-mode", CommandOptionType.SingleValue),
|
||||
|
||||
// tradier configuration
|
||||
new CommandLineOption("tradier-account-id", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("tradier-access-token", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("tradier-refresh-token", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("tradier-issued-at", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("tradier-lifespan", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("tradier-refresh-session", CommandOptionType.NoValue),
|
||||
|
||||
// oanda configuration
|
||||
new CommandLineOption("oanda-environment", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("oanda-access-token", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("oanda-account-id", CommandOptionType.SingleValue),
|
||||
|
||||
// fxcm configuration
|
||||
new CommandLineOption("fxcm-server", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("fxcm-terminal", CommandOptionType.SingleValue), //Real or Demo
|
||||
new CommandLineOption("fxcm-user-name", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("fxcm-password", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("fxcm-account-id", CommandOptionType.SingleValue),
|
||||
|
||||
// coinbase configuration
|
||||
new CommandLineOption("coinbase-rest-api", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("coinbase-url", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("coinbase-api-key", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("coinbase-api-secret", CommandOptionType.SingleValue),
|
||||
|
||||
// Required to access data from Quandl
|
||||
// To get your access token go to https://www.quandl.com/account/api
|
||||
new CommandLineOption("quandl-auth-token", CommandOptionType.SingleValue),
|
||||
|
||||
// parameters to set in the algorithm (the below are just samples)
|
||||
new CommandLineOption("parameters", CommandOptionType.MultipleValue),
|
||||
new CommandLineOption("environments", CommandOptionType.MultipleValue)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Argument parser constructor
|
||||
/// </summary>
|
||||
public static Dictionary<string, object> ParseArguments(string[] args)
|
||||
{
|
||||
return ApplicationParser.Parse(ApplicationName, ApplicationDescription, ApplicationHelpText, args, Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Command Line arguments parser for Lean Optimizer
|
||||
/// </summary>
|
||||
public static class OptimizerArgumentParser
|
||||
{
|
||||
private const string ApplicationName = "Lean Optimizer";
|
||||
|
||||
private const string ApplicationDescription = "Lean Optimizer is a strategy optimization engine for algorithms.";
|
||||
|
||||
private const string ApplicationHelpText = "If you are looking for help, please go to https://www.quantconnect.com/lean/docs";
|
||||
|
||||
private static readonly List<CommandLineOption> Options = new List<CommandLineOption>
|
||||
{
|
||||
new CommandLineOption("estimate", CommandOptionType.NoValue, "Estimate the optimization run time")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Parse and construct the args
|
||||
/// </summary>
|
||||
public static Dictionary<string, object> ParseArguments(string[] args)
|
||||
{
|
||||
return ApplicationParser.Parse(ApplicationName, ApplicationDescription, ApplicationHelpText, args, Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("QuantConnect.Configuration")]
|
||||
[assembly: AssemblyProduct("QuantConnect.Configuration")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1339b429-9256-4d54-abf5-d30112a484db")]
|
||||
@@ -0,0 +1,48 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<RootNamespace>QuantConnect.Configuration</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Configuration</AssemblyName>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<DocumentationFile>bin\$(Configuration)\QuantConnect.Configuration.xml</DocumentationFile>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<Description>QuantConnect LEAN Engine: Configuration Project - The Config and argument parser implementation</Description>
|
||||
<NoWarn>CA1062</NoWarn>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>$(SelectedOptimization)</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<Target Name="Print" BeforeTargets="Build">
|
||||
<Message Text="SelectedOptimization $(SelectedOptimization)" Importance="high" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.6.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logging\QuantConnect.Logging.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Command Line arguments parser for Report Creator
|
||||
/// </summary>
|
||||
public static class ReportArgumentParser
|
||||
{
|
||||
private const string ApplicationName = "Report Creator";
|
||||
|
||||
private const string ApplicationDescription =
|
||||
"LEAN Report Creator generates beautiful PDF reports from your backtesting strategies for sharing with prospective partners.";
|
||||
|
||||
private const string ApplicationHelpText =
|
||||
"If you are looking for help, please go to https://www.quantconnect.com/docs";
|
||||
|
||||
private static readonly List<CommandLineOption> Options = new List<CommandLineOption>
|
||||
{
|
||||
new CommandLineOption("close-automatically", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("data-folder", CommandOptionType.SingleValue),
|
||||
new CommandLineOption("strategy-name", CommandOptionType.SingleValue, "Strategy name"),
|
||||
new CommandLineOption("strategy-description", CommandOptionType.SingleValue, "Strategy description"),
|
||||
new CommandLineOption("live-data-source-file", CommandOptionType.SingleValue, "Live source data json file"),
|
||||
new CommandLineOption("backtest-data-source-file", CommandOptionType.SingleValue, "Backtest source data json file"),
|
||||
new CommandLineOption("report-destination", CommandOptionType.SingleValue, "Destination of processed report file"),
|
||||
new CommandLineOption("report-css-override-file", CommandOptionType.SingleValue, "CSS override source file"),
|
||||
new CommandLineOption("report-html-custom-file", CommandOptionType.SingleValue, "Custom HTML source file"),
|
||||
new CommandLineOption("python-venv", CommandOptionType.SingleValue, "Python virtual environment path"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Parse and construct the args.
|
||||
/// </summary>
|
||||
public static Dictionary<string, object> ParseArguments(string[] args)
|
||||
{
|
||||
return ApplicationParser.Parse(ApplicationName, ApplicationDescription, ApplicationHelpText, args, Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace QuantConnect.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Command Line arguments parser for Toolbox configuration
|
||||
/// </summary>
|
||||
public static class ToolboxArgumentParser
|
||||
{
|
||||
private const string ApplicationName = "QuantConnect.ToolBox.exe";
|
||||
private const string ApplicationDescription = "Lean Engine ToolBox";
|
||||
private const string ApplicationHelpText = "\nThe ToolBox is a wrapper of >15 tools. "
|
||||
+ "Each require a different set of parameters. Example: --app=RandomDataGenerator --tickers="
|
||||
+ "SPY,AAPL --resolution=Daily --from-date=yyyyMMdd-HH:mm:ss --to-date=yyyyMMdd-HH:mm:ss";
|
||||
private static readonly List<CommandLineOption> Options = new List<CommandLineOption>
|
||||
{
|
||||
new CommandLineOption("app", CommandOptionType.SingleValue,
|
||||
"[REQUIRED] Target tool, CASE INSENSITIVE: GDAXDownloader or GDAXDL"
|
||||
+ "/GoogleDownloader or GDL/IBDownloader or IBDL"
|
||||
+ "/AlgoSeekFuturesConverter or ASFC"
|
||||
+ "/KaikoDataConverter or KDC"
|
||||
+ "/CoarseUniverseGenerator or CUG/\n"
|
||||
+ "RandomDataGenerator or RDG\n"
|
||||
+ "Example 1: --app=RDG"),
|
||||
new CommandLineOption("tickers", CommandOptionType.MultipleValue, "[REQUIRED ALL downloaders] "
|
||||
+ "--tickers=SPY,AAPL,etc"),
|
||||
new CommandLineOption("resolution", CommandOptionType.SingleValue, "[REQUIRED ALL downloaders]"
|
||||
+ " *Not all downloaders support all resolutions. Send empty for more information.*"
|
||||
+ " CASE SENSITIVE: --resolution=Tick/Second/Minute/Hour/Daily/All" +Environment.NewLine+
|
||||
"[OPTIONAL for RandomDataGenerator - same format as downloaders, Options only support Minute"),
|
||||
new CommandLineOption("from-date", CommandOptionType.SingleValue, "[REQUIRED ALL downloaders] --from-date=yyyyMMdd-HH:mm:ss"),
|
||||
new CommandLineOption("to-date", CommandOptionType.SingleValue, "[OPTIONAL for downloaders] If not provided 'DateTime.UtcNow' will "
|
||||
+ "be used. --to-date=yyyyMMdd-HH:mm:ss"),
|
||||
new CommandLineOption("exchange", CommandOptionType.SingleValue, "[Optional for KaikoDataConverter] The exchange to process, if not defined, all exchanges will be processed."),
|
||||
new CommandLineOption("date", CommandOptionType.SingleValue, "[REQUIRED for AlgoSeekFuturesConverter, AlgoSeekOptionsConverter, KaikoDataConverter]"
|
||||
+ "Date for the option bz files: --date=yyyyMMdd"),
|
||||
new CommandLineOption("source-dir", CommandOptionType.SingleValue, "[REQUIRED for KaikoDataConverter,"),
|
||||
new CommandLineOption("destination-dir", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator]"),
|
||||
new CommandLineOption("start", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator. Format yyyyMMdd Example: --start=20010101]"),
|
||||
new CommandLineOption("end", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator. Format yyyyMMdd Example: --end=20020101]"),
|
||||
new CommandLineOption("market", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Market of generated symbols. Defaults to default market for security type: Example: --market=usa]"),
|
||||
new CommandLineOption("symbol-count", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator. Number of symbols to generate data for: Example: --symbol-count=10]"),
|
||||
new CommandLineOption("security-type", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Security type of generated symbols, defaults to Equity: Example: --security-type=Equity/Option/Forex/Future/Cfd/Crypto]"),
|
||||
new CommandLineOption("data-density", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Defaults to Dense. Valid values: --data-density=Dense/Sparse/VerySparse ]"),
|
||||
new CommandLineOption("include-coarse", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Only used for Equity, defaults to true: Example: --include-coarse=true]"),
|
||||
new CommandLineOption("quote-trade-ratio", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the ratio of generated quotes to generated trades. Values larger than 1 mean more quotes than trades. Only used for Option, Future and Crypto, defaults to 1: Example: --quote-trade-ratio=1.75 ]"),
|
||||
new CommandLineOption("random-seed", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the random number generator seed. Defaults to null (random seed). Example: --random-seed=11399 ]"),
|
||||
new CommandLineOption("ipo-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have an IPO event. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 5.0: Example: --ipo-percentage=43.25 ]"),
|
||||
new CommandLineOption("rename-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have a rename event. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 30.0: Example: --rename-percentage=20.0 ]"),
|
||||
new CommandLineOption("splits-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have a stock split event. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 15.0: Example: --splits-percentage=10.0 ]"),
|
||||
new CommandLineOption("dividends-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have dividends. Note that this is not the probability for all symbols genearted. Only used for Equity. Defaults to 60.0: Example: --dividends-percentage=25.5 ]"),
|
||||
new CommandLineOption("dividend-every-quarter-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have a dividend event every quarter. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 30.0: Example: --dividend-every-quarter-percentage=15.0 ]"),
|
||||
new CommandLineOption("option-price-engine", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the stochastic process, and returns new pricing engine to run calculations for that option. Defaults to BaroneAdesiWhaleyApproximationEngine: Example: --option-price-engine=BaroneAdesiWhaleyApproximationEngine ]"),
|
||||
new CommandLineOption("volatility-model-resolution", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the volatility model period span. Defaults to Daily: Example: --volatility-model-resolution=Daily ]"),
|
||||
new CommandLineOption("chain-symbol-count", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the size of the option chain. Defaults to 1 put and 1 call: Example: --chain-symbol-count=2 ]")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Argument parser constructor
|
||||
/// </summary>
|
||||
public static Dictionary<string, object> ParseArguments(string[] args)
|
||||
{
|
||||
return ApplicationParser.Parse(ApplicationName, ApplicationDescription, ApplicationHelpText, args, Options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to get the tickers from the provided options
|
||||
/// </summary>
|
||||
public static List<string> GetTickers(Dictionary<string, object> optionsObject)
|
||||
{
|
||||
return optionsObject.ContainsKey("tickers")
|
||||
? (optionsObject["tickers"] as Dictionary<string, string>)?.Keys.ToList()
|
||||
: new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user