/* * 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.Brokerages; using QuantConnect.Data.Market; using QuantConnect.Orders; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.Slippage; using QuantConnect.Securities; using System.Collections.Generic; using System.Linq; namespace QuantConnect.Python.Wrappers { /// /// Wrapper for an instance created in Python. /// All calls to python should be inside a "using (Py.GIL()) {/* Your code here */}" block. /// class BrokerageModelPythonWrapper : IBrokerageModel { private IBrokerageModel _brokerageModel; /// /// constructor. /// Wraps the object. /// /// object to be wrapped public BrokerageModelPythonWrapper(IBrokerageModel brokegeModel) { _brokerageModel = brokegeModel; } /// /// Wrapper for in Python /// public AccountType AccountType { get { using (Py.GIL()) { return _brokerageModel.AccountType; } } } /// /// Wrapper for in Python /// public IReadOnlyDictionary DefaultMarkets { get { using (Py.GIL()) { return _brokerageModel.DefaultMarkets.ToDictionary(x => x.Key, x => x.Value); } } } /// /// Wrapper for in Python /// /// The open tickets matching the split event /// The split event data public void ApplySplit(List tickets, Split split) { using (Py.GIL()) { _brokerageModel.ApplySplit(tickets, split); } } /// /// Wrapper for in Python /// /// The security being ordered /// The order to test for execution /// True if the brokerage would be able to perform the execution, false otherwise public bool CanExecuteOrder(Security security, Order order) { using (Py.GIL()) { return _brokerageModel.CanExecuteOrder(security, order); } } /// /// Wrapper for in Python /// /// The security being ordered /// The order to be processed /// If this function returns false, a brokerage message detailing why the order may not be submitted /// True if the brokerage could process the order, false otherwise public bool CanSubmitOrder(Security security, Order order, out BrokerageMessageEvent message) { using (Py.GIL()) { return _brokerageModel.CanSubmitOrder(security, order, out message); } } /// /// Wrapper for in Python /// /// The security of the order /// The order to be updated /// The requested updated to be made to the order /// If this function returns false, a brokerage message detailing why the order may not be updated /// True if the brokerage would allow updating the order, false otherwise public bool CanUpdateOrder(Security security, Order order, UpdateOrderRequest request, out BrokerageMessageEvent message) { using (Py.GIL()) { return _brokerageModel.CanUpdateOrder(security, order, request, out message); } } /// /// Wrapper for in Python /// /// The security to get a fee model for /// The new fee model for this brokerage public IFeeModel GetFeeModel(Security security) { using (Py.GIL()) { return _brokerageModel.GetFeeModel(security); } } /// /// Wrapper for in Python /// /// The security to get fill model for /// The new fill model for this brokerage public IFillModel GetFillModel(Security security) { using (Py.GIL()) { return _brokerageModel.GetFillModel(security); } } /// /// Wrapper for in Python /// /// The security's whose leverage we seek /// The leverage for the specified security public decimal GetLeverage(Security security) { using (Py.GIL()) { return _brokerageModel.GetLeverage(security); } } /// /// Wrapper for in Python /// /// The security to get a settlement model for /// The account type /// The settlement model for this brokerage public ISettlementModel GetSettlementModel(Security security, AccountType accountType) { using (Py.GIL()) { return _brokerageModel.GetSettlementModel(security, AccountType); } } /// /// Wrapper for in Python /// /// The security to get a slippage model for /// The new slippage model for this brokerage public ISlippageModel GetSlippageModel(Security security) { using (Py.GIL()) { return _brokerageModel.GetSlippageModel(security); } } } }