|
Lean
$LEAN_TAG$
|
Algorithm Transactions Manager - Recording Transactions More...
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< OrderTicket > | CancelOpenOrders () |
| Cancels all open orders for all symbols More... | |
| List< OrderTicket > | CancelOpenOrders (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< OrderTicket > | GetOrderTickets (Func< OrderTicket, bool > filter=null) |
| Gets an enumerable of OrderTicket matching the specified filter More... | |
| IEnumerable< OrderTicket > | GetOrderTickets (PyObject filter) |
| Gets an enumerable of OrderTicket matching the specified filter More... | |
| IEnumerable< OrderTicket > | GetOpenOrderTickets (Symbol symbol) |
| Get an enumerable of open OrderTicket for the specified symbol More... | |
| IEnumerable< OrderTicket > | GetOpenOrderTickets (Func< OrderTicket, bool > filter=null) |
| Gets an enumerable of opened OrderTicket matching the specified filter More... | |
| IEnumerable< OrderTicket > | 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. 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< Order > | GetOpenOrders (Symbol symbol) |
| Get a list of all open orders for a symbol. More... | |
| List< Order > | GetOpenOrders (Func< Order, bool > filter=null) |
| Gets open orders matching the specified filter. Specifying null will return an enumerable of all open orders. More... | |
| List< Order > | 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. 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... | |
| IEnumerable< Order > | GetOrders (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... | |
Algorithm Transactions Manager - Recording Transactions
Definition at line 30 of file SecurityTransactionManager.cs.
| 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.
| OrderTicket QuantConnect.Securities.SecurityTransactionManager.ProcessRequest | ( | OrderRequest | request | ) |
Processes the order request
| request | The request to be processed |
Definition at line 187 of file SecurityTransactionManager.cs.
| void QuantConnect.Securities.SecurityTransactionManager.SetOrderId | ( | SubmitOrderRequest | request | ) |
Sets the order id for the specified submit request
| request | Request 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.
| OrderTicket QuantConnect.Securities.SecurityTransactionManager.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 221 of file SecurityTransactionManager.cs.
| OrderTicket QuantConnect.Securities.SecurityTransactionManager.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 231 of file SecurityTransactionManager.cs.
| OrderTicket QuantConnect.Securities.SecurityTransactionManager.CancelOrder | ( | int | orderId, |
| string | orderTag = null |
||
| ) |
Added alias for RemoveOrder -
| orderId | Order id we wish to cancel |
| orderTag | Tag to indicate from where this method was called |
Definition at line 241 of file SecurityTransactionManager.cs.
| List<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.CancelOpenOrders | ( | ) |
Cancels all open orders for all symbols
Definition at line 250 of file SecurityTransactionManager.cs.
| List<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.CancelOpenOrders | ( | Symbol | symbol, |
| string | tag = null |
||
| ) |
Cancels all open orders for the specified symbol
| symbol | The symbol whose orders are to be cancelled |
| tag | Custom order tag |
Definition at line 272 of file SecurityTransactionManager.cs.
| OrderTicket QuantConnect.Securities.SecurityTransactionManager.RemoveOrder | ( | int | orderId, |
| string | tag = null |
||
| ) |
Remove this order from outstanding queue: user is requesting a cancel.
| orderId | Specific order id to remove |
| tag | Tag request |
Definition at line 293 of file SecurityTransactionManager.cs.
| IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOrderTickets | ( | Func< OrderTicket, bool > | filter = null | ) |
Gets an 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 303 of file SecurityTransactionManager.cs.
| IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOrderTickets | ( | PyObject | filter | ) |
Gets an enumerable of OrderTicket matching the specified filter
| filter | The Python function filter used to find the required order tickets |
Definition at line 313 of file SecurityTransactionManager.cs.
| IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrderTickets | ( | Symbol | symbol | ) |
Get an enumerable of open OrderTicket for the specified symbol
| symbol | The symbol for which to return the order tickets |
Definition at line 323 of file SecurityTransactionManager.cs.
| IEnumerable<OrderTicket> QuantConnect.Securities.SecurityTransactionManager.GetOpenOrderTickets | ( | Func< OrderTicket, bool > | filter = null | ) |
Gets an 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 333 of file SecurityTransactionManager.cs.
| 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.
| filter | The Python function filter used to find the required order tickets |
Definition at line 346 of file SecurityTransactionManager.cs.
| 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
| filter | Filters the order tickets to be included in the aggregate quantity remaining to be filled |
Definition at line 361 of file SecurityTransactionManager.cs.
| 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.
| filter | Filters the order tickets to be included in the aggregate quantity remaining to be filled |
Definition at line 375 of file SecurityTransactionManager.cs.
| 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
| symbol | Symbol to get the remaining quantity of currently open orders |
Definition at line 392 of file SecurityTransactionManager.cs.
| OrderTicket QuantConnect.Securities.SecurityTransactionManager.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 402 of file SecurityTransactionManager.cs.
| bool QuantConnect.Securities.SecurityTransactionManager.WaitForOrder | ( | int | orderId | ) |
Wait for a specific order to be either Filled, Invalid or Canceled
| orderId | The id of the order to wait for |
Definition at line 414 of file SecurityTransactionManager.cs.
Get a list of all open orders for a symbol.
| symbol | The symbol for which to return the orders |
Definition at line 443 of file SecurityTransactionManager.cs.
| 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.
| filter | Delegate used to filter the orders |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 454 of file SecurityTransactionManager.cs.
| 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.
| filter | Python function object used to filter the orders |
Definition at line 468 of file SecurityTransactionManager.cs.
| Order QuantConnect.Securities.SecurityTransactionManager.GetOrderById | ( | int | orderId | ) |
Get the order by its id
| orderId | Order id to fetch |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 492 of file SecurityTransactionManager.cs.
| List<Order> QuantConnect.Securities.SecurityTransactionManager.GetOrdersByBrokerageId | ( | string | brokerageId | ) |
Gets the order by its brokerage id
| brokerageId | The brokerage id to fetch |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 502 of file SecurityTransactionManager.cs.
| 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.
| filter | Delegate used to filter the orders |
Implements QuantConnect.Securities.IOrderProvider.
Definition at line 513 of file SecurityTransactionManager.cs.
| IEnumerable<Order> QuantConnect.Securities.SecurityTransactionManager.GetOrders | ( | PyObject | filter | ) |
Gets all orders matching the specified filter.
| filter | Python function object used to filter the orders |
Definition at line 523 of file SecurityTransactionManager.cs.
| int QuantConnect.Securities.SecurityTransactionManager.GetIncrementOrderId | ( | ) |
Get a new order id, and increment the internal counter.
Definition at line 532 of file SecurityTransactionManager.cs.
| int QuantConnect.Securities.SecurityTransactionManager.GetIncrementGroupOrderManagerId | ( | ) |
Get a new group order manager id, and increment the internal counter.
Definition at line 541 of file SecurityTransactionManager.cs.
| void QuantConnect.Securities.SecurityTransactionManager.SetOrderProcessor | ( | IOrderProcessor | orderProvider | ) |
Sets the IOrderProvider used for fetching orders for the algorithm
| orderProvider | The IOrderProvider to be used to manage fetching orders |
Definition at line 550 of file SecurityTransactionManager.cs.
| 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.
| time | Time of order processed |
| transactionProfitLoss | Profit Loss. |
| isWin | Whether 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.
| void QuantConnect.Securities.SecurityTransactionManager.SetLiveMode | ( | bool | isLiveMode | ) |
Set live mode state of the algorithm
| isLiveMode | True, live mode is enabled |
Definition at line 585 of file SecurityTransactionManager.cs.
|
get |
Gets the time the security information was last updated
Definition at line 51 of file SecurityTransactionManager.cs.
|
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.
|
get |
Gets the number or winning transactions
Definition at line 89 of file SecurityTransactionManager.cs.
|
get |
Gets the number of losing transactions
Definition at line 103 of file SecurityTransactionManager.cs.
|
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.
|
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.
|
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.
|
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.
|
get |
Get the last order id.
Definition at line 159 of file SecurityTransactionManager.cs.
|
getset |
Configurable timeout for market order fills
Default value is 5 seconds
Definition at line 171 of file SecurityTransactionManager.cs.
|
get |
Gets the current number of orders that have been processed
Definition at line 483 of file SecurityTransactionManager.cs.