Lean  $LEAN_TAG$
MarketOrder.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  /// Market order type definition
24  /// </summary>
25  public class MarketOrder : Order
26  {
27  /// <summary>
28  /// Added a default constructor for JSON Deserialization:
29  /// </summary>
30  public MarketOrder()
31  {
32  }
33 
34  /// <summary>
35  /// Market Order Type
36  /// </summary>
37  public override OrderType Type
38  {
39  get { return OrderType.Market; }
40  }
41 
42  /// <summary>
43  /// New market order constructor
44  /// </summary>
45  /// <param name="symbol">Symbol asset we're seeking to trade</param>
46  /// <param name="quantity">Quantity of the asset we're seeking to trade</param>
47  /// <param name="time">Time the order was placed</param>
48  /// <param name="price">Price of the order</param>
49  /// <param name="tag">User defined data tag for this order</param>
50  /// <param name="properties">The order properties for this order</param>
51  public MarketOrder(Symbol symbol, decimal quantity, DateTime time, decimal price, string tag = "", IOrderProperties properties = null)
52  : this(symbol, quantity, time, tag, properties)
53  {
54  Price = price;
55  }
56 
57  /// <summary>
58  /// New market order constructor
59  /// </summary>
60  /// <param name="symbol">Symbol asset we're seeking to trade</param>
61  /// <param name="quantity">Quantity of the asset we're seeking to trade</param>
62  /// <param name="time">Time the order was placed</param>
63  /// <param name="tag">User defined data tag for this order</param>
64  /// <param name="properties">The order properties for this order</param>
65  public MarketOrder(Symbol symbol, decimal quantity, DateTime time, string tag = "", IOrderProperties properties = null)
66  : base(symbol, quantity, time, tag, properties)
67  {
68  }
69 
70  /// <summary>
71  /// Gets the order value in units of the security's quote currency
72  /// </summary>
73  /// <param name="security">The security matching this order's symbol</param>
74  protected override decimal GetValueImpl(Security security)
75  {
76  return Quantity*security.Price;
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 MarketOrder();
86  CopyTo(order);
87  return order;
88  }
89  }
90 }