I am trying to setup a bracket order that uses a mkt order as parent with a trail aux price stop as well as a target. I have built code that will execute a mkt order and then attach a trail with specified aux price but I can't seem to understand how to tell the limit order to place the target x amount of dollars above the entry price of the market order. I have some coding background but this API TWS stuff is so difficult for me to understand.?
here is some working code mentioned above. I am aware of the bracket order but how do you define the target price. Also does Interactive brokers even allow you to do a MKT bracket order with trail stop and target based on a hard number above entry??
thank you for any help.?
qty=2
def make_order(action, quantity):
order = Order()
order.m_orderType = 'MKT'
order.m_totalQuantity = quantity
order.m_action = action
order.m_outsideRth = True
return order
def make_contract(symbol, sec_type, exch, curr, exp):
Contract.m_symbol = symbol
Contract.m_secType = sec_type
Contract.m_exchange = exch
Contract.m_currency = curr
Contract.m_expiry= exp
return Contract
def stop_lm(action,qty):
stopLoss = Order()
stopLoss.m_action = action
stopLoss.m_orderType = "TRAIL"
stopLoss.m_auxPrice = 4.00
stopLoss.m_totalQuantity = qty
stopLoss.m_outsideRth = True
return stopLoss
act="BUY"
cont = make_contract ('ES', "FUT", 'GLOBEX', 'USD',"201909")
offer = make_order(act, qty)
tws.placeOrder(orderId, cont, offer)
offers = stop_lm("SELL",qty)
tws.placeOrder(orderId +1,cont,offers)