Lean  $LEAN_TAG$
ComboLimitOrder.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;
19 
20 namespace QuantConnect.Orders
21 {
22  /// <summary>
23  /// Combo limit order type
24  /// </summary>
25  /// <remarks>Single limit price for the whole combo order</remarks>
26  public class ComboLimitOrder : ComboOrder
27  {
28  /// <summary>
29  /// Combo Limit Order Type
30  /// </summary>
31  public override OrderType Type => OrderType.ComboLimit;
32 
33  /// <summary>
34  /// Added a default constructor for JSON Deserialization:
35  /// </summary>
36  public ComboLimitOrder() : base()
37  {
38  }
39 
40  /// <summary>
41  /// New limit order constructor
42  /// </summary>
43  /// <param name="symbol">Symbol asset we're seeking to trade</param>
44  /// <param name="quantity">Quantity of the asset we're seeking to trade</param>
45  /// <param name="time">Time the order was placed</param>
46  /// <param name="groupOrderManager">Manager for the orders in the group</param>
47  /// <param name="limitPrice">Price the order should be filled at if a limit order</param>
48  /// <param name="tag">User defined data tag for this order</param>
49  /// <param name="properties">The order properties for this order</param>
50  public ComboLimitOrder(Symbol symbol, decimal quantity, decimal limitPrice, DateTime time, GroupOrderManager groupOrderManager,
51  string tag = "", IOrderProperties properties = null)
52  : base(symbol, quantity, time, groupOrderManager, tag, properties)
53  {
54  GroupOrderManager.LimitPrice = limitPrice;
55  }
56 
57  /// <summary>
58  /// Gets the order value in units of the security's quote currency
59  /// </summary>
60  /// <param name="security">The security matching this order's symbol</param>
61  protected override decimal GetValueImpl(Security security)
62  {
63  return LimitOrder.CalculateOrderValue(Quantity, GroupOrderManager.LimitPrice, security.Price);
64  }
65 
66  /// <summary>
67  /// Modifies the state of this order to match the update request
68  /// </summary>
69  /// <param name="request">The request to update this order object</param>
70  public override void ApplyUpdateOrderRequest(UpdateOrderRequest request)
71  {
72  base.ApplyUpdateOrderRequest(request);
73  if (request.LimitPrice.HasValue)
74  {
75  GroupOrderManager.LimitPrice = request.LimitPrice.Value;
76  }
77  }
78 
79  /// <summary>
80  /// Creates a deep-copy clone of this order
81  /// </summary>
82  /// <returns>A copy of this order</returns>
83  public override Order Clone()
84  {
85  var order = new ComboLimitOrder();
86  CopyTo(order);
87  return order;
88  }
89  }
90 }