Lean  $LEAN_TAG$
QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler Class Reference

This transaction handler is used for processing transactions during backtests More...

Inheritance diagram for QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler:
[legend]

Public Member Functions

override void Initialize (IAlgorithm algorithm, IBrokerage brokerage, IResultHandler resultHandler)
 Creates a new BacktestingTransactionHandler using the BacktestingBrokerage More...
 
override void ProcessSynchronousEvents ()
 Processes all synchronous events that must take place before the next time loop for the algorithm More...
 
override void ProcessAsynchronousEvents ()
 Processes asynchronous events on the transaction handler's thread More...
 
- Public Member Functions inherited from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler
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< OrderTicketGetOrderTickets (Func< OrderTicket, bool > filter=null)
 Gets and enumerable of OrderTicket matching the specified filter More...
 
IEnumerable< OrderTicketGetOpenOrderTickets (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< OrderGetOrdersByBrokerageId (string brokerageId)
 Gets the order by its brokerage id More...
 
IEnumerable< OrderGetOrders (Func< Order, bool > filter=null)
 Gets all orders matching the specified filter. Specifying null will return an enumerable of all orders. More...
 
List< OrderGetOpenOrders (Func< Order, bool > filter=null)
 Gets open orders matching the specified filter 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...
 

Protected Member Functions

override void WaitForOrderSubmission (OrderTicket ticket)
 For backtesting we will submit the order ourselves More...
 
override void InitializeTransactionThread ()
 For backtesting order requests will be processed by the algorithm thread sequentially at WaitForOrderSubmission and ProcessSynchronousEvents More...
 
- Protected Member Functions inherited from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler
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...
 

Protected Attributes

override DateTime CurrentTimeUtc => _algorithm.UtcTime
 Gets current time UTC. This is here to facilitate testing More...
 
- Protected Attributes inherited from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler
IBusyCollection< OrderRequest_orderRequestQueue
 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...
 
readonly CancelPendingOrders _cancelPendingOrders = new CancelPendingOrders()
 The _cancelPendingOrders instance will help to keep track of CancelPending orders and their Status More...
 
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...
 

Additional Inherited Members

- Public Attributes inherited from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler
IEnumerable< OrderEventOrderEvents => _orderEvents
 Gets all order events More...
 
int OrdersCount => _totalOrderCount
 Gets the current number of orders that have been processed More...
 
- Properties inherited from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler
ConcurrentDictionary< int, OrderOrders [get]
 Gets the permanent storage for all orders More...
 
ConcurrentDictionary< int, OrderTicketOrderTickets [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, OrderOrders [get]
 Gets the permanent storage for all orders More...
 
IEnumerable< OrderEventOrderEvents [get]
 Gets all order events More...
 
ConcurrentDictionary< int, OrderTicketOrderTickets [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 inherited from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler
EventHandler< OrderEventNewOrderEvent
 Event fired when there is a new OrderEvent More...
 
- Events inherited from QuantConnect.Securities.IOrderEventProvider
EventHandler< OrderEventNewOrderEvent
 Event fired when there is a new OrderEvent More...
 

Detailed Description

This transaction handler is used for processing transactions during backtests

Definition at line 30 of file BacktestingTransactionHandler.cs.

Member Function Documentation

◆ Initialize()

override void QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.Initialize ( IAlgorithm  algorithm,
IBrokerage  brokerage,
IResultHandler  resultHandler 
)
virtual

Creates a new BacktestingTransactionHandler using the BacktestingBrokerage

Parameters
algorithmThe algorithm instance
brokerageThe BacktestingBrokerage
resultHandler

Reimplemented from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.

Definition at line 48 of file BacktestingTransactionHandler.cs.

Here is the call graph for this function:

◆ ProcessSynchronousEvents()

override void QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.ProcessSynchronousEvents ( )
virtual

Processes all synchronous events that must take place before the next time loop for the algorithm

Reimplemented from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.

Definition at line 67 of file BacktestingTransactionHandler.cs.

Here is the call graph for this function:

◆ ProcessAsynchronousEvents()

override void QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.ProcessAsynchronousEvents ( )
virtual

Processes asynchronous events on the transaction handler's thread

Reimplemented from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.

Definition at line 87 of file BacktestingTransactionHandler.cs.

Here is the call graph for this function:

◆ WaitForOrderSubmission()

override void QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.WaitForOrderSubmission ( OrderTicket  ticket)
protectedvirtual

For backtesting we will submit the order ourselves

Parameters
ticketThe OrderTicket expecting to be submitted

Reimplemented from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.

Definition at line 98 of file BacktestingTransactionHandler.cs.

Here is the call graph for this function:

◆ InitializeTransactionThread()

override void QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.InitializeTransactionThread ( )
protectedvirtual

For backtesting order requests will be processed by the algorithm thread sequentially at WaitForOrderSubmission and ProcessSynchronousEvents

Reimplemented from QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler.

Definition at line 117 of file BacktestingTransactionHandler.cs.

Member Data Documentation

◆ CurrentTimeUtc

override DateTime QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler.CurrentTimeUtc => _algorithm.UtcTime
protected

Gets current time UTC. This is here to facilitate testing

Definition at line 40 of file BacktestingTransactionHandler.cs.


The documentation for this class was generated from the following file: