def TrailBracketOrder(self, parentOrderId, childOrderId, action, quantity, limitPrice, trailAmount): # This will be our main or "parent" order parent = Order() parent.orderId = parentOrderId parent.action = action parent.orderType = "LMT" parent.totalQuantity = 1000 #quantity parent.lmtPrice = limitPrice parent.transmit = False stopLoss = Order() stopLoss.orderId = childOrderId logging.info("Action is " + action) if action == "Buy": stopLoss.action = "Sell" stopLoss.trailStopPrice = limitPrice - (limitPrice * .02) if action == "Sell": stopLoss.action = "Buy" stopLoss.trailStopPrice = limitPrice + (limitPrice * .02) stopLoss.orderType = "TRAIL" stopLoss.auxPrice = limitPrice #trailAmount #trailAmount stopLoss.totalQuantity = 1000 #quantity stopLoss.parentId = parentOrderId stopLoss.transmit = True bracketOrder = [parent, stopLoss] return bracketOrder
def validate_order_trigger(order: Order, price: BarData) -> None: """ Verify if adjustable order triggered modification. If so modify order in place. """ # order doesn't have a trigger price (default value) if order.triggerPrice == 1.7976931348623157e+308: log.debug('validate_order_trigger returned') return if ((order.action.upper() == 'BUY' and order.triggerPrice >= price.low) or (order.action.upper() == 'SELL' and order.triggerPrice <= price.high)): order.orderType = order.adjustedOrderType order.auxPrice = order.adjustedStopPrice # prevent future trigger verification order.triggerPrice = 1.7976931348623157e+308 log.debug(f'Order adjusted: {order}')