Lean  $LEAN_TAG$
QuantConnect.Securities.SecurityTransactionManager Class Reference

Algorithm Transactions Manager - Recording Transactions More...

Inheritance diagram for QuantConnect.Securities.SecurityTransactionManager:
[legend]

Public Member Functions

 SecurityTransactionManager (IAlgorithm algorithm, SecurityManager security)
 Initialise the transaction manager for holding and processing orders. More...
 
OrderTicket ProcessRequest (OrderRequest request)
 Processes the order request More...
 
void SetOrderId (SubmitOrderRequest request)
 Sets the order id for the specified submit request 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 (int orderId, string orderTag=null)
 Added alias for RemoveOrder - More...
 
List< OrderTicketCancelOpenOrders ()
 Cancels all open orders for all symbols More...
 
List< OrderTicketCancelOpenOrders (Symbol symbol, string tag=null)
 Cancels all open orders for the specified symbol More...
 
OrderTicket RemoveOrder (int orderId, string tag=null)
 Remove this order from outstanding queue: user is requesting a cancel. More...
 
IEnumerable< OrderTicketGetOrderTickets (Func< OrderTicket, bool > filter=null)
 Gets an enumerable of OrderTicket matching the specified filter More...
 
IEnumerable< OrderTicketGetOrderTickets (PyObject filter)
 Gets an enumerable of OrderTicket matching the specified filter More...
 
IEnumerable< OrderTicketGetOpenOrderTickets (Symbol symbol)
 Get an enumerable of open OrderTicket for the specified symbol More...
 
IEnumerable< OrderTicketGetOpenOrderTickets (Func< OrderTicket, bool > filter=null)
 Gets an enumerable of opened OrderTicket matching the specified filter More...
 
IEnumerable< OrderTicketGetOpenOrderTickets (PyObject filter)
 Gets an enumerable of opened OrderTicket matching the specified filter However, this method can be confused with the override that takes a Symbol as parameter. For this reason it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is a Python function object and not a Python representation of a Symbol. More...
 
decimal GetOpenOrdersRemainingQuantity (Func< OrderTicket, bool > filter=null)
 Gets the remaining quantity to be filled from open orders, i.e. order size minus quantity filled More...
 
decimal GetOpenOrdersRemainingQuantity (PyObject filter)
 Gets the remaining quantity to be filled from open orders, i.e. order size minus quantity filled However, this method can be confused with the override that takes a Symbol as parameter. For this reason it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is a Python function object and not a Python representation of a Symbol. More...
 
decimal GetOpenOrdersRemainingQuantity (Symbol symbol)
 Gets the remaining quantity to be filled from open orders for a Symbol, i.e. order size minus quantity filled More...
 
OrderTicket GetOrderTicket (int orderId)
 Gets the order ticket for the specified order id. Returns null if not found More...
 
bool WaitForOrder (int orderId)
 Wait for a specific order to be either Filled, Invalid or Canceled More...
 
List< OrderGetOpenOrders (Symbol symbol)
 Get a list of all open orders for a symbol. More...
 
List< OrderGetOpenOrders (Func< Order, bool > filter=null)
 Gets open orders matching the specified filter. Specifying null will return an enumerable of all open orders. More...
 
List< OrderGetOpenOrders (PyObject filter)
 Gets open orders matching the specified filter. However, this method can be confused with the override that takes a Symbol as parameter. For this reason it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is a Python function object and not a Python representation of a Symbol. 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...
 
IEnumerable< OrderGetOrders (PyObject filter)
 Gets all orders matching the specified filter. More...
 
int GetIncrementOrderId ()
 Get a new order id, and increment the internal counter. More...
 
int GetIncrementGroupOrderManagerId ()
 Get a new group order manager id, and increment the internal counter. More...
 
void SetOrderProcessor (IOrderProcessor orderProvider)
 Sets the IOrderProvider used for fetching orders for the algorithm More...
 
