chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Packet to communicate updates to the algorithm's name
|
||||
/// </summary>
|
||||
public class AlgorithmNameUpdatePacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm id for this order event
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The new name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public AlgorithmNameUpdatePacket()
|
||||
: base(PacketType.AlgorithmNameUpdate)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of the algorithm tags up[date packet
|
||||
/// </summary>
|
||||
public AlgorithmNameUpdatePacket(string algorithmId, string name)
|
||||
: base(PacketType.AlgorithmNameUpdate)
|
||||
{
|
||||
AlgorithmId = algorithmId;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm Node Packet is a work task for the Lean Engine
|
||||
/// </summary>
|
||||
public class AlgorithmNodePacket : PythonEnvironmentPacket
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor for the algorithm node:
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
public AlgorithmNodePacket(PacketType type)
|
||||
: base(type)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// The host name to use if any
|
||||
/// </summary>
|
||||
public string HostName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User Id placing request
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Project Id of the request
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project name of the request
|
||||
/// </summary>
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm Id - BacktestId or DeployId - Common Id property between packets.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// User session Id for authentication
|
||||
/// </summary>
|
||||
public string SessionId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Language flag: Currently represents IL code or Dynamic Scripted Types.
|
||||
/// </summary>
|
||||
public Language Language { get; set; } = Language.CSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Server type for the deployment (512, 1024, 2048)
|
||||
/// </summary>
|
||||
public ServerType ServerType { get; set; } = ServerType.Server512;
|
||||
|
||||
/// <summary>
|
||||
/// Unique compile id of this backtest
|
||||
/// </summary>
|
||||
public string CompileId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Version number identifier for the lean engine.
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public bool Redelivered { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm binary with zip of contents
|
||||
/// </summary>
|
||||
public byte[] Algorithm { get; set; } = Array.Empty<byte>();
|
||||
|
||||
/// <summary>
|
||||
/// Request source - Web IDE or API - for controling result handler behaviour
|
||||
/// </summary>
|
||||
public string RequestSource { get; set; } = "WebIDE";
|
||||
|
||||
/// <summary>
|
||||
/// The maximum amount of RAM (in MB) this algorithm is allowed to utilize
|
||||
/// </summary>
|
||||
public int RamAllocation {
|
||||
get { return Controls?.RamAllocation ?? 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies values to control algorithm limits
|
||||
/// </summary>
|
||||
public Controls Controls { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The parameter values used to set algorithm parameters
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Parameters { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// String name of the HistoryProvider we're running with
|
||||
/// </summary>
|
||||
public string HistoryProvider { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm running mode.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public virtual AlgorithmMode AlgorithmMode { get; } = AlgorithmMode.Backtesting;
|
||||
|
||||
/// <summary>
|
||||
/// Deployment target, either local or cloud.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DeploymentTarget DeploymentTarget { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique name for the algorithm defined by this packet
|
||||
/// </summary>
|
||||
public string GetAlgorithmName()
|
||||
{
|
||||
return Invariant($"{UserId}-{ProjectId}-{AlgorithmId}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm status update information packet
|
||||
/// </summary>
|
||||
public class AlgorithmStatusPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Current algorithm status
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public AlgorithmStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Chart we're subscribed to for live trading.
|
||||
/// </summary>
|
||||
public string ChartSubscription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional message or reason for state change.
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm Id associated with this status packet
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OptimizationId for this result packet if any
|
||||
/// </summary>
|
||||
public string OptimizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project Id associated with this status packet
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current state of the channel
|
||||
/// </summary>
|
||||
public string ChannelStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public AlgorithmStatusPacket()
|
||||
: base(PacketType.AlgorithmStatus)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize algorithm state packet:
|
||||
/// </summary>
|
||||
public AlgorithmStatusPacket(string algorithmId, int projectId, AlgorithmStatus status, string message = "")
|
||||
: base (PacketType.AlgorithmStatus)
|
||||
{
|
||||
Status = status;
|
||||
ProjectId = projectId;
|
||||
AlgorithmId = algorithmId;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Packet to communicate updates to the algorithm tags
|
||||
/// </summary>
|
||||
public class AlgorithmTagsUpdatePacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm id for this order event
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The new tags
|
||||
/// </summary>
|
||||
public HashSet<string> Tags { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public AlgorithmTagsUpdatePacket()
|
||||
: base(PacketType.AlgorithmTagsUpdate)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of the algorithm tags up[date packet
|
||||
/// </summary>
|
||||
public AlgorithmTagsUpdatePacket(string algorithmId, HashSet<string> tags)
|
||||
: base(PacketType.AlgorithmTagsUpdate)
|
||||
{
|
||||
AlgorithmId = algorithmId;
|
||||
Tags = tags;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Alpha job packet
|
||||
/// </summary>
|
||||
public class AlphaNodePacket : LiveNodePacket
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the alpha id
|
||||
/// </summary>
|
||||
public string AlphaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new default instance of the <see cref="AlgorithmNodePacket"/> class
|
||||
/// </summary>
|
||||
public AlphaNodePacket()
|
||||
{
|
||||
Type = PacketType.AlphaNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using QuantConnect.Orders;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a packet type for transmitting alpha insights data
|
||||
/// </summary>
|
||||
public class AlphaResultPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// The user's id that deployed the alpha stream
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The deployed alpha id. This is the id generated upon submssion to the alpha marketplace.
|
||||
/// If this is a user backtest or live algo then this will not be specified
|
||||
/// </summary>
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string AlphaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The algorithm's unique identifier
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The generated insights
|
||||
/// </summary>
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Insight> Insights { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The generated OrderEvents
|
||||
/// </summary>
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<OrderEvent> OrderEvents { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The new or updated Orders
|
||||
/// </summary>
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Order> Orders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AlphaResultPacket"/> class
|
||||
/// </summary>
|
||||
public AlphaResultPacket()
|
||||
: base(PacketType.AlphaResult)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AlphaResultPacket"/> class
|
||||
/// </summary>
|
||||
/// <param name="algorithmId">The algorithm's unique identifier</param>
|
||||
/// <param name="userId">The user's id</param>
|
||||
/// <param name="insights">Alphas generated by the algorithm</param>
|
||||
/// <param name="orderEvents">OrderEvents generated by the algorithm</param>
|
||||
/// <param name="orders">Orders generated or updated by the algorithm</param>
|
||||
public AlphaResultPacket(string algorithmId, int userId, List<Insight> insights = null, List<OrderEvent> orderEvents = null, List<Order> orders = null)
|
||||
: base(PacketType.AlphaResult)
|
||||
{
|
||||
UserId = userId;
|
||||
AlgorithmId = algorithmId;
|
||||
Insights = insights;
|
||||
OrderEvents = orderEvents;
|
||||
Orders = orders;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Util;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm backtest task information packet.
|
||||
/// </summary>
|
||||
public class BacktestNodePacket : AlgorithmNodePacket
|
||||
{
|
||||
// default random id, static so its one per process
|
||||
private static readonly string DefaultId
|
||||
= Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// Name of the backtest as randomly defined in the IDE.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// BacktestId / Algorithm Id for this task
|
||||
/// </summary>
|
||||
public string BacktestId { get; set; } = DefaultId;
|
||||
|
||||
/// <summary>
|
||||
/// Optimization Id for this task
|
||||
/// </summary>
|
||||
public string OptimizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest start-date as defined in the Initialize() method.
|
||||
/// </summary>
|
||||
public DateTime? PeriodStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest end date as defined in the Initialize() method.
|
||||
/// </summary>
|
||||
public DateTime? PeriodFinish { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest maximum end date
|
||||
/// </summary>
|
||||
public DateTime? OutOfSampleMaxEndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest out of sample day count
|
||||
/// </summary>
|
||||
public int OutOfSampleDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Estimated number of trading days in this backtest task based on the start-end dates.
|
||||
/// </summary>
|
||||
public int TradeableDates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True, if this is a debugging backtest
|
||||
/// </summary>
|
||||
public bool Debugging { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional initial cash amount if set
|
||||
/// </summary>
|
||||
public CashAmount? CashAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm running mode.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public override AlgorithmMode AlgorithmMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return OptimizationId.IsNullOrEmpty() ? AlgorithmMode.Backtesting : AlgorithmMode.Optimization;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public BacktestNodePacket()
|
||||
: base(PacketType.BacktestNode)
|
||||
{
|
||||
Controls = new Controls
|
||||
{
|
||||
MinuteLimit = 500,
|
||||
SecondLimit = 100,
|
||||
TickLimit = 30
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the backtest task packet.
|
||||
/// </summary>
|
||||
public BacktestNodePacket(int userId, int projectId, string sessionId, byte[] algorithmData, decimal startingCapital, string name)
|
||||
: this (userId, projectId, sessionId, algorithmData, name, new CashAmount(startingCapital, Currencies.USD))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the backtest task packet.
|
||||
/// </summary>
|
||||
public BacktestNodePacket(int userId, int projectId, string sessionId, byte[] algorithmData, string name, CashAmount? startingCapital = null)
|
||||
: base(PacketType.BacktestNode)
|
||||
{
|
||||
UserId = userId;
|
||||
Algorithm = algorithmData;
|
||||
SessionId = sessionId;
|
||||
ProjectId = projectId;
|
||||
Name = name;
|
||||
CashAmount = startingCapital;
|
||||
Language = Language.CSharp;
|
||||
Controls = new Controls
|
||||
{
|
||||
MinuteLimit = 500,
|
||||
SecondLimit = 100,
|
||||
TickLimit = 30
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Logging;
|
||||
using QuantConnect.Statistics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Backtest result packet: send backtest information to GUI for user consumption.
|
||||
/// </summary>
|
||||
public class BacktestResultPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// User Id placing this task
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project Id of the this task.
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User Session Id
|
||||
/// </summary>
|
||||
public string SessionId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// BacktestId for this result packet
|
||||
/// </summary>
|
||||
public string BacktestId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// OptimizationId for this result packet if any
|
||||
/// </summary>
|
||||
public string OptimizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compile Id for the algorithm which generated this result packet.
|
||||
/// </summary>
|
||||
public string CompileId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Start of the backtest period as defined in Initialize() method.
|
||||
/// </summary>
|
||||
public DateTime PeriodStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// End of the backtest period as defined in the Initialize() method.
|
||||
/// </summary>
|
||||
public DateTime PeriodFinish { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DateTime (EST) the user requested this backtest.
|
||||
/// </summary>
|
||||
public DateTime DateRequested { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DateTime (EST) when the backtest was completed.
|
||||
/// </summary>
|
||||
public DateTime DateFinished { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Progress of the backtest as a percentage from 0-1 based on the days lapsed from start-finish.
|
||||
/// </summary>
|
||||
public decimal Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of this backtest.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Result data object for this backtest
|
||||
/// </summary>
|
||||
public BacktestResult Results { get; set; } = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Processing time of the algorithm (from moment the algorithm arrived on the algorithm node)
|
||||
/// </summary>
|
||||
public double ProcessingTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Estimated number of tradeable days in the backtest based on the start and end date or the backtest
|
||||
/// </summary>
|
||||
public int TradeableDates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON Serialization
|
||||
/// </summary>
|
||||
public BacktestResultPacket()
|
||||
: base(PacketType.BacktestResult)
|
||||
{
|
||||
PeriodStart = PeriodFinish = DateRequested = DateFinished = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compose the packet from a JSON string:
|
||||
/// </summary>
|
||||
public BacktestResultPacket(string json)
|
||||
: base (PacketType.BacktestResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
var packet = JsonConvert.DeserializeObject<BacktestResultPacket>(json, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
CompileId = packet.CompileId;
|
||||
Channel = packet.Channel;
|
||||
PeriodFinish = packet.PeriodFinish;
|
||||
PeriodStart = packet.PeriodStart;
|
||||
Progress = packet.Progress;
|
||||
SessionId = packet.SessionId;
|
||||
BacktestId = packet.BacktestId;
|
||||
Type = packet.Type;
|
||||
UserId = packet.UserId;
|
||||
DateFinished = packet.DateFinished;
|
||||
DateRequested = packet.DateRequested;
|
||||
Name = packet.Name;
|
||||
ProjectId = packet.ProjectId;
|
||||
Results = packet.Results;
|
||||
ProcessingTime = packet.ProcessingTime;
|
||||
TradeableDates = packet.TradeableDates;
|
||||
OptimizationId = packet.OptimizationId;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Trace($"BacktestResultPacket(): Error converting json: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Compose result data packet - with tradable dates from the backtest job task and the partial result packet.
|
||||
/// </summary>
|
||||
/// <param name="job">Job that started this request</param>
|
||||
/// <param name="results">Results class for the Backtest job</param>
|
||||
/// <param name="endDate">The algorithms backtest end date</param>
|
||||
/// <param name="startDate">The algorithms backtest start date</param>
|
||||
/// <param name="progress">Progress of the packet. For the packet we assume progess of 100%.</param>
|
||||
public BacktestResultPacket(BacktestNodePacket job, BacktestResult results, DateTime endDate, DateTime startDate, decimal progress = 1m)
|
||||
: this()
|
||||
{
|
||||
try
|
||||
{
|
||||
Progress = Math.Round(progress, 3);
|
||||
SessionId = job.SessionId;
|
||||
PeriodFinish = endDate;
|
||||
PeriodStart = startDate;
|
||||
CompileId = job.CompileId;
|
||||
Channel = job.Channel;
|
||||
BacktestId = job.BacktestId;
|
||||
OptimizationId = job.OptimizationId;
|
||||
Results = results;
|
||||
Name = job.Name;
|
||||
UserId = job.UserId;
|
||||
ProjectId = job.ProjectId;
|
||||
SessionId = job.SessionId;
|
||||
TradeableDates = job.TradeableDates;
|
||||
}
|
||||
catch (Exception err) {
|
||||
Log.Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty result packet, useful when the algorithm fails to initialize
|
||||
/// </summary>
|
||||
/// <param name="job">The associated job packet</param>
|
||||
/// <returns>An empty result packet</returns>
|
||||
public static BacktestResultPacket CreateEmpty(BacktestNodePacket job)
|
||||
{
|
||||
return new BacktestResultPacket(job, new BacktestResult(new BacktestResultParameters(
|
||||
new Dictionary<string, Chart>(), new Dictionary<int, Order>(), new Dictionary<DateTime, decimal>(),
|
||||
new Dictionary<string, string>(), new SortedDictionary<string, string>(), new Dictionary<string, AlgorithmPerformance>(),
|
||||
new List<OrderEvent>(), new AlgorithmPerformance(), new AlgorithmConfiguration(), new Dictionary<string, string>()
|
||||
)), DateTime.UtcNow, DateTime.UtcNow);
|
||||
}
|
||||
} // End Queue Packet:
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Backtest results object class - result specific items from the packet.
|
||||
/// </summary>
|
||||
public class BacktestResult : Result
|
||||
{
|
||||
/// <summary>
|
||||
/// Rolling window detailed statistics.
|
||||
/// </summary>
|
||||
public Dictionary<string, AlgorithmPerformance> RollingWindow { get; set; } = new Dictionary<string, AlgorithmPerformance>();
|
||||
|
||||
/// <summary>
|
||||
/// Default Constructor
|
||||
/// </summary>
|
||||
public BacktestResult()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the result class using dictionary objects.
|
||||
/// </summary>
|
||||
public BacktestResult(BacktestResultParameters parameters) : base(parameters)
|
||||
{
|
||||
RollingWindow = parameters.RollingWindow;
|
||||
}
|
||||
}
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 QuantConnect.Orders;
|
||||
using QuantConnect.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the parameters for <see cref="BacktestResult"/>
|
||||
/// </summary>
|
||||
public class BacktestResultParameters : BaseResultParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Rolling window detailed statistics.
|
||||
/// </summary>
|
||||
public Dictionary<string, AlgorithmPerformance> RollingWindow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance
|
||||
/// </summary>
|
||||
public BacktestResultParameters(IDictionary<string, Chart> charts,
|
||||
IDictionary<int, Order> orders,
|
||||
IDictionary<DateTime, decimal> profitLoss,
|
||||
IDictionary<string, string> statistics,
|
||||
IDictionary<string, string> runtimeStatistics,
|
||||
Dictionary<string, AlgorithmPerformance> rollingWindow,
|
||||
List<OrderEvent> orderEvents,
|
||||
AlgorithmPerformance totalPerformance = null,
|
||||
AlgorithmConfiguration algorithmConfiguration = null,
|
||||
IDictionary<string, string> state = null,
|
||||
IReadOnlyList<Analysis> analysisResult = null)
|
||||
: base(charts, orders, profitLoss, statistics, runtimeStatistics, orderEvents, totalPerformance, algorithmConfiguration, state, analysisResult)
|
||||
{
|
||||
RollingWindow = rollingWindow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 QuantConnect.Orders;
|
||||
using QuantConnect.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Base parameters used by <see cref="LiveResultParameters"/> and <see cref="BacktestResultParameters"/>
|
||||
/// </summary>
|
||||
public class BaseResultParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Trade profit and loss information since the last algorithm result packet
|
||||
/// </summary>
|
||||
public IDictionary<DateTime, decimal> ProfitLoss { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Charts updates for the live algorithm since the last result packet
|
||||
/// </summary>
|
||||
public IDictionary<string, Chart> Charts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order updates since the last result packet
|
||||
/// </summary>
|
||||
public IDictionary<int, Order> Orders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order events updates since the last result packet
|
||||
/// </summary>
|
||||
public List<OrderEvent> OrderEvents { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Statistics information sent during the algorithm operations.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> Statistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runtime banner/updating statistics in the title banner of the live algorithm GUI.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> RuntimeStatistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// State information of the algorithm.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The algorithm's configuration required for report generation
|
||||
/// </summary>
|
||||
public AlgorithmConfiguration AlgorithmConfiguration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rolling window detailed statistics.
|
||||
/// </summary>
|
||||
public AlgorithmPerformance TotalPerformance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest analysis results.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Analysis> Analysis { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance
|
||||
/// </summary>
|
||||
public BaseResultParameters(IDictionary<string, Chart> charts,
|
||||
IDictionary<int, Order> orders,
|
||||
IDictionary<DateTime, decimal> profitLoss,
|
||||
IDictionary<string, string> statistics,
|
||||
IDictionary<string, string> runtimeStatistics,
|
||||
List<OrderEvent> orderEvents,
|
||||
AlgorithmPerformance totalPerformance = null,
|
||||
AlgorithmConfiguration algorithmConfiguration = null,
|
||||
IDictionary<string, string> state = null,
|
||||
IReadOnlyList<Analysis> analysisResult = null)
|
||||
{
|
||||
Charts = charts;
|
||||
Orders = orders;
|
||||
ProfitLoss = profitLoss;
|
||||
Statistics = statistics;
|
||||
RuntimeStatistics = runtimeStatistics;
|
||||
OrderEvents = orderEvents;
|
||||
AlgorithmConfiguration = algorithmConfiguration;
|
||||
State = state;
|
||||
TotalPerformance = totalPerformance;
|
||||
Analysis = analysisResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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 QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies values used to control algorithm limits
|
||||
/// </summary>
|
||||
public class Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum runtime in minutes
|
||||
/// </summary>
|
||||
public int MaximumRuntimeMinutes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of minute symbols
|
||||
/// </summary>
|
||||
public int MinuteLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of second symbols
|
||||
/// </summary>
|
||||
public int SecondLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of tick symbol
|
||||
/// </summary>
|
||||
public int TickLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ram allocation for this algorithm in MB
|
||||
/// </summary>
|
||||
public int RamAllocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CPU allocation for this algorithm
|
||||
/// </summary>
|
||||
public decimal CpuAllocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user live log limit
|
||||
/// </summary>
|
||||
public int LiveLogLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user backtesting log limit
|
||||
/// </summary>
|
||||
public int BacktestLogLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The daily log limit of a user
|
||||
/// </summary>
|
||||
public int DailyLogLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The remaining log allowance for a user
|
||||
/// </summary>
|
||||
public int RemainingLogAllowance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximimum number of insights we'll store and score in a single backtest
|
||||
/// </summary>
|
||||
public int BacktestingMaxInsights { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximimum number of orders we'll allow in a backtest.
|
||||
/// </summary>
|
||||
public int BacktestingMaxOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limits the amount of data points per chart series. Applies only for backtesting
|
||||
/// </summary>
|
||||
public int MaximumDataPointsPerChartSeries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limits the amount of chart series. Applies only for backtesting
|
||||
/// </summary>
|
||||
public int MaximumChartSeries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount seconds used for timeout limits
|
||||
/// </summary>
|
||||
public int SecondTimeOut { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets parameters used for determining the behavior of the leaky bucket algorithm that
|
||||
/// controls how much time is available for an algorithm to use the training feature.
|
||||
/// </summary>
|
||||
public LeakyBucketControlParameters TrainingLimits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limits the total size of storage used by <see cref="IObjectStore"/>
|
||||
/// </summary>
|
||||
public long StorageLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limits the number of files to be held under the <see cref="IObjectStore"/>
|
||||
/// </summary>
|
||||
public int StorageFileCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the permissions for the object store
|
||||
/// </summary>
|
||||
public StoragePermissions StorageAccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The interval over which the <see cref="IObjectStore"/> will persistence the contents of
|
||||
/// the object store
|
||||
/// </summary>
|
||||
public int PersistenceIntervalSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The cost associated with running this job
|
||||
/// </summary>
|
||||
public decimal CreditCost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new default instance of the <see cref="Controls"/> class
|
||||
/// </summary>
|
||||
public Controls()
|
||||
{
|
||||
MinuteLimit = 500;
|
||||
SecondLimit = 100;
|
||||
TickLimit = 30;
|
||||
RamAllocation = 1024;
|
||||
BacktestLogLimit = 10000;
|
||||
BacktestingMaxOrders = int.MaxValue;
|
||||
DailyLogLimit = 3000000;
|
||||
RemainingLogAllowance = 10000;
|
||||
MaximumRuntimeMinutes = 60 * 24 * 100; // 100 days default
|
||||
BacktestingMaxInsights = 10000;
|
||||
MaximumChartSeries = 10;
|
||||
MaximumDataPointsPerChartSeries = 4000;
|
||||
SecondTimeOut = 300;
|
||||
StorageLimit = 10737418240;
|
||||
StorageFileCount = 10000;
|
||||
PersistenceIntervalSeconds = 5;
|
||||
StorageAccess = new StoragePermissions();
|
||||
|
||||
// initialize to default leaky bucket values in case they're not specified
|
||||
TrainingLimits = new LeakyBucketControlParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Send a simple debug message from the users algorithm to the console.
|
||||
/// </summary>
|
||||
public class DebugPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// String debug message to send to the users console
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Associated algorithm Id.
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compile id of the algorithm sending this message
|
||||
/// </summary>
|
||||
public string CompileId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project Id for this message
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True to emit message as a popup notification (toast),
|
||||
/// false to emit message in console as text
|
||||
/// </summary>
|
||||
public bool Toast { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public DebugPacket()
|
||||
: base (PacketType.Debug)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for inherited types
|
||||
/// </summary>
|
||||
/// <param name="packetType">The type of packet to create</param>
|
||||
protected DebugPacket(PacketType packetType)
|
||||
: base(packetType)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of the notify debug packet:
|
||||
/// </summary>
|
||||
public DebugPacket(int projectId, string algorithmId, string compileId, string message, bool toast = false)
|
||||
: base(PacketType.Debug)
|
||||
{
|
||||
ProjectId = projectId;
|
||||
Message = message;
|
||||
CompileId = compileId;
|
||||
AlgorithmId = algorithmId;
|
||||
Toast = toast;
|
||||
}
|
||||
|
||||
} // End Work Packet:
|
||||
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm runtime error packet from the lean engine.
|
||||
/// This is a managed error which stops the algorithm execution.
|
||||
/// </summary>
|
||||
public class HandledErrorPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Runtime error message from the exception
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm id which generated this runtime error
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Error stack trace information string passed through from the Lean exception
|
||||
/// </summary>
|
||||
public string StackTrace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public HandledErrorPacket()
|
||||
: base (PacketType.HandledError)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new handled error packet
|
||||
/// </summary>
|
||||
public HandledErrorPacket(string algorithmId, string message, string stacktrace = "")
|
||||
: base(PacketType.HandledError)
|
||||
{
|
||||
Message = message;
|
||||
AlgorithmId = algorithmId;
|
||||
StackTrace = stacktrace;
|
||||
}
|
||||
|
||||
} // End Work Packet:
|
||||
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Packet for history jobs
|
||||
/// </summary>
|
||||
public class HistoryPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// The queue where the data should be sent
|
||||
/// </summary>
|
||||
public string QueueName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The individual requests to be processed
|
||||
/// </summary>
|
||||
public List<HistoryRequest> Requests { get; set; } = new List<HistoryRequest>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HistoryPacket"/> class
|
||||
/// </summary>
|
||||
public HistoryPacket()
|
||||
: base(PacketType.History)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies request parameters for a single historical request.
|
||||
/// A HistoryPacket is made of multiple requests for data. These
|
||||
/// are used to request data during live mode from a data server
|
||||
/// </summary>
|
||||
public class HistoryRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The start time to request data in UTC
|
||||
/// </summary>
|
||||
public DateTime StartTimeUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The end time to request data in UTC
|
||||
/// </summary>
|
||||
public DateTime EndTimeUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The symbol to request data for
|
||||
/// </summary>
|
||||
public Symbol Symbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The requested resolution
|
||||
/// </summary>
|
||||
public Resolution Resolution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of data to retrieve
|
||||
/// </summary>
|
||||
public TickType TickType { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies various types of history results
|
||||
/// </summary>
|
||||
public enum HistoryResultType
|
||||
{
|
||||
/// <summary>
|
||||
/// The requested file data
|
||||
/// </summary>
|
||||
File,
|
||||
|
||||
/// <summary>
|
||||
/// The request's status
|
||||
/// </summary>
|
||||
Status,
|
||||
|
||||
/// <summary>
|
||||
/// The request is completed
|
||||
/// </summary>
|
||||
Completed,
|
||||
|
||||
/// <summary>
|
||||
/// The request had an error
|
||||
/// </summary>
|
||||
Error
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a container for results from history requests. This contains
|
||||
/// the file path relative to the /Data folder where the data can be written
|
||||
/// </summary>
|
||||
public abstract class HistoryResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of history result
|
||||
/// </summary>
|
||||
public HistoryResultType Type { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HistoryResult"/> class
|
||||
/// </summary>
|
||||
/// <param name="type">The type of history result</param>
|
||||
protected HistoryResult(HistoryResultType type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines requested file data for a history request
|
||||
/// </summary>
|
||||
public class FileHistoryResult : HistoryResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The relative file path where the data should be written
|
||||
/// </summary>
|
||||
public string Filepath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The file's contents, this is a zipped csv file
|
||||
/// </summary>
|
||||
public byte[] File { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for serializers
|
||||
/// </summary>
|
||||
public FileHistoryResult()
|
||||
: base(HistoryResultType.File)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HistoryResult"/> class
|
||||
/// </summary>
|
||||
/// <param name="filepath">The relative file path where the file should be written, rooted in /Data, so for example ./forex/fxcm/daily/eurusd.zip</param>
|
||||
/// <param name="file">The zipped csv file content in bytes</param>
|
||||
public FileHistoryResult(string filepath, byte[] file)
|
||||
: this()
|
||||
{
|
||||
Filepath = filepath;
|
||||
File = file;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the completed message from a history result
|
||||
/// </summary>
|
||||
public class CompletedHistoryResult : HistoryResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="CompletedHistoryResult"/> class
|
||||
/// </summary>
|
||||
public CompletedHistoryResult()
|
||||
: base(HistoryResultType.Completed)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specfies an error message in a history result
|
||||
/// </summary>
|
||||
public class ErrorHistoryResult : HistoryResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the error that was encountered
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for serializers
|
||||
/// </summary>
|
||||
public ErrorHistoryResult()
|
||||
: base(HistoryResultType.Error)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ErrorHistoryResult"/> class
|
||||
/// </summary>
|
||||
/// <param name="message">The error message</param>
|
||||
public ErrorHistoryResult(string message)
|
||||
: this()
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the progress of a request
|
||||
/// </summary>
|
||||
public class StatusHistoryResult : HistoryResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the progress of the request
|
||||
/// </summary>
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for serializers
|
||||
/// </summary>
|
||||
public StatusHistoryResult()
|
||||
: base(HistoryResultType.Status)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StatusHistoryResult"/> class
|
||||
/// </summary>
|
||||
/// <param name="progress">The progress, from 0 to 100</param>
|
||||
public StatusHistoryResult(int progress)
|
||||
: this()
|
||||
{
|
||||
Progress = progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using QuantConnect.Configuration;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides parameters that control the behavior of a leaky bucket rate limiting algorithm. The
|
||||
/// parameter names below are phrased in the positive, such that the bucket is filled up over time
|
||||
/// vs leaking out over time.
|
||||
/// </summary>
|
||||
public class LeakyBucketControlParameters
|
||||
{
|
||||
// defaults represent 2 hour max capacity refilling at one seventh the capacity (~17.2 => 18) each day.
|
||||
// rounded up to 18 to prevent a very small decrease in refilling, IOW, if it's defaulting to 17, then
|
||||
// after 7 days have passed, we'll end up being at 119 and not completely refilled, but at 18, on the 6th
|
||||
// day we'll reach 108 and on the seventh day it will top off at 120 since it's not permitted to exceed the max
|
||||
/// <summary>
|
||||
/// Default capacity for leaky bucket
|
||||
/// </summary>
|
||||
public static int DefaultCapacity { get; set; } = Config.GetInt("scheduled-event-leaky-bucket-capacity", 2 * 60);
|
||||
|
||||
/// <summary>
|
||||
/// Default time interval
|
||||
/// </summary>
|
||||
public static int DefaultTimeInterval { get; set; } = Config.GetInt("scheduled-event-leaky-bucket-time-interval-minutes", 1440);
|
||||
|
||||
/// <summary>
|
||||
/// Default refill amount
|
||||
/// </summary>
|
||||
public static int DefaultRefillAmount { get; set; } = Config.GetInt("scheduled-event-leaky-bucket-refill-amount", (int)Math.Ceiling(DefaultCapacity/7.0));
|
||||
|
||||
/// <summary>
|
||||
/// Sets the total capacity of the bucket in a leaky bucket algorithm. This is the maximum
|
||||
/// number of 'units' the bucket can hold and also defines the maximum burst rate, assuming
|
||||
/// instantaneous usage of 'units'. In reality, the usage of 'units' takes times, and so it
|
||||
/// is possible for the bucket to incrementally refill while consuming from the bucket.
|
||||
/// </summary>
|
||||
public int Capacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the refill amount of the bucket. This defines the quantity of 'units' that become available
|
||||
/// to a consuming entity after the time interval has elapsed. For example, if the refill amount is
|
||||
/// equal to one, then each time interval one new 'unit' will be made available for a consumer that is
|
||||
/// throttled by the leaky bucket.
|
||||
/// </summary>
|
||||
public int RefillAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the time interval for the refill amount of the bucket, in minutes. After this amount of wall-clock
|
||||
/// time has passed, the bucket will refill the refill amount, thereby making more 'units' available
|
||||
/// for a consumer. For example, if the refill amount equals 10 and the time interval is 30 minutes, then
|
||||
/// every 30 minutes, 10 more 'units' become available for a consumer. The available 'units' will
|
||||
/// continue to increase until the bucket capacity is reached.
|
||||
/// </summary>
|
||||
public int TimeIntervalMinutes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LeakyBucketControlParameters"/> using default values
|
||||
/// </summary>
|
||||
public LeakyBucketControlParameters()
|
||||
{
|
||||
Capacity = DefaultCapacity;
|
||||
RefillAmount = DefaultRefillAmount;
|
||||
TimeIntervalMinutes = DefaultTimeInterval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LeakyBucketControlParameters"/> with the specified value
|
||||
/// </summary>
|
||||
/// <param name="capacity">The total capacity of the bucket in minutes</param>
|
||||
/// <param name="refillAmount">The number of additional minutes to add to the bucket
|
||||
/// after <paramref name="timeIntervalMinutes"/> has elapsed</param>
|
||||
/// <param name="timeIntervalMinutes">The interval, in minutes, that must pass before the <paramref name="refillAmount"/>
|
||||
/// is added back to the bucket for reuse</param>
|
||||
public LeakyBucketControlParameters(int capacity, int refillAmount, int timeIntervalMinutes)
|
||||
{
|
||||
Capacity = capacity;
|
||||
RefillAmount = refillAmount;
|
||||
TimeIntervalMinutes = timeIntervalMinutes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Notifications;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Live job task packet: container for any live specific job variables
|
||||
/// </summary>
|
||||
public class LiveNodePacket : AlgorithmNodePacket
|
||||
{
|
||||
/// <summary>
|
||||
/// Deploy Id for this live algorithm.
|
||||
/// </summary>
|
||||
public string DeployId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// String name of the brokerage we're trading with
|
||||
/// </summary>
|
||||
public string Brokerage { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// String-String Dictionary of Brokerage Data for this Live Job
|
||||
/// </summary>
|
||||
public Dictionary<string, string> BrokerageData { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// String name of the DataQueueHandler or LiveDataProvider we're running with
|
||||
/// </summary>
|
||||
public string DataQueueHandler { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// String name of the DataChannelProvider we're running with
|
||||
/// </summary>
|
||||
public string DataChannelProvider { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets flag indicating whether or not the message should be acknowledged and removed from the queue
|
||||
/// </summary>
|
||||
public bool DisableAcknowledgement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of event types to generate notifications for, which will use <see cref="NotificationTargets"/>
|
||||
/// </summary>
|
||||
public HashSet<string> NotificationEvents { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of notification targets to use
|
||||
/// </summary>
|
||||
public List<Notification> NotificationTargets { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of real time data types available in the live trading environment
|
||||
/// </summary>
|
||||
public HashSet<string> LiveDataTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm running mode.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public override AlgorithmMode AlgorithmMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return AlgorithmMode.Live;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON of the Live Task Packet
|
||||
/// </summary>
|
||||
public LiveNodePacket()
|
||||
: base(PacketType.LiveNode)
|
||||
{
|
||||
Controls = new Controls
|
||||
{
|
||||
MinuteLimit = 100,
|
||||
SecondLimit = 50,
|
||||
TickLimit = 25,
|
||||
RamAllocation = 512
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using QuantConnect.Logging;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Live result packet from a lean engine algorithm.
|
||||
/// </summary>
|
||||
public class LiveResultPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// User Id sending result packet
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project Id of the result packet
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Live Algorithm Id (DeployId) for this result packet
|
||||
/// </summary>
|
||||
public string DeployId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Result data object for this result packet
|
||||
/// </summary>
|
||||
public LiveResult Results { get; set; } = new LiveResult();
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON Serialization
|
||||
/// </summary>
|
||||
public LiveResultPacket()
|
||||
: base(PacketType.LiveResult)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Compose the packet from a JSON string:
|
||||
/// </summary>
|
||||
public LiveResultPacket(string json)
|
||||
: base(PacketType.LiveResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
var packet = JsonConvert.DeserializeObject<LiveResultPacket>(json);
|
||||
Channel = packet.Channel;
|
||||
DeployId = packet.DeployId;
|
||||
Type = packet.Type;
|
||||
UserId = packet.UserId;
|
||||
ProjectId = packet.ProjectId;
|
||||
Results = packet.Results;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Trace($"LiveResultPacket(): Error converting json: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compose Live Result Data Packet - With tradable dates
|
||||
/// </summary>
|
||||
/// <param name="job">Job that started this request</param>
|
||||
/// <param name="results">Results class for the Backtest job</param>
|
||||
public LiveResultPacket(LiveNodePacket job, LiveResult results)
|
||||
:base (PacketType.LiveResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
DeployId = job.DeployId;
|
||||
Results = results;
|
||||
UserId = job.UserId;
|
||||
ProjectId = job.ProjectId;
|
||||
Channel = job.Channel;
|
||||
}
|
||||
catch (Exception err) {
|
||||
Log.Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty result packet, useful when the algorithm fails to initialize
|
||||
/// </summary>
|
||||
/// <param name="job">The associated job packet</param>
|
||||
/// <returns>An empty result packet</returns>
|
||||
public static LiveResultPacket CreateEmpty(LiveNodePacket job)
|
||||
{
|
||||
return new LiveResultPacket(job, new LiveResult(new LiveResultParameters(
|
||||
new Dictionary<string, Chart>(), new Dictionary<int, Order>(), new Dictionary<DateTime, decimal>(),
|
||||
new Dictionary<string, Holding>(), new CashBook(), new Dictionary<string, string>(),
|
||||
new SortedDictionary<string, string>(), new List<OrderEvent>(), null, new Dictionary<string, string>(),
|
||||
new AlgorithmConfiguration(), new Dictionary<string, string>())));
|
||||
}
|
||||
} // End Queue Packet:
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Live results object class for packaging live result data.
|
||||
/// </summary>
|
||||
public class LiveResult : Result
|
||||
{
|
||||
private CashBook _cashBook;
|
||||
|
||||
/// <summary>
|
||||
/// Holdings dictionary of algorithm holdings information
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, Holding> Holdings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cashbook for the algorithm's live results.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public CashBook CashBook
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cashBook;
|
||||
}
|
||||
set
|
||||
{
|
||||
_cashBook = value;
|
||||
|
||||
Cash = _cashBook?.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
AccountCurrency = CashBook?.AccountCurrency;
|
||||
AccountCurrencySymbol = AccountCurrency != null ? Currencies.GetCurrencySymbol(AccountCurrency) : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cash for the algorithm's live results.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public Dictionary<string, Cash> Cash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The algorithm's account currency
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string AccountCurrency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The algorithm's account currency
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string AccountCurrencySymbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default Constructor
|
||||
/// </summary>
|
||||
public LiveResult()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the result class for dictionary objects
|
||||
/// </summary>
|
||||
public LiveResult(LiveResultParameters parameters) : base(parameters)
|
||||
{
|
||||
Holdings = parameters.Holdings;
|
||||
CashBook = parameters.CashBook;
|
||||
}
|
||||
}
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the parameters for <see cref="LiveResult"/>
|
||||
/// </summary>
|
||||
public class LiveResultParameters : BaseResultParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Holdings dictionary of algorithm holdings information
|
||||
/// </summary>
|
||||
public IDictionary<string, Holding> Holdings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cashbook for the algorithm's live results.
|
||||
/// </summary>
|
||||
public CashBook CashBook { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Server status information, including CPU/RAM usage, ect...
|
||||
/// </summary>
|
||||
public IDictionary<string, string> ServerStatistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance
|
||||
/// </summary>
|
||||
public LiveResultParameters(IDictionary<string, Chart> charts,
|
||||
IDictionary<int, Order> orders,
|
||||
IDictionary<DateTime, decimal> profitLoss,
|
||||
IDictionary<string, Holding> holdings,
|
||||
CashBook cashBook,
|
||||
IDictionary<string, string> statistics,
|
||||
IDictionary<string, string> runtimeStatistics,
|
||||
List<OrderEvent> orderEvents,
|
||||
AlgorithmPerformance totalPerformance = null,
|
||||
IDictionary<string, string> serverStatistics = null,
|
||||
AlgorithmConfiguration algorithmConfiguration = null,
|
||||
IDictionary<string, string> state = null,
|
||||
IReadOnlyList<Analysis> analysisResult = null)
|
||||
: base(charts, orders, profitLoss, statistics, runtimeStatistics, orderEvents, totalPerformance, algorithmConfiguration, state, analysisResult)
|
||||
{
|
||||
Holdings = holdings;
|
||||
CashBook = cashBook;
|
||||
ServerStatistics = serverStatistics ?? OS.GetServerStatistics();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple log message instruction from the lean engine.
|
||||
/// </summary>
|
||||
public class LogPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Log message to the users console:
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm Id requesting this logging
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public LogPacket()
|
||||
: base (PacketType.Log)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of the notify Log packet:
|
||||
/// </summary>
|
||||
public LogPacket(string algorithmId, string message)
|
||||
: base(PacketType.Log)
|
||||
{
|
||||
Message = message;
|
||||
AlgorithmId = algorithmId;
|
||||
}
|
||||
|
||||
} // End Work Packet:
|
||||
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Market today information class
|
||||
/// </summary>
|
||||
public class MarketToday
|
||||
{
|
||||
/// <summary>
|
||||
/// Date this packet was generated.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "date")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Given the dates and times above, what is the current market status - open or closed.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "status")]
|
||||
public string Status { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Premarket hours for today
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "premarket")]
|
||||
public MarketHours PreMarket { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Normal trading market hours for today
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "open")]
|
||||
public MarketHours Open { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Post market hours for today
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "postmarket")]
|
||||
public MarketHours PostMarket { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor (required for JSON serialization)
|
||||
/// </summary>
|
||||
public MarketToday()
|
||||
{ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Market open hours model for pre, normal and post market hour definitions.
|
||||
/// </summary>
|
||||
public class MarketHours
|
||||
{
|
||||
/// <summary>
|
||||
/// Start time for this market hour category
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "start")]
|
||||
public DateTime Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// End time for this market hour category
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "end")]
|
||||
public DateTime End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Market hours initializer given an hours since midnight measure for the market hours today
|
||||
/// </summary>
|
||||
/// <param name="referenceDate">Reference date used for as base date from the specified hour offsets</param>
|
||||
/// <param name="defaultStart">Time in hours since midnight to start this open period.</param>
|
||||
/// <param name="defaultEnd">Time in hours since midnight to end this open period.</param>
|
||||
public MarketHours(DateTime referenceDate, double defaultStart, double defaultEnd)
|
||||
{
|
||||
Start = referenceDate.Date.AddHours(defaultStart);
|
||||
End = referenceDate.Date.AddHours(defaultEnd);
|
||||
if (defaultEnd == 24)
|
||||
{
|
||||
// when we mark it as the end of the day other code that relies on .TimeOfDay has issues
|
||||
End = End.AddTicks(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Order event packet for passing updates on the state of an order to the portfolio.
|
||||
/// </summary>
|
||||
/// <remarks>As an order is updated in pieces/partial fills the order fill price is passed back to the Algorithm Portfolio method</remarks>
|
||||
public class OrderEventPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Order event object
|
||||
/// </summary>
|
||||
public OrderEvent Event { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm id for this order event
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public OrderEventPacket()
|
||||
: base (PacketType.OrderEvent)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of the order event packet
|
||||
/// </summary>
|
||||
public OrderEventPacket(string algorithmId, OrderEvent eventOrder)
|
||||
: base(PacketType.OrderEvent)
|
||||
{
|
||||
AlgorithmId = algorithmId;
|
||||
Event = eventOrder;
|
||||
}
|
||||
|
||||
} // End Order Event Packet:
|
||||
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for packet messaging system
|
||||
/// </summary>
|
||||
public class Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Packet type defined by a string enum
|
||||
/// </summary>
|
||||
public PacketType Type { get; set; } = PacketType.None;
|
||||
|
||||
/// <summary>
|
||||
/// User unique specific channel endpoint to send the packets
|
||||
/// </summary>
|
||||
public virtual string Channel { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the base class and setup the packet type.
|
||||
/// </summary>
|
||||
/// <param name="type">PacketType for the class.</param>
|
||||
public Packet(PacketType type)
|
||||
{
|
||||
Channel = "";
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Classifications of internal packet system
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum PacketType
|
||||
{
|
||||
/// <summary>
|
||||
/// Default, unset:
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Base type for backtest and live work
|
||||
/// </summary>
|
||||
AlgorithmNode,
|
||||
|
||||
/// <summary>
|
||||
/// Autocomplete Work Packet
|
||||
/// </summary>
|
||||
AutocompleteWork,
|
||||
|
||||
/// <summary>
|
||||
/// Result of the Autocomplete Job:
|
||||
/// </summary>
|
||||
AutocompleteResult,
|
||||
|
||||
/// <summary>
|
||||
/// Controller->Backtest Node Packet:
|
||||
/// </summary>
|
||||
BacktestNode,
|
||||
|
||||
/// <summary>
|
||||
/// Packet out of backtest node:
|
||||
/// </summary>
|
||||
BacktestResult,
|
||||
|
||||
/// <summary>
|
||||
/// API-> Controller Work Packet:
|
||||
/// </summary>
|
||||
BacktestWork,
|
||||
|
||||
/// <summary>
|
||||
/// Controller -> Live Node Packet:
|
||||
/// </summary>
|
||||
LiveNode,
|
||||
|
||||
/// <summary>
|
||||
/// Live Node -> User Packet:
|
||||
/// </summary>
|
||||
LiveResult,
|
||||
|
||||
/// <summary>
|
||||
/// API -> Controller Packet:
|
||||
/// </summary>
|
||||
LiveWork,
|
||||
|
||||
/// <summary>
|
||||
/// Node -> User Algo Security Types
|
||||
/// </summary>
|
||||
SecurityTypes,
|
||||
|
||||
/// <summary>
|
||||
/// Controller -> User Error in Backtest Settings:
|
||||
/// </summary>
|
||||
BacktestError,
|
||||
|
||||
/// <summary>
|
||||
/// Nodes -> User Algorithm Status Packet:
|
||||
/// </summary>
|
||||
AlgorithmStatus,
|
||||
|
||||
/// <summary>
|
||||
/// API -> Compiler Work Packet:
|
||||
/// </summary>
|
||||
BuildWork,
|
||||
|
||||
/// <summary>
|
||||
/// Compiler -> User Build Success
|
||||
/// </summary>
|
||||
BuildSuccess,
|
||||
|
||||
/// <summary>
|
||||
/// Compiler -> User, Compile Error
|
||||
/// </summary>
|
||||
BuildError,
|
||||
|
||||
/// <summary>
|
||||
/// Node -> User Algorithm Runtime Error
|
||||
/// </summary>
|
||||
RuntimeError,
|
||||
|
||||
/// <summary>
|
||||
/// Error is an internal handled error packet inside users algorithm
|
||||
/// </summary>
|
||||
HandledError,
|
||||
|
||||
/// <summary>
|
||||
/// Nodes -> User Log Message
|
||||
/// </summary>
|
||||
Log,
|
||||
|
||||
/// <summary>
|
||||
/// Nodes -> User Debug Message
|
||||
/// </summary>
|
||||
Debug,
|
||||
|
||||
/// <summary>
|
||||
/// Nodes -> User, Order Update Event
|
||||
/// </summary>
|
||||
OrderEvent,
|
||||
|
||||
/// <summary>
|
||||
/// Boolean true/false success
|
||||
/// </summary>
|
||||
Success,
|
||||
|
||||
/// <summary>
|
||||
/// History live job packets
|
||||
/// </summary>
|
||||
History,
|
||||
|
||||
/// <summary>
|
||||
/// Result from a command
|
||||
/// </summary>
|
||||
CommandResult,
|
||||
|
||||
/// <summary>
|
||||
/// Hook from git hub
|
||||
/// </summary>
|
||||
GitHubHook,
|
||||
|
||||
/// <summary>
|
||||
/// Documentation result from docs server
|
||||
/// </summary>
|
||||
DocumentationResult,
|
||||
|
||||
/// <summary>
|
||||
/// Documentation request to the docs server
|
||||
/// </summary>
|
||||
Documentation,
|
||||
|
||||
/// <summary>
|
||||
/// Debug packet generated by Lean
|
||||
/// </summary>
|
||||
SystemDebug,
|
||||
|
||||
/// <summary>
|
||||
/// Packet containing insights generated by the algorithm
|
||||
/// </summary>
|
||||
AlphaResult,
|
||||
|
||||
/// <summary>
|
||||
/// Alpha API -> Controller packet
|
||||
/// </summary>
|
||||
AlphaWork,
|
||||
|
||||
/// <summary>
|
||||
/// Alpha Controller -> Alpha Node packet
|
||||
/// </summary>
|
||||
AlphaNode,
|
||||
|
||||
/// <summary>
|
||||
/// Packet containing list of algorithms to run as a regression test
|
||||
/// </summary>
|
||||
RegressionAlgorithm,
|
||||
|
||||
/// <summary>
|
||||
/// Packet containing a heartbeat
|
||||
/// </summary>
|
||||
AlphaHeartbeat,
|
||||
|
||||
/// <summary>
|
||||
/// Used when debugging to send status updates
|
||||
/// </summary>
|
||||
DebuggingStatus,
|
||||
|
||||
/// <summary>
|
||||
/// Optimization Node Packet:
|
||||
/// </summary>
|
||||
OptimizationNode,
|
||||
|
||||
/// <summary>
|
||||
/// Optimization Estimate Packet:
|
||||
/// </summary>
|
||||
OptimizationEstimate,
|
||||
|
||||
/// <summary>
|
||||
/// Optimization work status update
|
||||
/// </summary>
|
||||
OptimizationStatus,
|
||||
|
||||
/// <summary>
|
||||
/// Optimization work result
|
||||
/// </summary>
|
||||
OptimizationResult,
|
||||
|
||||
/// <summary>
|
||||
/// Aggregated packets
|
||||
/// </summary>
|
||||
Aggregated,
|
||||
|
||||
/// <summary>
|
||||
/// Query the language model
|
||||
/// </summary>
|
||||
LanguageModelQuery,
|
||||
|
||||
/// <summary>
|
||||
/// Send feedback to a language model response
|
||||
/// </summary>
|
||||
LanguageModelFeedback,
|
||||
|
||||
/// <summary>
|
||||
/// The language models response
|
||||
/// </summary>
|
||||
LanguageModelResponse,
|
||||
|
||||
/// <summary>
|
||||
/// Language model code analysis
|
||||
/// </summary>
|
||||
LanguageModelCodeAnalysis,
|
||||
|
||||
/// <summary>
|
||||
/// Language model chat work
|
||||
/// </summary>
|
||||
LanguageModelChatWork,
|
||||
|
||||
/// <summary>
|
||||
/// Language model chat response
|
||||
/// </summary>
|
||||
LanguageModelChatResponse,
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm name update
|
||||
/// </summary>
|
||||
AlgorithmNameUpdate,
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm tags update
|
||||
/// </summary>
|
||||
AlgorithmTagsUpdate,
|
||||
|
||||
/// <summary>
|
||||
/// Research job packet
|
||||
/// </summary>
|
||||
ResearchNode,
|
||||
|
||||
/// <summary>
|
||||
/// Organization update
|
||||
/// </summary>
|
||||
OrganizationUpdate,
|
||||
|
||||
/// <summary>
|
||||
/// Compiler -> User Build Warnings
|
||||
/// </summary>
|
||||
BuildWarning,
|
||||
|
||||
/// <summary>
|
||||
/// Language model function call related packet
|
||||
/// </summary>
|
||||
LanguageModelFunctionCall,
|
||||
|
||||
/// <summary>
|
||||
/// Language model agent message
|
||||
/// </summary>
|
||||
LanguageModelAgentMessage,
|
||||
|
||||
/// <summary>
|
||||
/// Agent job packet
|
||||
/// </summary>
|
||||
AgentNode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Python Environment Packet is an abstract packet that contains a PythonVirtualEnvironment
|
||||
/// definition. Intended to be used by inheriting classes that may use a PythonVirtualEnvironment
|
||||
/// </summary>
|
||||
public abstract class PythonEnvironmentPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor for a PythonEnvironmentPacket
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
protected PythonEnvironmentPacket(PacketType type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Virtual environment ID used to find PythonEvironments
|
||||
/// Ideally MD5, but environment names work as well.
|
||||
/// </summary>
|
||||
public string PythonVirtualEnvironment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a research node packet
|
||||
/// </summary>
|
||||
public class ResearchNodePacket : AlgorithmNodePacket
|
||||
{
|
||||
/// <summary>
|
||||
/// The research id
|
||||
/// </summary>
|
||||
public string ResearchId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Associated research token
|
||||
/// </summary>
|
||||
public string ResearchToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance
|
||||
/// </summary>
|
||||
public ResearchNodePacket() : base(PacketType.ResearchNode)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm runtime error packet from the lean engine.
|
||||
/// This is a managed error which stops the algorithm execution.
|
||||
/// </summary>
|
||||
public class RuntimeErrorPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// Runtime error message from the exception
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm id which generated this runtime error
|
||||
/// </summary>
|
||||
public string AlgorithmId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Error stack trace information string passed through from the Lean exception
|
||||
/// </summary>
|
||||
public string StackTrace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User Id associated with the backtest that threw the error
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public RuntimeErrorPacket()
|
||||
: base (PacketType.RuntimeError)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new runtime error packet
|
||||
/// </summary>
|
||||
public RuntimeErrorPacket(int userId, string algorithmId, string message, string stacktrace = "")
|
||||
: base(PacketType.RuntimeError)
|
||||
{
|
||||
UserId = userId;
|
||||
Message = message;
|
||||
AlgorithmId = algorithmId;
|
||||
StackTrace = stacktrace;
|
||||
}
|
||||
|
||||
} // End Work Packet:
|
||||
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Security types packet contains information on the markets the user data has requested.
|
||||
/// </summary>
|
||||
public class SecurityTypesPacket : Packet
|
||||
{
|
||||
/// <summary>
|
||||
/// List of Security Type the user has requested (Equity, Forex, Futures etc).
|
||||
/// </summary>
|
||||
public List<SecurityType> Types { get; set; } = new List<SecurityType>();
|
||||
|
||||
/// <summary>
|
||||
/// CSV formatted, lower case list of SecurityTypes for the web API.
|
||||
/// </summary>
|
||||
public string TypesCSV
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = "";
|
||||
foreach (var type in Types)
|
||||
{
|
||||
result += type + ",";
|
||||
}
|
||||
result = result.TrimEnd(',');
|
||||
return result.ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public SecurityTypesPacket()
|
||||
: base (PacketType.SecurityTypes)
|
||||
{ }
|
||||
|
||||
} // End Work Packet:
|
||||
|
||||
} // End of Namespace:
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the permissions for the object store
|
||||
/// </summary>
|
||||
public class StoragePermissions
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the user has read permissions on the object store
|
||||
/// </summary>
|
||||
public bool Read { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user has write permissions on the object store
|
||||
/// </summary>
|
||||
public bool Write { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user has delete permissions on the object store
|
||||
/// </summary>
|
||||
public bool Delete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StoragePermissions"/> struct with default permissions.
|
||||
/// </summary>
|
||||
public StoragePermissions()
|
||||
{
|
||||
// default permissions for controls storage
|
||||
Read = true;
|
||||
Write = true;
|
||||
Delete = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of the storage permissions.
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Read={Read} Write={Write} Delete={Delete}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Packets
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug packets generated by Lean
|
||||
/// </summary>
|
||||
public class SystemDebugPacket : DebugPacket
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor for JSON
|
||||
/// </summary>
|
||||
public SystemDebugPacket()
|
||||
: base (PacketType.SystemDebug)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of the system debug packet
|
||||
/// </summary>
|
||||
public SystemDebugPacket(int projectId, string algorithmId, string compileId, string message, bool toast = false)
|
||||
: base(PacketType.SystemDebug)
|
||||
{
|
||||
ProjectId = projectId;
|
||||
Message = message;
|
||||
CompileId = compileId;
|
||||
AlgorithmId = algorithmId;
|
||||
Toast = toast;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user