/* * 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 System; using QuantConnect.Orders; using static QuantConnect.StringExtensions; namespace QuantConnect.Securities { /// /// Defines the parameters for /// public class HasSufficientBuyingPowerForOrderParameters { /// /// Gets the algorithm's portfolio /// public SecurityPortfolioManager Portfolio { get; } /// /// Gets the security /// public Security Security { get; } /// /// Gets the order /// public Order Order { get; } /// /// Initializes a new instance of the class /// /// The algorithm's portfolio /// The security /// The order public HasSufficientBuyingPowerForOrderParameters(SecurityPortfolioManager portfolio, Security security, Order order) { Portfolio = portfolio; Security = security; Order = order; } /// /// Creates a new targeting the security's underlying. /// If the security does not implement then an /// will be thrown. If the order's symbol does not match the underlying then an will /// be thrown. /// /// The new order targeting the underlying /// New parameters instance suitable for invoking the sufficient capital method for the underlying security public HasSufficientBuyingPowerForOrderParameters ForUnderlying(Order order) { var derivative = (IDerivativeSecurity) Security; return new HasSufficientBuyingPowerForOrderParameters(Portfolio, derivative.Underlying, order); } /// /// Creates a new result indicating that there is sufficient buying power for the contemplated order /// public HasSufficientBuyingPowerForOrderResult Sufficient() { return new HasSufficientBuyingPowerForOrderResult(true); } /// /// Creates a new result indicating that there is insufficient buying power for the contemplated order /// public HasSufficientBuyingPowerForOrderResult Insufficient(string reason) { return new HasSufficientBuyingPowerForOrderResult(false, reason); } /// /// Creates a new result indicating that there is insufficient buying power for the contemplated order /// public HasSufficientBuyingPowerForOrderResult Insufficient(FormattableString reason) { return new HasSufficientBuyingPowerForOrderResult(false, Invariant(reason)); } } }