Lean
$LEAN_TAG$
ComboOrder.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
QuantConnect
.
Interfaces
;
18
19
namespace
QuantConnect.Orders
20
{
21
/// <summary>
22
/// Combo order type
23
/// </summary>
24
public
abstract
class
ComboOrder
:
Order
25
{
26
private
decimal _ratio;
27
28
/// <summary>
29
/// Number of shares to execute.
30
/// For combo orders, we store the ratio of each leg instead of the quantity,
31
/// and the actual quantity is calculated when requested using the group order manager quantity.
32
/// This allows for a single quantity update to be applied to all the legs of the combo.
33
/// </summary>
34
public
override
decimal
Quantity
35
{
36
get
37
{
38
return
_ratio.GetOrderLegGroupQuantity(
GroupOrderManager
).Normalize();
39
}
40
internal
set
41
{
42
_ratio = value.GetOrderLegRatio(
GroupOrderManager
);
43
}
44
}
45
46
/// <summary>
47
/// Added a default constructor for JSON Deserialization:
48
/// </summary>
49
public
ComboOrder
() : base()
50
{
51
}
52
53
/// <summary>
54
/// New market order constructor
55
/// </summary>
56
/// <param name="symbol">Symbol asset we're seeking to trade</param>
57
/// <param name="quantity">Quantity of the asset we're seeking to trade</param>
58
/// <param name="time">Time the order was placed</param>
59
/// <param name="groupOrderManager">Manager for the orders in the group</param>
60
/// <param name="tag">User defined data tag for this order</param>
61
/// <param name="properties">The order properties for this order</param>
62
public
ComboOrder
(
Symbol
symbol, decimal quantity, DateTime time,
GroupOrderManager
groupOrderManager,
string
tag =
""
,
63
IOrderProperties
properties =
null
)
64
: base(symbol, 0m, time, tag, properties)
65
{
66
GroupOrderManager
= groupOrderManager;
67
Quantity
= quantity;
68
}
69
70
/// <summary>
71
/// Modifies the state of this order to match the update request
72
/// </summary>
73
/// <param name="request">The request to update this order object</param>
74
public
override
void
ApplyUpdateOrderRequest
(
UpdateOrderRequest
request)
75
{
76
if
(request.
OrderId
!=
Id
)
77
{
78
throw
new
ArgumentException(
"Attempted to apply updates to the incorrect order!"
);
79
}
80
if
(request.
Tag
!=
null
)
81
{
82
Tag
= request.
Tag
;
83
}
84
if
(request.
Quantity
.HasValue)
85
{
86
// For combo orders, the updated quantity is the quantity of the group
87
GroupOrderManager
.
Quantity
= request.
Quantity
.Value;
88
}
89
}
90
}
91
}
Common
Orders
ComboOrder.cs
Generated by
1.8.17