Skip to navigation

Order Conditioning

View as Markdown

Order Conditions are a set of parameters attached to an order that allow the order to either be placed or cancel upon achieving the condition criteria. There are 6 unique Order Conditions that can be applied to a given order: Price, Time, Margin, Execution, Volume, and PercentChange.

Order Conditions can be applied to nearly any order and more than one condition can be attached to an individual order using to be Inclusive, “AND”, or Exclusive, “OR”.

More information on Order Conditions can be found here.

For the sake of simplicity, all Condition Orders below will be based on an example order, shown here. The additional content will be included in each order’s content.

base_order = Order()
base_order.action = action
base_order.orderType = "MKT"
base_order.totalQuantity = quantity
base_order.conditionsCancelOrder = False

Price Conditions

A Price Condition will trigger if an order should transmit or cancel when a given contract’s price goes above or beyond a given threshold.

See PriceCondition for more details on the PriceCondition class.

priceCondition = PriceCondition()
priceCondition.conId = conId
priceCondition.exchange = exchange
priceCondition.isMore = isMore
priceCondition.triggerMethod = triggerMethod
priceCondition.price = price
base_order.conditions = [priceCondition]

Time Conditions

The Time Condition will trigger an order for submission or cancellation after a time has been reached.

See TimeCondition for more details on the TimeCondition class.

timeCondition = order_condition.Create(OrderCondition.Time)
timeCondition.isMore = isMore
timeCondition.time = time
timeCondition.isConjunctionConnection = isConjunction
base_order.conditions = [timeCondition]

Margin Conditions

Margin Conditions permit users to ready an order in case their order starts falling to a given threshold that may lead to liquidation or to submit an order after ample margin cushion has been established.

See MarginCondition for more details on the MarginCondition class.

marginCondition = order_condition.Create(OrderCondition.Margin)
marginCondition.isMore = isMore
marginCondition.percent = percent
marginCondition.isConjunctionConnection = isConjunction
base_order.conditions = [marginCondition]

Execution Conditions

The Execution Condition triggers an order whenever another order on your account has executed. The parameters allow the developer to specify how narrow a scope will trigger a condition.

See ExecutionCondition for more details on the ExecutionCondition class.

execCondition = order_condition.Create(OrderCondition.Execution)
execCondition.symbol = symbol
execCondition.exchange = exchange
execCondition.secType = secType
base_order.conditions = [execCondition]

Volume Conditions

Volume Condition will trigger in the event the contract’s volume remains above or below a given threshold.

Note: VolumeCondition orders must be SMART routed.

See VolumeCondition for more details on the VolumeCondition class.

volCond = order_condition.Create(OrderCondition.Volume)
volCond.conId = conId
volCond.exchange = exchange
volCond.isMore = isMore
volCond.volume = volume
volCond.isConjunctionConnection = isConjunction

Percentage Conditions

The Percent Change Condition will trigger if there is a price percent change measured against last close price.

See PercentChangeCondition for more details on the PercentChangeCondition class.

pctChangeCondition = order_condition.Create(OrderCondition.PercentChange)
pctChangeCondition.isMore = isMore
pctChangeCondition.changePercent = pctChange
pctChangeCondition.conId = conId
pctChangeCondition.exchange = exchange
pctChangeCondition.isConjunctionConnection = isConjunction
base_order.conditions = [pctChangeCondition]