void AddTransactionRecord (DateTime time, decimal transactionProfitLoss, bool isWin)
 Record the transaction value and time in a list to later be processed for statistics creation. More...
 
void SetLiveMode (bool isLiveMode)
 Set live mode state of the algorithm More...
 

Properties

DateTime UtcTime [get]
 Gets the time the security information was last updated More...
 
Dictionary< DateTime, decimal > TransactionRecord [get]
 Trade record of profits and losses for each trade statistics calculations More...
 
int WinCount [get]
 Gets the number or winning transactions More...
 
int LossCount [get]
 Gets the number of losing transactions More...
 
Dictionary< DateTime, decimal > WinningTransactions [get]
 Trade record of profits and losses for each trade statistics calculations that are considered winning trades More...
 
Dictionary< DateTime, decimal > LosingTransactions [get]
 Trade record of profits and losses for each trade statistics calculations that are considered losing trades More...
 
decimal MinimumOrderSize [get]
 Configurable minimum order value to ignore bad orders, or orders with unrealistic sizes More...
 
int MinimumOrderQuantity [get]
 Configurable minimum order size to ignore bad orders, or orders with unrealistic sizes More...
 
int LastOrderId [get]
 Get the last order id. More...
 
TimeSpan MarketOrderFillTimeout [get, set]
 Configurable timeout for market order fills More...
 
int OrdersCount [get]
 Gets the current number of orders that have been processed More...
 
- Properties inherited from QuantConnect.Securities.IOrderProvider
int OrdersCount [get]
 Gets the current number of orders that have been processed More...
 

Detailed Description

Algorithm Transactions Manager - Recording Transactions

Definition at line 30 of file SecurityTransactionManager.cs.

Constructor & Destructor Documentation

◆ SecurityTransactionManager()

QuantConnect.Securities.SecurityTransactionManager.SecurityTransactionManager ( IAlgorithm  algorithm,
SecurityManager  security 
)

Initialise the transaction manager for holding and processing orders.

Definition at line 58 of file SecurityTransactionManager.cs.

Member Function Documentation

◆ ProcessRequest()

OrderTicket QuantConnect.Securities.SecurityTransactionManager.ProcessRequest ( OrderRequest  request)

Processes the order request

Parameters
requestThe request to be processed
Returns
The order ticket for the request

Definition at line 187 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetOrderId()

void QuantConnect.Securities.SecurityTransactionManager.SetOrderId ( SubmitOrderRequest  request)

Sets the order id for the specified submit request

Parameters
requestRequest to set the order id for

This method is public so we can request an order id from outside the assembly, for testing for example

Definition at line 207 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddOrder()

OrderTicket QuantConnect.Securities.SecurityTransactionManager.AddOrder ( SubmitOrderRequest  request)

Add an order to collection and return the unique order id or negative if an error.

Parameters
requestA request detailing the order to be submitted
Returns
New unique, increasing orderid

Definition at line 221 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateOrder()

OrderTicket QuantConnect.Securities.SecurityTransactionManager.UpdateOrder ( UpdateOrderRequest  request)

Update an order yet to be filled such as stop or limit orders.

Parameters
requestRequest detailing how the order should be updated

Does not apply if the order is already fully filled

Definition at line 231 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ CancelOrder()

OrderTicket QuantConnect.Securities.SecurityTransactionManager.CancelOrder ( int  orderId,
string  orderTag = null 
)

Added alias for RemoveOrder -

Parameters
orderIdOrder id we wish to cancel
orderTagTag to indicate from where this method was called

Definition at line 241 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CancelOpenOrders() [1/2]

List<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.CancelOpenOrders ( )

Cancels all open orders for all symbols

Returns
List containing the cancelled order tickets

Definition at line 250 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CancelOpenOrders() [2/2]

List<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.CancelOpenOrders ( Symbol  symbol,
string  tag = null 
)

Cancels all open orders for the specified symbol

