/* * 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 System.Collections.Generic; namespace QuantConnect.Orders { /// /// Manager of a group of orders /// public class GroupOrderManager { /// /// The unique order group Id /// [JsonProperty(PropertyName = "id")] public int Id { get; internal set; } /// /// The group order quantity /// [JsonProperty(PropertyName = "quantity")] public decimal Quantity { get; internal set; } /// /// The total order count associated with this order group /// [JsonProperty(PropertyName = "count")] public int Count { get; } /// /// The limit price associated with this order group if any /// [JsonProperty(PropertyName = "limitPrice")] public decimal LimitPrice { get; set; } /// /// The order Ids in this group /// /// In live trading we process orders in a dedicated thread so we need to be thread safe [JsonProperty(PropertyName = "orderIds")] public HashSet OrderIds { get; } /// /// Order Direction Property based off Quantity. /// [JsonProperty(PropertyName = "direction")] public OrderDirection Direction { get { if (Quantity > 0) { return OrderDirection.Buy; } if (Quantity < 0) { return OrderDirection.Sell; } return OrderDirection.Hold; } } /// /// Get the absolute quantity for this combo order /// [JsonIgnore] public decimal AbsoluteQuantity => Math.Abs(Quantity); /// /// Creates a new empty instance /// public GroupOrderManager() { } /// /// Creates a new instance of /// /// This order group unique Id /// The order leg count /// The group order quantity /// The limit price associated with this order group if any public GroupOrderManager(int id, int legCount, decimal quantity, decimal limitPrice = 0) : this(legCount, quantity, limitPrice) { Id = id; } /// /// Creates a new instance of /// /// The order leg count /// The group order quantity /// The limit price associated with this order group if any public GroupOrderManager(int legCount, decimal quantity, decimal limitPrice = 0) { Count = legCount; Quantity = quantity; LimitPrice = limitPrice; OrderIds = new(capacity: legCount); } } }