/* * 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 System.Collections.Generic; using QuantConnect.Orders; namespace QuantConnect.Securities { /// /// Represents a type capable of fetching Order instances by its QC order id or by a brokerage id /// public interface IOrderProvider { /// /// Gets the current number of orders that have been processed /// int OrdersCount { get; } /// /// Get the order by its id /// /// Order id to fetch /// A clone of the order with the specified id, or null if no match is found Order GetOrderById(int orderId); /// /// Gets the Lean orders by its brokerage id /// /// The brokerage id to fetch /// The orders matching the brokerage id, or null if no match is found List GetOrdersByBrokerageId(string brokerageId); /// /// Gets and enumerable of matching the specified /// /// The filter predicate used to find the required order tickets. If null is specified then all tickets are returned /// An enumerable of matching the specified IEnumerable GetOrderTickets(Func filter = null); /// /// Gets and enumerable of opened matching the specified /// /// The filter predicate used to find the required order tickets. If null is specified then all tickets are returned /// An enumerable of opened matching the specified IEnumerable GetOpenOrderTickets(Func filter = null); /// /// Gets the order ticket for the specified order id. Returns null if not found /// /// The order's id /// The order ticket with the specified id, or null if not found OrderTicket GetOrderTicket(int orderId); /// /// Gets all orders matching the specified filter. Specifying null will return an enumerable /// of all orders. /// /// Delegate used to filter the orders /// All orders this order provider currently holds by the specified filter IEnumerable GetOrders(Func filter = null); /// /// Gets open orders matching the specified filter. Specifying null will return an enumerable /// of all open orders. /// /// Delegate used to filter the orders /// All filtered open orders this order provider currently holds List GetOpenOrders(Func filter = null); /// /// Calculates the projected holdings for the specified security based on the current open orders. /// /// The security /// /// The projected holdings for the specified security, which is the sum of the current holdings /// plus the sum of the open orders quantity. /// ProjectedHoldings GetProjectedHoldings(Security security); } /// /// Provides extension methods for the interface /// public static class OrderProviderExtensions { /// /// Gets the order by its brokerage id /// /// The order provider to search /// The brokerage id to fetch /// The first order matching the brokerage id, or null if no match is found public static List GetOrdersByBrokerageId(this IOrderProvider orderProvider, long brokerageId) { return orderProvider.GetOrdersByBrokerageId(brokerageId.ToStringInvariant()); } /// /// Gets the order by its brokerage id /// /// The order provider to search /// The brokerage id to fetch /// The first order matching the brokerage id, or null if no match is found public static List GetOrdersByBrokerageId(this IOrderProvider orderProvider, int brokerageId) { return orderProvider.GetOrdersByBrokerageId(brokerageId.ToStringInvariant()); } } }