Parameters
symbolThe symbol whose orders are to be cancelled
tagCustom order tag
Returns
List containing the cancelled order tickets

Definition at line 272 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ RemoveOrder()

OrderTicket QuantConnect.Securities.SecurityTransactionManager.RemoveOrder ( int  orderId,
string  tag = null 
)

Remove this order from outstanding queue: user is requesting a cancel.

Parameters
orderIdSpecific order id to remove
tagTag request

Definition at line 293 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOrderTickets() [1/2]

IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOrderTickets ( Func< OrderTicket, bool >  filter = null)

Gets an enumerable of OrderTicket matching the specified filter

Parameters
filterThe filter predicate used to find the required order tickets
Returns
An enumerable of OrderTicket matching the specified filter

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 303 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOrderTickets() [2/2]

IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOrderTickets ( PyObject  filter)

Gets an enumerable of OrderTicket matching the specified filter

Parameters
filterThe Python function filter used to find the required order tickets
Returns
An enumerable of OrderTicket matching the specified filter

Definition at line 313 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOpenOrderTickets() [1/3]

IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrderTickets ( Symbol  symbol)

Get an enumerable of open OrderTicket for the specified symbol

Parameters
symbolThe symbol for which to return the order tickets
Returns
An enumerable of open OrderTicket.

Definition at line 323 of file SecurityTransactionManager.cs.

Here is the caller graph for this function:

◆ GetOpenOrderTickets() [2/3]

IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrderTickets ( Func< OrderTicket, bool >  filter = null)

Gets an enumerable of opened OrderTicket matching the specified filter

Parameters
filterThe filter predicate used to find the required order tickets
Returns
An enumerable of opened OrderTicket matching the specified filter

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 333 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOpenOrderTickets() [3/3]

IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrderTickets ( PyObject  filter)

Gets an enumerable of opened OrderTicket matching the specified filter However, this method can be confused with the override that takes a Symbol as parameter. For this reason it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is a Python function object and not a Python representation of a Symbol.

Parameters
filterThe Python function filter used to find the required order tickets
Returns
An enumerable of opened OrderTicket matching the specified filter

Definition at line 346 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOpenOrdersRemainingQuantity() [1/3]

decimal QuantConnect.Securities.SecurityTransactionManager.GetOpenOrdersRemainingQuantity ( Func< OrderTicket, bool >  filter = null)

Gets the remaining quantity to be filled from open orders, i.e. order size minus quantity filled

Parameters
filterFilters the order tickets to be included in the aggregate quantity remaining to be filled
Returns
Total quantity that hasn't been filled yet for all orders that were not filtered

Definition at line 361 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOpenOrdersRemainingQuantity() [2/3]

decimal QuantConnect.Securities.SecurityTransactionManager.GetOpenOrdersRemainingQuantity ( PyObject  filter)

Gets the remaining quantity to be filled from open orders, i.e. order size minus quantity filled However, this method can be confused with the override that takes a Symbol as parameter. For this reason it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is a Python function object and not a Python representation of a Symbol.

Parameters
filterFilters the order tickets to be included in the aggregate quantity remaining to be filled
Returns
Total quantity that hasn't been filled yet for all orders that were not filtered

Definition at line 375 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOpenOrdersRemainingQuantity() [3/3]

decimal QuantConnect.Securities.SecurityTransactionManager.GetOpenOrdersRemainingQuantity ( Symbol  symbol)

Gets the remaining quantity to be filled from open orders for a Symbol, i.e. order size minus quantity filled

Parameters
symbolSymbol to get the remaining quantity of currently open orders
Returns
Total quantity that hasn't been filled yet for orders matching the Symbol

Definition at line 392 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOrderTicket()

OrderTicket QuantConnect.Securities.SecurityTransactionManager.GetOrderTicket ( int  orderId)

Gets the order ticket for the specified order id. Returns null if not found

