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