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