Lean  $LEAN_TAG$
Program.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
17 using QuantConnect.Logging;
22 using QuantConnect.Util;
23 using System;
24 using System.IO;
26 
27 namespace QuantConnect.ToolBox
28 {
29  public class Program
30  {
31  public static void Main(string[] args)
32  {
33  Log.DebuggingEnabled = Config.GetBool("debug-mode");
34  var destinationDir = Config.Get("results-destination-folder");
35  if (!string.IsNullOrEmpty(destinationDir))
36  {
37  Directory.CreateDirectory(destinationDir);
38  Log.FilePath = Path.Combine(destinationDir, "log.txt");
39  }
40  Log.LogHandler = Composer.Instance.GetExportedValueByTypeName<ILogHandler>(Config.Get("log-handler", "CompositeLogHandler"));
41 
42  var optionsObject = ToolboxArgumentParser.ParseArguments(args);
43  if (optionsObject.Count == 0)
44  {
45  PrintMessageAndExit();
46  }
47 
48  var dataProvider
49  = Composer.Instance.GetExportedValueByTypeName<IDataProvider>(Config.Get("data-provider", "DefaultDataProvider"));
50  var mapFileProvider
51  = Composer.Instance.GetExportedValueByTypeName<IMapFileProvider>(Config.Get("map-file-provider", "LocalDiskMapFileProvider"));
52  var factorFileProvider
53  = Composer.Instance.GetExportedValueByTypeName<IFactorFileProvider>(Config.Get("factor-file-provider", "LocalDiskFactorFileProvider"));
54 
55  mapFileProvider.Initialize(dataProvider);
56  factorFileProvider.Initialize(mapFileProvider, dataProvider);
57 
58  var targetApp = GetParameterOrExit(optionsObject, "app").ToLowerInvariant();
59  if (targetApp.Contains("download") || targetApp.EndsWith("dl"))
60  {
61  var fromDate = Parse.DateTimeExact(GetParameterOrExit(optionsObject, "from-date"), "yyyyMMdd-HH:mm:ss");
62  var resolution = optionsObject.ContainsKey("resolution") ? optionsObject["resolution"].ToString() : "";
63  var market = optionsObject.ContainsKey("market") ? optionsObject["market"].ToString() : "";
64  var securityType = optionsObject.ContainsKey("security-type") ? optionsObject["security-type"].ToString() : "";
65  var tickers = ToolboxArgumentParser.GetTickers(optionsObject);
66  var toDate = optionsObject.ContainsKey("to-date")
67  ? Parse.DateTimeExact(optionsObject["to-date"].ToString(), "yyyyMMdd-HH:mm:ss")
68  : DateTime.UtcNow;
69  switch (targetApp)
70  {
71  default:
72  PrintMessageAndExit(1, "ERROR: Unrecognized --app value");
73  break;
74  }
75  }
76  else
77  {
78  switch (targetApp)
79  {
80  case "asfc":
81  case "algoseekfuturesconverter":
82  AlgoSeekFuturesProgram.AlgoSeekFuturesConverter(GetParameterOrExit(optionsObject, "date"));
83  break;
84  case "kdc":
85  case "kaikodataconverter":
86  KaikoDataConverterProgram.KaikoDataConverter(GetParameterOrExit(optionsObject, "source-dir"),
87  GetParameterOrExit(optionsObject, "date"),
88  GetParameterOrDefault(optionsObject, "exchange", string.Empty));
89  break;
90  case "cug":
91  case "coarseuniversegenerator":
93  break;
94  case "rdg":
95  case "randomdatagenerator":
96  var tickers = ToolboxArgumentParser.GetTickers(optionsObject);
97  RandomDataGeneratorProgram.RandomDataGenerator(
98  GetParameterOrExit(optionsObject, "start"),
99  GetParameterOrExit(optionsObject, "end"),
100  GetParameterOrDefault(optionsObject, "symbol-count", null),
101  GetParameterOrDefault(optionsObject, "market", null),
102  GetParameterOrDefault(optionsObject, "security-type", "Equity"),
103  GetParameterOrDefault(optionsObject, "resolution", "Minute"),
104  GetParameterOrDefault(optionsObject, "data-density", "Dense"),
105  GetParameterOrDefault(optionsObject, "include-coarse", "true"),
106  GetParameterOrDefault(optionsObject, "quote-trade-ratio", "1"),
107  GetParameterOrDefault(optionsObject, "random-seed", null),
108  GetParameterOrDefault(optionsObject, "ipo-percentage", "5.0"),
109  GetParameterOrDefault(optionsObject, "rename-percentage", "30.0"),
110  GetParameterOrDefault(optionsObject, "splits-percentage", "15.0"),
111  GetParameterOrDefault(optionsObject, "dividends-percentage", "60.0"),
112  GetParameterOrDefault(optionsObject, "dividend-every-quarter-percentage", "30.0"),
113  GetParameterOrDefault(optionsObject, "option-price-engine", "BaroneAdesiWhaleyApproximationEngine"),
114  GetParameterOrDefault(optionsObject, "volatility-model-resolution", "Daily"),
115  GetParameterOrDefault(optionsObject, "chain-symbol-count", "1"),
116  tickers
117  );
118  break;
119 
120  default:
121  PrintMessageAndExit(1, "ERROR: Unrecognized --app value");
122  break;
123  }
124  }
125  }
126  }
127 }