Skip to content

GroupOrderExtensions

QuantConnect.Orders.GroupOrderExtensions

Bases: Object

Group (combo) orders extension methods for easiest combo order manipulation

get_error_message

get_error_message(
    securities: Dictionary[Order, Security],
    has_sufficient_buying_power_result: HasSufficientBuyingPowerForOrderResult,
) -> str

Returns an error string message saying there is insufficient buying power for the given orders associated with their respective securities

get_group_quantity_by_each_leg_quantity

get_group_quantity_by_each_leg_quantity(
    leg_quantity: List[float],
    order_direction: OrderDirection,
) -> float

Calculates the greatest common divisor (GCD) of the provided leg quantities and returns it as a signed quantity based on the OrderDirection.

Parameters:

Name Type Description Default
leg_quantity List[float]

A collection of leg quantities.

required
order_direction OrderDirection

Determines the sign of the returned quantity: OrderDirection.BUY returns a positive quantity, OrderDirection.SELL returns a negative quantity.

required

Returns:

Type Description
float

The greatest common divisor of the leg quantities, signed according to order_direction.

get_order_leg_group_quantity

get_order_leg_group_quantity(
    leg_ratio: float, group_order_manager: GroupOrderManager
) -> float

Gets the combo order leg group quantity, that is, the total number of shares to be bought/sold from this leg, from its ratio and the group order quantity

Parameters:

Name Type Description Default
leg_ratio float

The leg ratio

required
group_order_manager GroupOrderManager

The group order manager

required

Returns:

Type Description
float

The total number of shares to be bought/sold from this leg.

get_order_leg_ratio

get_order_leg_ratio(
    leg_group_quantity: float,
    group_order_manager: GroupOrderManager,
) -> float

Gets the combo order leg ratio from its group quantity and the group order quantity

Parameters:

Name Type Description Default
leg_group_quantity float

The total number of shares to be bought/sold from this leg, that is, the result of the let ratio times the group quantity

required
group_order_manager GroupOrderManager

The group order manager

required

Returns:

Type Description
float

The ratio of this combo order leg.

try_get_group_orders

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

Gets the grouped orders (legs) of a group order

Parameters:

Name Type Description Default
order Order

Target order, which can be any of the legs of the combo

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 combo

required

Returns:

Type Description
Tuple[bool, List[Order]]

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

try_get_group_orders_securities

try_get_group_orders_securities(
    orders: List[Order],
    security_provider: ISecurityProvider,
    securities: Optional[Dictionary[Order, Security]],
) -> Tuple[bool, Dictionary[Order, Security]]

Gets the securities corresponding to each order in the group

Parameters:

Name Type Description Default
orders List[Order]

List of orders to map

required
security_provider ISecurityProvider

The security provider to use

required
securities Optional[Dictionary[Order, Security]]

The resulting map of order to security

required

Returns:

Type Description
Tuple[bool, Dictionary[Order, Security]]

True if the mapping is successful, false otherwise.