I am currently using this code to do my trades as bracket orders. I need my trades to exit by the end of the day. Is it possible to place a limit or market order at 15:59 or 16:00 and have it continue trading after market hours to get the fill using this?
def BracketOrder(self, parentOrderId:int, openinglimitPrice:float, quantity:Decimal, trailingPercent:float, timeswitch:str, adaptive_type:str):
# 1st part: Buy Adaptive Algo order
opening = Order()
opening.orderId = parentOrderId
opening.action = "BUY"
opening.orderType = "LMT"
opening.lmtPrice = openinglimitPrice
opening.totalQuantity = abs(quantity)
opening.transmit = False
opening.tif = 'GTC'
algo.FillAdaptiveParams(opening, adaptive_type)
timeCondition = TimeCondition()
timeCondition.time = timeswitch
timeCondition.isMore = True
opening.conditions.append(timeCondition)
# 2nd part: Trailing Stop Sell order
trailingStopLoss = Order()
trailingStopLoss.orderId = opening.orderId + 1
trailingStopLoss.action = "SELL"
trailingStopLoss.trailingPercent = trailingPercent
trailingStopLoss.orderType = "TRAIL"
trailingStopLoss.totalQuantity = abs(quantity)
trailingStopLoss.parentId = parentOrderId
trailingStopLoss.tif = "GTC"
trailingStopLoss.transmit = False
# 3rd part: Sell Market order
closing = Order()
closing.orderId = opening.orderId + 2
closing.action = "SELL"
closing.orderType = "MKT"
closing.totalQuantity = abs(quantity)
closing.parentId = parentOrderId
closing.tif = "GTC"
closing.goodAfterTime = timeswitch
closing.transmit = True
closing.conditionsCancelOrder = False
timeCondition = TimeCondition()
timeCondition.time = timeswitch
timeCondition.isMore = True
closing.conditions.append(timeCondition)
bracketOrder = [opening, trailingStopLoss, closing]
return bracketOrder