Lean  $LEAN_TAG$
AlgorithmNodePacket.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.Collections.Generic;
18 using Newtonsoft.Json;
19 using static QuantConnect.StringExtensions;
20 
21 namespace QuantConnect.Packets
22 {
23  /// <summary>
24  /// Algorithm Node Packet is a work task for the Lean Engine
25  /// </summary>
27  {
28  /// <summary>
29  /// Default constructor for the algorithm node:
30  /// </summary>
31  /// <param name="type"></param>
33  : base(type)
34  { }
35 
36  /// <summary>
37  /// The host name to use if any
38  /// </summary>
39  public string HostName;
40 
41  /// <summary>
42  /// User Id placing request
43  /// </summary>
44  public int UserId = 0;
45 
46  /// User API Token
47  public string UserToken = "";
48 
49  /// User Organization Id
50  public string OrganizationId = "";
51 
52  /// <summary>
53  /// Project Id of the request
54  /// </summary>
55  public int ProjectId = 0;
56 
57  /// <summary>
58  /// Project name of the request
59  /// </summary>
60  public string ProjectName;
61 
62  /// <summary>
63  /// Algorithm Id - BacktestId or DeployId - Common Id property between packets.
64  /// </summary>
65  public string AlgorithmId
66  {
67  get
68  {
69  if (Type == PacketType.LiveNode || Type == PacketType.AlphaNode)
70  {
71  return ((LiveNodePacket)this).DeployId;
72  }
73  return ((BacktestNodePacket)this).BacktestId;
74  }
75  }
76 
77  /// <summary>
78  /// User session Id for authentication
79  /// </summary>
80  public string SessionId = "";
81 
82  /// <summary>
83  /// Language flag: Currently represents IL code or Dynamic Scripted Types.
84  /// </summary>
85  public Language Language = Language.CSharp;
86 
87  /// <summary>
88  /// Server type for the deployment (512, 1024, 2048)
89  /// </summary>
90  public ServerType ServerType = ServerType.Server512;
91 
92  /// <summary>
93  /// Unique compile id of this backtest
94  /// </summary>
95  public string CompileId = "";
96 
97  /// <summary>
98  /// Version number identifier for the lean engine.
99  /// </summary>
100  public string Version;
101 
102  /// <summary>
103  /// An algorithm packet which has already been run and is being redelivered on this node.
104  /// In this event we don't want to relaunch the task as it may result in unexpected behaviour for user.
105  /// </summary>
106  public bool Redelivered = false;
107 
108  /// <summary>
109  /// Algorithm binary with zip of contents
110  /// </summary>
111  public byte[] Algorithm = new byte[] { };
112 
113  /// <summary>
114  /// Request source - Web IDE or API - for controling result handler behaviour
115  /// </summary>
116  public string RequestSource = "WebIDE";
117 
118  /// <summary>
119  /// The maximum amount of RAM (in MB) this algorithm is allowed to utilize
120  /// </summary>
121  public int RamAllocation {
122  get { return Controls.RamAllocation; }
123  }
124 
125  /// <summary>
126  /// Specifies values to control algorithm limits
127  /// </summary>
129 
130  /// <summary>
131  /// The parameter values used to set algorithm parameters
132  /// </summary>
133  public Dictionary<string, string> Parameters = new Dictionary<string, string>();
134 
135  /// <summary>
136  /// String name of the HistoryProvider we're running with
137  /// </summary>
138  public string HistoryProvider = "";
139 
140  /// <summary>
141  /// Algorithm running mode.
142  /// </summary>
143  [JsonIgnore]
144  public virtual AlgorithmMode AlgorithmMode { get; } = AlgorithmMode.Backtesting;
145 
146  /// <summary>
147  /// Deployment target, either local or cloud.
148  /// </summary>
149  [JsonIgnore]
151 
152  /// <summary>
153  /// Gets a unique name for the algorithm defined by this packet
154  /// </summary>
155  public string GetAlgorithmName()
156  {
157  return Invariant($"{UserId}-{ProjectId}-{AlgorithmId}");
158  }
159  }
160 }