-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProgram.cs
More file actions
131 lines (117 loc) · 5.23 KB
/
Program.cs
File metadata and controls
131 lines (117 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* 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.Linq;
using System.Threading;
using System.Threading.Tasks;
using FactSet.SDK.Utils.Authentication;
using Newtonsoft.Json;
using QuantConnect.Configuration;
using QuantConnect.Logging;
using QuantConnect.Securities.IndexOption;
using QuantConnect.Util;
using FactSetAuthenticationConfiguration = FactSet.SDK.Utils.Authentication.Configuration;
namespace QuantConnect.DataProcessing
{
public class Program
{
public static string DataFleetDeploymentDate = "QC_DATAFLEET_DEPLOYMENT_DATE";
public static void Main()
{
var tickers = Config.GetValue<List<string>>("tickers");
var securityType = Config.GetValue("security-type", SecurityType.IndexOption);
SecurityType underlyingSecurityType;
try
{
underlyingSecurityType = Symbol.GetUnderlyingFromOptionType(securityType);
}
catch (Exception ex)
{
Log.Error($"QuantConnect.DataProcessing.Program.Main(): {ex.Message}");
Environment.Exit(1);
return;
}
var symbols = tickers.Select(ticker =>
{
var underlyingTicker = IndexOptionSymbol.MapToUnderlying(ticker);
var underlying = Symbol.Create(underlyingTicker, underlyingSecurityType, Market.USA);
return Symbol.CreateCanonicalOption(underlying, ticker, Market.USA, null);
}).ToList();
var resolution = Config.GetValue("resolution", Resolution.Daily);
var startDate = Config.GetValue<DateTime>("start-date");
var endDate = startDate;
if (startDate != default)
{
endDate = DateTime.UtcNow.Date.AddDays(-1);
}
else
{
var startDateStr = Environment.GetEnvironmentVariable(DataFleetDeploymentDate);
if (string.IsNullOrEmpty(startDateStr))
{
Log.Error($"QuantConnect.DataProcessing.Program.Main(): The start date was neither set in the configuration " +
$"nor in the {DataFleetDeploymentDate} environment variable.");
Environment.Exit(1);
}
startDate = DateTime.ParseExact(startDateStr, "yyyyMMdd", CultureInfo.InvariantCulture);
endDate = startDate;
}
var factSetAuthConfig = JsonConvert.DeserializeObject<FactSetAuthenticationConfiguration>(Config.Get("factset-auth-config"));
if (factSetAuthConfig == null)
{
Log.Error($"QuantConnect.DataProcessing.Program.Main(): The FactSet authentication configuration was not set.");
Environment.Exit(1);
}
var tickerWhitelist = Config.GetValue<List<string>>("factset-ticker-whitelist");
// Get the config values first before running. These values are set for us
// automatically to the value set on the website when defining this data type
var dataFolder = Config.Get("temp-output-directory", "/temp-output-directory");
var rawDataFolder = Config.Get("raw-data-folder", "/raw");
var tickersStr = string.Join(", ", tickers);
Log.Trace($"DataProcessing.Main(): Processing {tickersStr} | {resolution} | {startDate:yyyy-MM-dd} - {endDate:yyyy-MM-dd}");
FactSetDataProcessor processor = null;
try
{
processor = new FactSetDataProcessor(factSetAuthConfig, symbols, resolution, startDate, endDate, dataFolder, rawDataFolder,
tickerWhitelist);
}
catch (Exception err)
{
Log.Error(err, $"QuantConnect.DataProcessing.Program.Main(): The downloader/converter failed to be instantiated");
Environment.Exit(1);
}
try
{
if (!processor.Run())
{
Log.Error($"QuantConnect.DataProcessing.Program.Main(): Failed to download/process data");
Environment.Exit(1);
}
}
catch (Exception err)
{
Log.Error(err, $"QuantConnect.DataProcessing.Program.Main(): The downloader/converter exited unexpectedly");
Environment.Exit(1);
}
finally
{
processor.DisposeSafely();
}
Environment.Exit(0);
}
}
}