SecurityTransactionManager
QuantConnect.Securities.SecurityTransactionManager
SecurityTransactionManager(
algorithm: IAlgorithm, security: SecurityManager
)
Bases: Object, IOrderProvider
Algorithm Transactions Manager - Recording Transactions
Initialise the transaction manager for holding and processing orders.
utc_time
utc_time: datetime
Gets the time the security information was last updated
transaction_record
transaction_record: Dictionary[datetime, float]
Trade record of profits and losses for each trade statistics calculations
win_count
win_count: int
Gets the number or winning transactions
loss_count
loss_count: int
Gets the number of losing transactions
winning_transactions
winning_transactions: Dictionary[datetime, float]
Trade record of profits and losses for each trade statistics calculations that are considered winning trades
losing_transactions
losing_transactions: Dictionary[datetime, float]
Trade record of profits and losses for each trade statistics calculations that are considered losing trades
minimum_order_size
minimum_order_size: float
Configurable minimum order value to ignore bad orders, or orders with unrealistic sizes
MinimumOrderSize is obsolete and will not be used, please use Settings.MinimumOrderMarginPortfolioPercentage instead
minimum_order_quantity
minimum_order_quantity: int
Configurable minimum order size to ignore bad orders, or orders with unrealistic sizes
MinimumOrderQuantity is obsolete and will not be used, please use Settings.MinimumOrderMarginPortfolioPercentage instead
last_order_id
last_order_id: int
Get the last order id.
market_order_fill_timeout
market_order_fill_timeout: timedelta
Configurable timeout for market order fills
orders_count
orders_count: int
Gets the current number of orders that have been processed
cancel_open_orders
cancel_open_orders() -> List[OrderTicket]
cancel_open_orders(
symbol: Union[Symbol, str, BaseContract],
tag: str = None,
) -> List[OrderTicket]
Signature descriptions:
-
Cancels all open orders for all symbols
-
Cancels all open orders for the specified symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Optional[Union[Symbol, str, BaseContract]]
|
The symbol whose orders are to be cancelled |
None
|
tag
|
Optional[str]
|
Custom order tag |
None
|
Returns:
| Type | Description |
|---|---|
List[OrderTicket]
|
List containing the cancelled order tickets. |
get_open_order_tickets
get_open_order_tickets(
filter: Any,
) -> Iterable[OrderTicket]
get_open_order_tickets(
symbol: Union[Symbol, str, BaseContract],
) -> Iterable[OrderTicket]
get_open_order_tickets(
filter: Callable[[OrderTicket], bool] = None,
) -> Iterable[OrderTicket]
Signature descriptions:
-
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.
-
Get an enumerable of open OrderTicket for the specified symbol
-
Gets an enumerable of opened OrderTicket matching the specified filter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
Optional[Any | Callable[[OrderTicket], bool]]
|
The Python function filter used to find the required order tickets |
None
|
symbol
|
Optional[Union[Symbol, str, BaseContract]]
|
The symbol for which to return the order tickets |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[OrderTicket]
|
Depends on the signature used. Case 1: [An enumerable of opened OrderTicket matching the specified filter.]; Case 2: [An enumerable of open OrderTicket.] |
get_open_orders
get_open_orders(filter: Any) -> List[Order]
get_open_orders(
symbol: Union[Symbol, str, BaseContract],
) -> List[Order]
Signature descriptions:
-
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.
-
Get a list of all open orders for a symbol.
-
Gets open orders matching the specified filter. Specifying null will return an enumerable of all open orders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
Optional[Any | Callable[[Order], bool]]
|
Python function object used to filter the orders |
None
|
symbol
|
Optional[Union[Symbol, str, BaseContract]]
|
The symbol for which to return the orders |
None
|
Returns:
| Type | Description |
|---|---|
List[Order]
|
Depends on the signature used. Case 1: [All filtered open orders this order provider currently holds.]; Case 2: [List of open orders.] |
get_open_orders_remaining_quantity
get_open_orders_remaining_quantity(filter: Any) -> float
get_open_orders_remaining_quantity(
filter: Callable[[OrderTicket], bool] = None,
) -> float
get_open_orders_remaining_quantity(
symbol: Union[Symbol, str, BaseContract],
) -> float
Signature descriptions:
-
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.
-
Gets the remaining quantity to be filled from open orders, i.e. order size minus quantity filled
-
Gets the remaining quantity to be filled from open orders for a Symbol, i.e. order size minus quantity filled
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
Optional[Any | Callable[[OrderTicket], bool]]
|
Filters the order tickets to be included in the aggregate quantity remaining to be filled |
None
|
symbol
|
Optional[Union[Symbol, str, BaseContract]]
|
Symbol to get the remaining quantity of currently open orders |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Depends on the signature used. Case 1: [Total quantity that hasn't been filled yet for all orders that were not filtered.]; Case 2: [Total quantity that hasn't been filled yet for orders matching the Symbol.] |
get_order_tickets
get_order_tickets(filter: Any) -> Iterable[OrderTicket]
get_order_tickets(
filter: Callable[[OrderTicket], bool] = None,
) -> Iterable[OrderTicket]
Gets an enumerable of OrderTicket matching the specified filter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
Any | Callable[[OrderTicket], bool]
|
The Python function filter used to find the required order tickets |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[OrderTicket]
|
An enumerable of OrderTicket matching the specified filter. |
get_orders
get_orders(filter: Any) -> Iterable[Order]
Signature descriptions:
-
Gets all orders matching the specified filter.
-
Gets all orders matching the specified filter. Specifying null will return an enumerable of all orders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
Any | Callable[[Order], bool]
|
Python function object used to filter the orders |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Order]
|
All orders this order provider currently holds by the specified filter. |
add_order
add_order(request: SubmitOrderRequest) -> OrderTicket
Add an order to collection and return the unique order id or negative if an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SubmitOrderRequest
|
A request detailing the order to be submitted |
required |
Returns:
| Type | Description |
|---|---|
OrderTicket
|
New unique, increasing orderid. |
add_transaction_record
add_transaction_record(
time: Union[datetime, date],
transaction_profit_loss: float,
is_win: bool,
) -> None
Record the transaction value and time in a list to later be processed for statistics creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Union[datetime, date]
|
Time of order processed |
required |
transaction_profit_loss
|
float
|
Profit Loss. |
required |
is_win
|
bool
|
Whether the transaction is a win. For options exercise, this might not depend only on the profit/loss value |
required |
cancel_order
cancel_order(
order_id: int, order_tag: str = None
) -> OrderTicket
Added alias for RemoveOrder -
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
int
|
Order id we wish to cancel |
required |
order_tag
|
str
|
Tag to indicate from where this method was called |
None
|
get_increment_group_order_manager_id
get_increment_group_order_manager_id() -> int
Get a new group order manager id, and increment the internal counter.
Returns:
| Type | Description |
|---|---|
int
|
New unique int group order manager id. |
get_increment_order_id
get_increment_order_id() -> int
Get a new order id, and increment the internal counter.
Returns:
| Type | Description |
|---|---|
int
|
New unique int order id. |
get_order_by_id
get_order_by_id(order_id: int) -> Order
Get the order by its id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
int
|
Order id to fetch |
required |
Returns:
| Type | Description |
|---|---|
Order
|
A clone of the order with the specified id, or null if no match is found. |
get_orders_by_brokerage_id
get_orders_by_brokerage_id(
brokerage_id: str,
) -> List[Order]
Gets the order by its brokerage id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
brokerage_id
|
str
|
The brokerage id to fetch |
required |
Returns:
| Type | Description |
|---|---|
List[Order]
|
The first order matching the brokerage id, or null if no match is found. |
get_order_ticket
get_order_ticket(order_id: int) -> OrderTicket
Gets the order ticket for the specified order id. Returns null if not found
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
int
|
The order's id |
required |
Returns:
| Type | Description |
|---|---|
OrderTicket
|
The order ticket with the specified id, or null if not found. |
get_projected_holdings
get_projected_holdings(
security: Security,
) -> ProjectedHoldings
Calculates the projected holdings for the specified security based on the current open orders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security |
required |
Returns:
| Type | Description |
|---|---|
ProjectedHoldings
|
The projected holdings for the specified security, which is the sum of the current holdings plus the sum of the open orders quantity. |
process_request
process_request(request: OrderRequest) -> OrderTicket
Processes the order request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
OrderRequest
|
The request to be processed |
required |
Returns:
| Type | Description |
|---|---|
OrderTicket
|
The order ticket for the request. |
remove_order
remove_order(order_id: int, tag: str = None) -> OrderTicket
Remove this order from outstanding queue: user is requesting a cancel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
int
|
Specific order id to remove |
required |
tag
|
str
|
Tag request |
None
|
set_live_mode
set_live_mode(is_live_mode: bool) -> None
Set live mode state of the algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_live_mode
|
bool
|
True, live mode is enabled |
required |
set_order_id
set_order_id(request: SubmitOrderRequest) -> None
Sets the order id for the specified submit request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SubmitOrderRequest
|
Request to set the order id for |
required |
set_order_processor
set_order_processor(
order_provider: IOrderProcessor,
) -> None
Sets the IOrderProvider used for fetching orders for the algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_provider
|
IOrderProcessor
|
The IOrderProvider to be used to manage fetching orders |
required |
update_order
update_order(request: UpdateOrderRequest) -> OrderTicket
Update an order yet to be filled such as stop or limit orders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
UpdateOrderRequest
|
Request detailing how the order should be updated |
required |
wait_for_order
wait_for_order(order_id: int) -> bool
Wait for a specific order to be either Filled, Invalid or Canceled
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
int
|
The id of the order to wait for |
required |
Returns:
| Type | Description |
|---|---|
bool
|
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. |