Skip to content

ContingentOrderExtensions

QuantConnect.Orders.ContingentOrderExtensions

Bases: Object

Contingent orders (OCO, OTO, OUO, brackets) extension methods for easiest manipulation

get_contingency_link(
    order: Order, role: ContingencyRole
) -> ContingencyLink

Gets the first ContingencyType.ONE_TRIGGERS_OTHER link of the order with the given role, null if none

get_contingent_children

get_contingent_children(
    order: Order, contingent_orders: List[Order]
) -> Sequence[Order]

Gets the children the given parent order triggers once filled

Parameters:

Name Type Description Default
order Order

The parent order

required
contingent_orders List[Order]

The orders in the set

required

get_contingent_descendants

get_contingent_descendants(
    order: Order, contingent_orders: Sequence[Order]
) -> List[Order]

Gets all the descendants of the given order: its children, their children and so on

Parameters:

Name Type Description Default
order Order

The parent order

required
contingent_orders Sequence[Order]

The orders in the set

required

get_contingent_parents

get_contingent_parents(
    order: Order, contingent_orders: List[Order]
) -> Sequence[Order]

Gets the parent orders of the given child, more than one when the parent is a combo order

Parameters:

Name Type Description Default
order Order

The child order

required
contingent_orders List[Order]

The orders in the set

required

get_contingent_siblings

get_contingent_siblings(
    order: Order, contingent_orders: List[Order]
) -> Sequence[Order]

Gets the sibling orders of the given one, the other members of its OCO/OUO contingency. The legs of the same combo order are not siblings

Parameters:

Name Type Description Default
order Order

The member order

required
contingent_orders List[Order]

The orders in the set

required

get_existing_contingent_orders

get_existing_contingent_orders(
    order: Order, order_provider: Callable[[int], Order]
) -> List[Order]

Gets the orders of the set which exist in the given provider, without requiring all of them to be present

Parameters:

Name Type Description Default
order Order

Target order, which can be any of the orders in the set

required
order_provider Callable[[int], Order]

Order provider to use to access the existing orders

required

Returns:

Type Description
List[Order]

The existing orders of the set, including the given one, sorted by id.

get_sibling_link(order: Order) -> ContingencyLink

Gets the link of the order to its siblings, the other members of its ContingencyType.ONE_CANCELS_OTHER or ContingencyType.ONE_UPDATES_OTHER contingency, null if none

get_triggered_time

get_triggered_time(order: Order) -> Optional[datetime]

Gets the utc time at which the contingent child order was triggered, null if not a child or not triggered yet

get_working_time

get_working_time(order: Order) -> datetime

Gets the utc time from which the order is considered to be working in the market: the time it was triggered for contingent child orders, else its creation time

is_contingent

is_contingent(order: Order) -> bool

Determines whether the order is part of a set of contingent orders

is_contingent_sibling

is_contingent_sibling(order: Order, other: Order) -> bool

Determines whether both orders are members of the same ContingencyType.ONE_CANCELS_OTHER or ContingencyType.ONE_UPDATES_OTHER contingency, so at most one of them is expected to completely fill

is_same_group_order

is_same_group_order(order: Order, other: Order) -> bool

Determines whether both orders are legs of the same group (combo) order

is_waiting_for_trigger

is_waiting_for_trigger(order: Order) -> bool

Determines whether the order is a contingent child still held waiting for its parent to fill, that is, the order is not working in the market yet

try_get_contingent_orders

try_get_contingent_orders(
    order: Order,
    order_provider: Callable[[int], Order],
    orders: Optional[List[Order]],
) -> Tuple[bool, List[Order]]

Gets all the orders in the set of contingent orders the given order belongs to

Parameters:

Name Type Description Default
order Order

Target order, which can be any of the orders in the set

required
order_provider Callable[[int], Order]

Order provider to use to access the existing orders

required
orders Optional[List[Order]]

List of orders in the set, sorted by id

required

Returns:

Type Description
Tuple[bool, List[Order]]

False if any of the orders in the set is not yet found in the order provider. True otherwise.