/* * 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 Newtonsoft.Json; using static QuantConnect.StringExtensions; namespace QuantConnect.Packets { /// /// Algorithm Node Packet is a work task for the Lean Engine /// public class AlgorithmNodePacket : PythonEnvironmentPacket { /// /// Default constructor for the algorithm node: /// /// public AlgorithmNodePacket(PacketType type) : base(type) { } /// /// The host name to use if any /// public string HostName { get; set; } /// /// User Id placing request /// public int UserId { get; set; } /// User API Token public string UserToken { get; set; } = string.Empty; /// User Organization Id public string OrganizationId { get; set; } = string.Empty; /// /// Project Id of the request /// public int ProjectId { get; set; } /// /// Project name of the request /// public string ProjectName { get; set; } /// /// Algorithm Id - BacktestId or DeployId - Common Id property between packets. /// public string AlgorithmId { get { if (Type == PacketType.LiveNode || Type == PacketType.AlphaNode) { return ((LiveNodePacket)this).DeployId; } else if (Type == PacketType.ResearchNode) { return ((ResearchNodePacket)this).ResearchId; } return ((BacktestNodePacket)this).BacktestId; } } /// /// User session Id for authentication /// public string SessionId { get; set; } = string.Empty; /// /// Language flag: Currently represents IL code or Dynamic Scripted Types. /// public Language Language { get; set; } = Language.CSharp; /// /// Server type for the deployment (512, 1024, 2048) /// public ServerType ServerType { get; set; } = ServerType.Server512; /// /// Unique compile id of this backtest /// public string CompileId { get; set; } = string.Empty; /// /// Version number identifier for the lean engine. /// public string Version { get; set; } /// /// An algorithm packet which has already been run and is being redelivered on this node. /// In this event we don't want to relaunch the task as it may result in unexpected behaviour for user. /// public bool Redelivered { get; set; } /// /// Algorithm binary with zip of contents /// public byte[] Algorithm { get; set; } = Array.Empty(); /// /// Request source - Web IDE or API - for controling result handler behaviour /// public string RequestSource { get; set; } = "WebIDE"; /// /// The maximum amount of RAM (in MB) this algorithm is allowed to utilize /// public int RamAllocation { get { return Controls?.RamAllocation ?? 0; } } /// /// Specifies values to control algorithm limits /// public Controls Controls { get; set; } /// /// The parameter values used to set algorithm parameters /// public Dictionary Parameters { get; set; } = new Dictionary(); /// /// String name of the HistoryProvider we're running with /// public string HistoryProvider { get; set; } = string.Empty; /// /// Algorithm running mode. /// [JsonIgnore] public virtual AlgorithmMode AlgorithmMode { get; } = AlgorithmMode.Backtesting; /// /// Deployment target, either local or cloud. /// [JsonIgnore] public DeploymentTarget DeploymentTarget { get; set; } /// /// Gets a unique name for the algorithm defined by this packet /// public string GetAlgorithmName() { return Invariant($"{UserId}-{ProjectId}-{AlgorithmId}"); } } }