Parameters
orderIdThe order's id
Returns
The order ticket with the specified id, or null if not found

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 402 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitForOrder()

bool QuantConnect.Securities.SecurityTransactionManager.WaitForOrder ( int  orderId)

Wait for a specific order to be either Filled, Invalid or Canceled

Parameters
orderIdThe id of the order to wait for
Returns
True if we successfully wait for the fill, false if we were unable to wait. This may be because it is not a market order or because the timeout was reached

Definition at line 414 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOpenOrders() [1/3]

List<Order> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrders ( Symbol  symbol)

Get a list of all open orders for a symbol.

Parameters
symbolThe symbol for which to return the orders
Returns
List of open orders.

Definition at line 443 of file SecurityTransactionManager.cs.

Here is the caller graph for this function:

◆ GetOpenOrders() [2/3]

List<Order> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrders ( Func< Order, bool >  filter = null)

Gets open orders matching the specified filter. Specifying null will return an enumerable of all open orders.

Parameters
filterDelegate used to filter the orders
Returns
All filtered open orders this order provider currently holds

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 454 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOpenOrders() [3/3]

List<Order> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrders ( PyObject  filter)

Gets open orders matching the specified filter. However, this method can be confused with the override that takes a Symbol as parameter. For this reason it first checks if it can convert the parameter into a symbol. If that conversion cannot be aplied it assumes the parameter is a Python function object and not a Python representation of a Symbol.

Parameters
filterPython function object used to filter the orders
Returns
All filtered open orders this order provider currently holds

Definition at line 468 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOrderById()

Order QuantConnect.Securities.SecurityTransactionManager.GetOrderById ( int  orderId)

Get the order by its id

Parameters
orderIdOrder id to fetch
Returns
A clone of the order with the specified id, or null if no match is found

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 492 of file SecurityTransactionManager.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOrdersByBrokerageId()

List<Order> QuantConnect.Securities.SecurityTransactionManager.GetOrdersByBrokerageId ( string  brokerageId)

Gets the order by its brokerage id

Parameters
brokerageIdThe brokerage id to fetch
Returns
The first order matching the brokerage id, or null if no match is found

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 502 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOrders() [1/2]

IEnumerable<Order> QuantConnect.Securities.SecurityTransactionManager.GetOrders ( Func< Order, bool >  filter = null)

Gets all orders matching the specified filter. Specifying null will return an enumerable of all orders.

Parameters
filterDelegate used to filter the orders
Returns
All orders this order provider currently holds by the specified filter

Implements QuantConnect.Securities.IOrderProvider.

Definition at line 513 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetOrders() [2/2]

IEnumerable<Order> QuantConnect.Securities.SecurityTransactionManager.GetOrders ( PyObject  filter)

Gets all orders matching the specified filter.

Parameters
filterPython function object used to filter the orders
Returns
All orders this order provider currently holds by the specified filter

Definition at line 523 of file SecurityTransactionManager.cs.

Here is the call graph for this function:

◆ GetIncrementOrderId()

int QuantConnect.Securities.SecurityTransactionManager.GetIncrementOrderId ( )

Get a new order id, and increment the internal counter.

Returns
New unique int order id.

Definition at line 532 of file SecurityTransactionManager.cs.

Here is the caller graph for this function:

◆ GetIncrementGroupOrderManagerId()

int QuantConnect.Securities.SecurityTransactionManager.GetIncrementGroupOrderManagerId ( )

Get a new group order manager id, and increment the internal counter.

Returns
New unique int group order manager id.

Definition at line 541 of file SecurityTransactionManager.cs.

Here is the caller graph for this function:

◆ SetOrderProcessor()

void QuantConnect.Securities.SecurityTransactionManager.SetOrderProcessor ( IOrderProcessor  orderProvider)

Sets the IOrderProvider used for fetching orders for the algorithm

Parameters
orderProviderThe IOrderProvider to be used to manage fetching orders

