Lean  $LEAN_TAG$
ComboLegLimitOrder.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using Newtonsoft.Json;
20 
21 namespace QuantConnect.Orders
22 {
23  /// <summary>
24  /// Combo leg limit order type
25  /// </summary>
26  /// <remarks>Limit price per leg in the combo order</remarks>
28  {
29  /// <summary>
30  /// Combo Limit Leg Order Type
31  /// </summary>
32  public override OrderType Type => OrderType.ComboLegLimit;
33 
34  /// <summary>
35  /// Limit price for this order.
36  /// </summary>
37  [JsonProperty(PropertyName = "limitPrice")]
38  public decimal LimitPrice { get; internal set; }
39 
40  /// <summary>
41  /// Added a default constructor for JSON Deserialization:
42  /// </summary>
43  public ComboLegLimitOrder() : base()
44  {
45  }
46 
47  /// <summary>
48  /// New limit order constructor
49  /// </summary>
50  /// <param name="symbol">Symbol asset we're seeking to trade</param>
51  /// <param name="quantity">Quantity of the asset we're seeking to trade</param>
52  /// <param name="time">Time the order was placed</param>
53  /// <param name="groupOrderManager">Manager for the orders in the group</param>
54  /// <param name="limitPrice">Price the order should be filled at if a limit order</param>
55  /// <param name="tag">User defined data tag for this order</param>
56  /// <param name="properties">The order properties for this order</param>
57  public ComboLegLimitOrder(Symbol symbol, decimal quantity, decimal limitPrice, DateTime time, GroupOrderManager groupOrderManager,
58  string tag = "", IOrderProperties properties = null)
59  : base(symbol, quantity, time, groupOrderManager, tag, properties)
60  {
61  GroupOrderManager = groupOrderManager;
62  LimitPrice = limitPrice;
63  }
64 
65  /// <summary>
66  /// Gets the order value in units of the security's quote currency
67  /// </summary>
68  /// <param name="security">The security matching this order's symbol</param>
69  protected override decimal GetValueImpl(Security security)
70  {
71  return LimitOrder.CalculateOrderValue(Quantity, LimitPrice, security.Price);
72  }
73 
74  /// <summary>
75  /// Modifies the state of this order to match the update request
76  /// </summary>
77  /// <param name="request">The request to update this order object</param>
78  public override void ApplyUpdateOrderRequest(UpdateOrderRequest request)
79  {
80  base.ApplyUpdateOrderRequest(request);
81  if (request.LimitPrice.HasValue)
82  {
83  LimitPrice = request.LimitPrice.Value;
84  }
85  }
86 
87  /// <summary>
88  /// Creates a deep-copy clone of this order
89  /// </summary>
90  /// <returns>A copy of this order</returns>
91  public override Order Clone()
92  {
93  var order = new ComboLegLimitOrder { LimitPrice = LimitPrice };
94  CopyTo(order);
95  return order;
96  }
97  }
98 }