Lean  $LEAN_TAG$
Globals.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  *
15 */
16 
17 using System.IO;
18 using System.Reflection;
20 
21 namespace QuantConnect
22 {
23  /// <summary>
24  /// Provides application level constant values
25  /// </summary>
26  public static class Globals
27  {
28  static Globals()
29  {
30  Reset();
31  }
32 
33  /// <summary>
34  /// The base api url address to use
35  /// </summary>
36  public static string Api { get; set; }
37 
38  /// <summary>
39  /// The user Id
40  /// </summary>
41  public static int UserId { get; set; }
42 
43  /// <summary>
44  /// The project id
45  /// </summary>
46  public static int ProjectId { get; set; }
47 
48  /// <summary>
49  /// The user token
50  /// </summary>
51  public static string UserToken { get; set; }
52 
53  /// <summary>
54  /// The organization id
55  /// </summary>
56  public static string OrganizationID { get; set; }
57 
58  /// <summary>
59  /// The results destination folder
60  /// </summary>
61  public static string ResultsDestinationFolder { get; set; }
62 
63  /// <summary>
64  /// The root directory of the data folder for this application
65  /// </summary>
66  public static string DataFolder { get; private set; }
67 
68  /// <summary>
69  /// True if running in live mode
70  /// </summary>
71  public static bool LiveMode { get; private set; }
72 
73  /// <summary>
74  /// Resets global values with the Config data.
75  /// </summary>
76  public static void Reset ()
77  {
78  CacheDataFolder = DataFolder = Config.Get("data-folder", @"../../../Data/");
79 
80  Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
81  var versionid = Config.Get("version-id");
82  if (!string.IsNullOrWhiteSpace(versionid))
83  {
84  Version += "." + versionid;
85  }
86 
87  var cacheLocation = Config.Get("cache-location");
88  if (!string.IsNullOrEmpty(cacheLocation) && !cacheLocation.IsDirectoryEmpty())
89  {
90  CacheDataFolder = cacheLocation;
91  }
92 
93  LiveMode = Config.GetBool("live-mode");
94 
95  UserId = Config.GetInt("job-user-id");
96  ProjectId = Config.GetInt("project-id");
97  UserToken = Config.Get("api-access-token");
98  OrganizationID = Config.Get("job-organization-id");
99  Api = Config.Get("api-url", "https://www.quantconnect.com/api/v2/");
100  ResultsDestinationFolder = Config.Get("results-destination-folder", Directory.GetCurrentDirectory());
101  }
102 
103  /// <summary>
104  /// The directory used for storing downloaded remote files
105  /// </summary>
106  public const string Cache = "./cache/data";
107 
108  /// <summary>
109  /// The version of lean
110  /// </summary>
111  public static string Version { get; private set; }
112 
113  /// <summary>
114  /// Data path to cache folder location
115  /// </summary>
116  public static string CacheDataFolder { get; private set; }
117 
118  /// <summary>
119  /// Helper method that will build a data folder path checking if it exists on the cache folder else will return data folder
120  /// </summary>
121  public static string GetDataFolderPath(string relativePath)
122  {
123  var result = Path.Combine(CacheDataFolder, relativePath);
124  if (result.IsDirectoryEmpty())
125  {
126  result = Path.Combine(DataFolder, relativePath);
127  }
128 
129  return result;
130  }
131  }
132 }