Definition at line 550 of file SecurityTransactionManager.cs.

◆ AddTransactionRecord()

void QuantConnect.Securities.SecurityTransactionManager.AddTransactionRecord ( DateTime  time,
decimal  transactionProfitLoss,
bool  isWin 
)

Record the transaction value and time in a list to later be processed for statistics creation.

Bit of a hack – but using datetime as dictionary key is dangerous as you can process multiple orders within a second. For the accounting / statistics generating purposes its not really critical to know the precise time, so just add a millisecond while there's an identical key.

Parameters
timeTime of order processed
transactionProfitLossProfit Loss.
isWinWhether the transaction is a win. For options exercise, this might not depend only on the profit/loss value

Definition at line 568 of file SecurityTransactionManager.cs.

Here is the caller graph for this function:

◆ SetLiveMode()

void QuantConnect.Securities.SecurityTransactionManager.SetLiveMode ( bool  isLiveMode)

Set live mode state of the algorithm

Parameters
isLiveModeTrue, live mode is enabled

Definition at line 585 of file SecurityTransactionManager.cs.

Here is the caller graph for this function:

Property Documentation

◆ UtcTime

DateTime QuantConnect.Securities.SecurityTransactionManager.UtcTime
get

Gets the time the security information was last updated

Definition at line 51 of file SecurityTransactionManager.cs.

◆ TransactionRecord

Dictionary<DateTime, decimal> QuantConnect.Securities.SecurityTransactionManager.TransactionRecord
get

Trade record of profits and losses for each trade statistics calculations

Will return a shallow copy, modifying the returned container will have no effect AddTransactionRecord

Definition at line 75 of file SecurityTransactionManager.cs.

◆ WinCount

int QuantConnect.Securities.SecurityTransactionManager.WinCount
get

Gets the number or winning transactions

Definition at line 89 of file SecurityTransactionManager.cs.

◆ LossCount

int QuantConnect.Securities.SecurityTransactionManager.LossCount
get

Gets the number of losing transactions

Definition at line 103 of file SecurityTransactionManager.cs.

◆ WinningTransactions

Dictionary<DateTime, decimal> QuantConnect.Securities.SecurityTransactionManager.WinningTransactions
get

Trade record of profits and losses for each trade statistics calculations that are considered winning trades

Definition at line 117 of file SecurityTransactionManager.cs.

◆ LosingTransactions

Dictionary<DateTime, decimal> QuantConnect.Securities.SecurityTransactionManager.LosingTransactions
get

Trade record of profits and losses for each trade statistics calculations that are considered losing trades

Definition at line 131 of file SecurityTransactionManager.cs.

◆ MinimumOrderSize

decimal QuantConnect.Securities.SecurityTransactionManager.MinimumOrderSize
get

Configurable minimum order value to ignore bad orders, or orders with unrealistic sizes

Default minimum order size is $0 value

Definition at line 146 of file SecurityTransactionManager.cs.

◆ MinimumOrderQuantity

int QuantConnect.Securities.SecurityTransactionManager.MinimumOrderQuantity
get

Configurable minimum order size to ignore bad orders, or orders with unrealistic sizes

Default minimum order size is 0 shares

Definition at line 153 of file SecurityTransactionManager.cs.

◆ LastOrderId

int QuantConnect.Securities.SecurityTransactionManager.LastOrderId
get

Get the last order id.

Definition at line 159 of file SecurityTransactionManager.cs.

◆ MarketOrderFillTimeout

TimeSpan QuantConnect.Securities.SecurityTransactionManager.MarketOrderFillTimeout
getset

Configurable timeout for market order fills

Default value is 5 seconds

Definition at line 171 of file SecurityTransactionManager.cs.

◆ OrdersCount

int QuantConnect.Securities.SecurityTransactionManager.OrdersCount
get

Gets the current number of orders that have been processed

Definition at line 483 of file SecurityTransactionManager.cs.


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