/* * 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 Python.Runtime; using QuantConnect.Securities; namespace QuantConnect.Python { /// /// Wraps a object that represents a security's model of buying power /// public class BuyingPowerModelPythonWrapper : BasePythonWrapper, IBuyingPowerModel { /// /// Constructor for initializing the class with wrapped object /// /// Represents a security's model of buying power public BuyingPowerModelPythonWrapper(PyObject model) : base(model) { } /// /// Gets the buying power available for a trade /// /// A parameters object containing the algorithm's potrfolio, security, and order direction /// The buying power available for the trade public BuyingPower GetBuyingPower(BuyingPowerParameters parameters) { return InvokeMethod(nameof(GetBuyingPower), parameters); } /// /// Gets the current leverage of the security /// /// The security to get leverage for /// The current leverage in the security public decimal GetLeverage(Security security) { return InvokeMethod(nameof(GetLeverage), security); } /// /// Get the maximum market order quantity to obtain a position with a given buying power percentage. /// Will not take into account free buying power. /// /// An object containing the portfolio, the security and the target signed buying power percentage /// Returns the maximum allowed market order quantity and if zero, also the reason public GetMaximumOrderQuantityResult GetMaximumOrderQuantityForTargetBuyingPower(GetMaximumOrderQuantityForTargetBuyingPowerParameters parameters) { return InvokeMethod(nameof(GetMaximumOrderQuantityForTargetBuyingPower), parameters); } /// /// Get the maximum market order quantity to obtain a delta in the buying power used by a security. /// The deltas sign defines the position side to apply it to, positive long, negative short. /// /// An object containing the portfolio, the security and the delta buying power /// Returns the maximum allowed market order quantity and if zero, also the reason public GetMaximumOrderQuantityResult GetMaximumOrderQuantityForDeltaBuyingPower( GetMaximumOrderQuantityForDeltaBuyingPowerParameters parameters) { return InvokeMethod(nameof(GetMaximumOrderQuantityForDeltaBuyingPower), parameters); } /// /// Gets the amount of buying power reserved to maintain the specified position /// /// A parameters object containing the security /// The reserved buying power in account currency public ReservedBuyingPowerForPosition GetReservedBuyingPowerForPosition(ReservedBuyingPowerForPositionParameters parameters) { return InvokeMethod(nameof(GetReservedBuyingPowerForPosition), parameters); } /// /// Check if there is sufficient buying power to execute this order. /// /// An object containing the portfolio, the security and the order /// Returns buying power information for an order public HasSufficientBuyingPowerForOrderResult HasSufficientBuyingPowerForOrder(HasSufficientBuyingPowerForOrderParameters parameters) { return InvokeMethod(nameof(HasSufficientBuyingPowerForOrder), parameters); } /// /// Sets the leverage for the applicable securities, i.e, equities /// /// /// This is added to maintain backwards compatibility with the old margin/leverage system /// /// The security to set leverage for /// The new leverage public void SetLeverage(Security security, decimal leverage) { InvokeMethod(nameof(SetLeverage), security, leverage); } /// /// Gets the margin currently allocated to the specified holding /// /// An object containing the security /// The maintenance margin required for the provided holdings quantity/cost/value public MaintenanceMargin GetMaintenanceMargin(MaintenanceMarginParameters parameters) { return InvokeMethod(nameof(GetMaintenanceMargin), parameters); } /// /// The margin that must be held in order to increase the position by the provided quantity /// /// An object containing the security and quantity /// The initial margin required for the provided security and quantity public InitialMargin GetInitialMarginRequirement(InitialMarginParameters parameters) { return InvokeMethod(nameof(GetInitialMarginRequirement), parameters); } /// /// Gets the total margin required to execute the specified order in units of the account currency including fees /// /// An object containing the portfolio, the security and the order /// The total margin in terms of the currency quoted in the order public InitialMargin GetInitialMarginRequiredForOrder(InitialMarginRequiredForOrderParameters parameters) { return InvokeMethod(nameof(GetInitialMarginRequiredForOrder), parameters); } } }