Lean
$LEAN_TAG$
OrderFee.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
ProtoBuf;
17
using
QuantConnect
.
Securities
;
18
19
namespace
QuantConnect.Orders.Fees
20
{
21
/// <summary>
22
/// Defines the result for <see cref="IFeeModel.GetOrderFee"/>
23
/// </summary>
24
[ProtoContract(SkipConstructor =
true
)]
25
public
class
OrderFee
26
{
27
/// <summary>
28
/// Gets the order fee
29
/// </summary>
30
[ProtoMember(1)]
31
public
CashAmount
Value
{
get
;
set
; }
32
33
/// <summary>
34
/// Initializes a new instance of the <see cref="OrderFee"/> class
35
/// </summary>
36
/// <param name="orderFee">The order fee</param>
37
public
OrderFee
(
CashAmount
orderFee)
38
{
39
Value
=
new
CashAmount
(
40
orderFee.
Amount
.Normalize(),
41
orderFee.
Currency
);
42
}
43
44
/// <summary>
45
/// Applies the order fee to the given portfolio
46
/// </summary>
47
/// <param name="portfolio">The portfolio instance</param>
48
/// <param name="fill">The order fill event</param>
49
public
virtual
void
ApplyToPortfolio
(
SecurityPortfolioManager
portfolio,
OrderEvent
fill)
50
{
51
portfolio.
CashBook
[
Value
.
Currency
].AddAmount(-
Value
.
Amount
);
52
}
53
54
/// <summary>
55
/// This is for backward compatibility with old 'decimal' order fee
56
/// </summary>
57
public
override
string
ToString
()
58
{
59
return
$
"{Value.Amount} {Value.Currency}"
;
60
}
61
62
/// <summary>
63
/// This is for backward compatibility with old 'decimal' order fee
64
/// </summary>
65
public
static
implicit
operator
decimal(
OrderFee
m)
66
{
67
return
m.
Value
.
Amount
;
68
}
69
70
/// <summary>
71
/// Gets an instance of <see cref="OrderFee"/> that represents zero.
72
/// </summary>
73
public
static
readonly
OrderFee
Zero
=
74
new
OrderFee
(
new
CashAmount
(0,
Currencies
.
NullCurrency
));
75
}
76
}
Common
Orders
Fees
OrderFee.cs
Generated by
1.8.17