/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using ProtoBuf;
using QuantConnect.Securities;
namespace QuantConnect.Orders.Fees
{
///
/// Defines the result for
///
[ProtoContract(SkipConstructor = true)]
public class OrderFee
{
///
/// Gets the order fee
///
[ProtoMember(1)]
public CashAmount Value { get; set; }
///
/// Initializes a new instance of the class
///
/// The order fee
public OrderFee(CashAmount orderFee)
{
Value = new CashAmount(
orderFee.Amount.Normalize(),
orderFee.Currency);
}
///
/// Applies the order fee to the given portfolio
///
/// The portfolio instance
/// The order fill event
public virtual void ApplyToPortfolio(SecurityPortfolioManager portfolio, OrderEvent fill)
{
portfolio.CashBook[Value.Currency].AddAmount(-Value.Amount);
}
///
/// This is for backward compatibility with old 'decimal' order fee
///
public override string ToString()
{
return $"{Value.Amount} {Value.Currency}";
}
///
/// This is for backward compatibility with old 'decimal' order fee
///
public static implicit operator decimal(OrderFee m)
{
return m.Value.Amount;
}
///
/// Gets an instance of that represents zero.
///
public static readonly OrderFee Zero =
new OrderFee(new CashAmount(0, Currencies.NullCurrency));
}
}