/* * 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 QuantConnect.Logging; using QuantConnect.Orders; using QuantConnect.Securities; namespace QuantConnect.Packets { /// /// Live result packet from a lean engine algorithm. /// public class LiveResultPacket : Packet { /// /// User Id sending result packet /// [JsonProperty(PropertyName = "iUserID")] public int UserId = 0; /// /// Project Id of the result packet /// [JsonProperty(PropertyName = "iProjectID")] public int ProjectId = 0; /// /// User session Id who issued the result packet /// [JsonProperty(PropertyName = "sSessionID")] public string SessionId = ""; /// /// Live Algorithm Id (DeployId) for this result packet /// [JsonProperty(PropertyName = "sDeployID")] public string DeployId = ""; /// /// Compile Id algorithm which generated this result packet /// [JsonProperty(PropertyName = "sCompileID")] public string CompileId = ""; /// /// Result data object for this result packet /// [JsonProperty(PropertyName = "oResults")] public LiveResult Results = new LiveResult(); /// /// Processing time / running time for the live algorithm. /// [JsonProperty(PropertyName = "dProcessingTime")] public double ProcessingTime = 0; /// /// Default constructor for JSON Serialization /// public LiveResultPacket() : base(PacketType.LiveResult) { } /// /// Compose the packet from a JSON string: /// public LiveResultPacket(string json) : base(PacketType.LiveResult) { try { var packet = JsonConvert.DeserializeObject(json); CompileId = packet.CompileId; Channel = packet.Channel; SessionId = packet.SessionId; DeployId = packet.DeployId; Type = packet.Type; UserId = packet.UserId; ProjectId = packet.ProjectId; Results = packet.Results; ProcessingTime = packet.ProcessingTime; } catch (Exception err) { Log.Trace("LiveResultPacket(): Error converting json: " + err); } } /// /// Compose Live Result Data Packet - With tradable dates /// /// Job that started this request /// Results class for the Backtest job public LiveResultPacket(LiveNodePacket job, LiveResult results) :base (PacketType.LiveResult) { try { SessionId = job.SessionId; CompileId = job.CompileId; DeployId = job.DeployId; Results = results; UserId = job.UserId; ProjectId = job.ProjectId; SessionId = job.SessionId; Channel = job.Channel; } catch (Exception err) { Log.Error(err); } } } // End Queue Packet: /// /// Live results object class for packaging live result data. /// public class LiveResult : Result { /// /// Holdings dictionary of algorithm holdings information /// public IDictionary Holdings = new Dictionary(); /// /// Cashbook for the algorithm's live results. /// public CashBook Cash; /// /// Server status information, including CPU/RAM usage, ect... /// public IDictionary ServerStatistics = new Dictionary(); /// /// Default Constructor /// public LiveResult() { } /// /// Constructor for the result class for dictionary objects /// public LiveResult(IDictionary charts, IDictionary orders, IDictionary profitLoss, IDictionary holdings, CashBook cashbook, IDictionary statistics, IDictionary runtime, IDictionary serverStatistics = null) { Charts = charts; Orders = orders; ProfitLoss = profitLoss; Statistics = statistics; Holdings = holdings; Cash = cashbook; RuntimeStatistics = runtime; ServerStatistics = serverStatistics ?? OS.GetServerStatistics(); } } } // End of Namespace: