|
Lean
$LEAN_TAG$
|
Transaction handler for all brokerages More...
Public Member Functions | |
| virtual void | Initialize (IAlgorithm algorithm, IBrokerage brokerage, IResultHandler resultHandler) |
| Creates a new BrokerageTransactionHandler to process orders using the specified brokerage implementation More... | |
| OrderTicket | Process (OrderRequest request) |
| Adds the specified order to be processed More... | |
| OrderTicket | AddOrder (SubmitOrderRequest request) |
| Add an order to collection and return the unique order id or negative if an error. More... | |
| OrderTicket | UpdateOrder (UpdateOrderRequest request) |
| Update an order yet to be filled such as stop or limit orders. More... | |
| OrderTicket | CancelOrder (CancelOrderRequest request) |
| Remove this order from outstanding queue: user is requesting a cancel. More... | |
| IEnumerable< OrderTicket > | GetOrderTickets (Func< OrderTicket, bool > filter=null) |
| Gets and enumerable of OrderTicket matching the specified filter More... | |
| IEnumerable< OrderTicket > | GetOpenOrderTickets (Func< OrderTicket, bool > filter=null) |
| Gets and enumerable of opened OrderTicket matching the specified filter More... | |
| OrderTicket | GetOrderTicket (int orderId) |
| Gets the order ticket for the specified order id. Returns null if not found More... | |
| Order | GetOrderById (int orderId) |
| Get the order by its id More... | |
| List< Order > | GetOrdersByBrokerageId (string brokerageId) |
| Gets the order by its brokerage id More... | |
| IEnumerable< Order > | GetOrders (Func< Order, bool > filter=null) |
| Gets all orders matching the specified filter. Specifying null will return an enumerable of all orders. More... | |
| List< Order > | GetOpenOrders (Func< Order, bool > filter=null) |
| Gets open orders matching the specified filter More... | |
| virtual void | ProcessAsynchronousEvents () |
| Processes asynchronous events on the transaction handler's thread More... | |
| virtual void | ProcessSynchronousEvents () |
| Processes all synchronous events that must take place before the next time loop for the algorithm More... | |
| void | AddOpenOrder (Order order, IAlgorithm algorithm) |
| Register an already open Order More... | |
| void | Exit () |
| Signal a end of thread request to stop monitoring the transactions. More... | |
| void | HandleOrderRequest (OrderRequest request) |
| Handles a generic order request More... | |
| decimal | RoundOffOrder (Order order, Security security) |
| Rounds off the order towards 0 to the nearest multiple of Lot Size More... | |
Public Attributes | |
| IEnumerable< OrderEvent > | OrderEvents => _orderEvents |
| Gets all order events More... | |
| int | OrdersCount => _totalOrderCount |
| Gets the current number of orders that have been processed More... | |
Protected Member Functions | |
| virtual void | InitializeTransactionThread () |
| Create and start the transaction thread, who will be in charge of processing the order requests More... | |
| virtual void | WaitForOrderSubmission (OrderTicket ticket) |
| Wait for the order to be handled by the _processingThread More... | |
| void | Run () |
| Primary thread entry point to launch the transaction thread. More... | |
| void | RoundOrderPrices (Order order, Security security) |
| Rounds the order prices to its security minimum price variation. More... | |
| void | RoundOrderPrices (Order order, Security security, bool comboIsReady, Dictionary< Order, Security > orders) |
| Rounds the order prices to its security minimum price variation. More... | |
Protected Attributes | |
| virtual TimeSpan | TimeSinceLastFill |
| Gets the amount of time since the last call to algorithm.Portfolio.ProcessFill(fill) More... | |
| virtual DateTime | CurrentTimeUtc => DateTime.UtcNow |
| Gets current time UTC. This is here to facilitate testing More... | |
Properties | |
| IBusyCollection< OrderRequest > | _orderRequestQueue [get, set] |
| OrderQueue holds the newly updated orders from the user algorithm waiting to be processed. Once orders are processed they are moved into the Orders queue awaiting the brokerage response. More... | |
| CancelPendingOrders | _cancelPendingOrders = new CancelPendingOrders() [get] |
| The _cancelPendingOrders instance will help to keep track of CancelPending orders and their Status More... | |
| ConcurrentDictionary< int, Order > | Orders [get] |
| Gets the permanent storage for all orders More... | |
| ConcurrentDictionary< int, OrderTicket > | OrderTickets [get] |
| Gets the permanent storage for all order tickets More... | |
| bool | IsActive [get] |
| Boolean flag indicating the Run thread method is busy. False indicates it is completely finished processing and ready to be terminated. More... | |
Properties inherited from QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler | |
| bool | IsActive [get] |
| Boolean flag indicating the thread is busy. False indicates it is completely finished processing and ready to be terminated. More... | |
| ConcurrentDictionary< int, Order > | Orders [get] |
| Gets the permanent storage for all orders More... | |
| IEnumerable< OrderEvent > | OrderEvents [get] |
| Gets all order events More... | |
| ConcurrentDictionary< int, OrderTicket > | OrderTickets [get] |
| Gets the permanent storage for all order tickets More... | |
Properties inherited from QuantConnect.Securities.IOrderProvider | |
| int | OrdersCount [get] |
| Gets the current number of orders that have been processed More... | |
Events | |
| EventHandler< OrderEvent > | NewOrderEvent |
| Event fired when there is a new OrderEvent More... | |
Events inherited from QuantConnect.Securities.IOrderEventProvider | |
| EventHandler< OrderEvent > | NewOrderEvent |
| Event fired when there is a new OrderEvent More... | |
Transaction handler for all brokerages
Definition at line 41 of file BrokerageTransactionHandler.cs.
|
virtual |
Creates a new BrokerageTransactionHandler to process orders using the specified brokerage implementation
| algorithm | The algorithm instance |
| brokerage | The brokerage implementation to process orders and fire fill events |
| resultHandler |
Implements QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler.
Reimplemented in QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.
Definition at line 155 of file BrokerageTransactionHandler.cs.
|
protectedvirtual |
Create and start the transaction thread, who will be in charge of processing the order requests
Reimplemented in QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.
Definition at line 225 of file BrokerageTransactionHandler.cs.
| OrderTicket QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.Process | ( | OrderRequest | request | ) |
Adds the specified order to be processed
| request | The order to be processed |
Implements QuantConnect.Securities.IOrderProcessor.
Definition at line 243 of file BrokerageTransactionHandler.cs.
| OrderTicket QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.AddOrder | ( | SubmitOrderRequest | request | ) |
Add an order to collection and return the unique order id or negative if an error.
| request | A request detailing the order to be submitted |
Definition at line 273 of file BrokerageTransactionHandler.cs.
|
protectedvirtual |
Wait for the order to be handled by the _processingThread
| ticket | The OrderTicket expecting to be submitted |
Reimplemented in QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.
Definition at line 345 of file BrokerageTransactionHandler.cs.
| OrderTicket QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.UpdateOrder | ( | UpdateOrderRequest | request | ) |
Update an order yet to be filled such as stop or limit orders.
| request | Request detailing how the order should be updated |
Does not apply if the order is already fully filled
Definition at line 360 of file BrokerageTransactionHandler.cs.
| OrderTicket QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.CancelOrder | ( | CancelOrderRequest | request | ) |
Remove this order from outstanding queue: user is requesting a cancel.
| request | Request containing the specific order id to remove |
Definition at line 442 of file BrokerageTransactionHandler.cs.
| IEnumerable<OrderTicket> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOrderTickets | ( | Func< OrderTicket, bool > | filter = null | ) |
Gets and enumerable of OrderTicket matching the specified filter
| filter | The filter predicate used to find the required order tickets |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 517 of file BrokerageTransactionHandler.cs.
| IEnumerable<OrderTicket> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOpenOrderTickets | ( | Func< OrderTicket, bool > | filter = null | ) |
Gets and enumerable of opened OrderTicket matching the specified filter
| filter | The filter predicate used to find the required order tickets |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 527 of file BrokerageTransactionHandler.cs.
| OrderTicket QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOrderTicket | ( | int | orderId | ) |
Gets the order ticket for the specified order id. Returns null if not found
| orderId | The order's id |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 537 of file BrokerageTransactionHandler.cs.
| Order QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOrderById | ( | int | orderId | ) |
Get the order by its id
| orderId | Order id to fetch |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 551 of file BrokerageTransactionHandler.cs.
| List<Order> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOrdersByBrokerageId | ( | string | brokerageId | ) |
Gets the order by its brokerage id
| brokerageId | The brokerage id to fetch |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 568 of file BrokerageTransactionHandler.cs.
| IEnumerable<Order> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOrders | ( | Func< Order, bool > | filter = null | ) |
Gets all orders matching the specified filter. Specifying null will return an enumerable of all orders.
| filter | Delegate used to filter the orders |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 596 of file BrokerageTransactionHandler.cs.
| List<Order> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.GetOpenOrders | ( | Func< Order, bool > | filter = null | ) |
Gets open orders matching the specified filter
| filter | Delegate used to filter the orders |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 611 of file BrokerageTransactionHandler.cs.
|
protected |
Primary thread entry point to launch the transaction thread.
Definition at line 624 of file BrokerageTransactionHandler.cs.
|
virtual |
Processes asynchronous events on the transaction handler's thread
Reimplemented in QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.
Definition at line 650 of file BrokerageTransactionHandler.cs.
|
virtual |
Processes all synchronous events that must take place before the next time loop for the algorithm
Implements QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler.
Reimplemented in QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.
Definition at line 658 of file BrokerageTransactionHandler.cs.
| void QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.AddOpenOrder | ( | Order | order, |
| IAlgorithm | algorithm | ||
| ) |
Register an already open Order
Implements QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler.
Definition at line 714 of file BrokerageTransactionHandler.cs.
| void QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.Exit | ( | ) |
Signal a end of thread request to stop monitoring the transactions.
Implements QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler.
Definition at line 745 of file BrokerageTransactionHandler.cs.
| void QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.HandleOrderRequest | ( | OrderRequest | request | ) |
Handles a generic order request
| request | OrderRequest to be handled |
Definition at line 767 of file BrokerageTransactionHandler.cs.
| decimal QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.RoundOffOrder | ( | Order | order, |
| Security | security | ||
| ) |
Rounds off the order towards 0 to the nearest multiple of Lot Size
Definition at line 1644 of file BrokerageTransactionHandler.cs.
|
protected |
Rounds the order prices to its security minimum price variation.
This procedure is needed to meet brokerage precision requirements.
Definition at line 1673 of file BrokerageTransactionHandler.cs.
|
protected |
Rounds the order prices to its security minimum price variation.
This procedure is needed to meet brokerage precision requirements.
Definition at line 1687 of file BrokerageTransactionHandler.cs.
| IEnumerable<OrderEvent> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.OrderEvents => _orderEvents |
Gets all order events
Definition at line 131 of file BrokerageTransactionHandler.cs.
| int QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.OrdersCount => _totalOrderCount |
Gets the current number of orders that have been processed
Definition at line 147 of file BrokerageTransactionHandler.cs.
|
protected |
Gets the amount of time since the last call to algorithm.Portfolio.ProcessFill(fill)
Definition at line 1633 of file BrokerageTransactionHandler.cs.
|
protected |
Gets current time UTC. This is here to facilitate testing
Definition at line 1639 of file BrokerageTransactionHandler.cs.
|
getsetprotected |
OrderQueue holds the newly updated orders from the user algorithm waiting to be processed. Once orders are processed they are moved into the Orders queue awaiting the brokerage response.
Definition at line 65 of file BrokerageTransactionHandler.cs.
|
getprotected |
The _cancelPendingOrders instance will help to keep track of CancelPending orders and their Status
Definition at line 106 of file BrokerageTransactionHandler.cs.
|
get |
Gets the permanent storage for all orders
Definition at line 121 of file BrokerageTransactionHandler.cs.
|
get |
Gets the permanent storage for all order tickets
Definition at line 137 of file BrokerageTransactionHandler.cs.
|
get |
Boolean flag indicating the Run thread method is busy. False indicates it is completely finished processing and ready to be terminated.
Definition at line 235 of file BrokerageTransactionHandler.cs.
| EventHandler<OrderEvent> QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.NewOrderEvent |
Event fired when there is a new OrderEvent
Definition at line 115 of file BrokerageTransactionHandler.cs.