0

The order gets placed into tws but on activation it just cancels itself and the attached stop and target. Leaving me with no orders no pos. Is this because of the way I am attaching the parent and not setting transmit to false until target? I was couldn't figure out the example by in the tws guide using the transmit = false then last one true. Is that why this isn't working?


###################################Place Buy /BUY Bracket
                if direction == "BUY":
                    app.reqGlobalCancel()
                    Entry = Order()
                    Entry.action = 'BUY'
                    Entry.orderId = app.nextorderId
                    Entry.orderType = 'STP LMT'
                    Entry.auxPrice = price + .25
                    Entry.lmtPrice = price + .25
                    Entry.totalQuantity = lotsize
                    Entry.outsideRth = True
                    Entry.tif = 'GTC'
                    app.placeOrder(Entry.orderId, contract, Entry)

###################################Place Stop /BUY Bracket                  
                    app.nextorderId += 1
                    stop_order = Order()
                    stop_order.parentId = Entry.orderId
                    stop_order.action = 'SELL'
                    stop_order.orderType = 'STP'
                    stop_order.auxPrice = buystop + .25
                    stop_order.totalQuantity = lotsize                  
                    stop_order.orderId= Entry.orderId +1
                    stop_order.outsideRth = True
                    stop_order.tif = 'GTC'
                    app.placeOrder(stop_order.orderId, contract, stop_order)
                    stopid=str(stop_order.orderId)
###################################Store Stop Id for stop adjustments                   
                    if path.exists("StopOrder.txt"):
                        os.remove("StopOrder.txt")            
                    file = open("StopOrder.txt","w")
                    file.write(stopid)
                    file.close()
###################################Place Target /BUY Bracket
                    app.nextorderId += 1                
                    target_order = Order()
                    target_order.parentId = Entry.orderId
                    target_order.action = 'SELL'
                    target_order.orderType = 'LMT'
                    target_order.lmtPrice = buytar + .25
                    target_order.totalQuantity = lotsize
                    target_order.outsideRth = True
                    target_order.tif = 'GTC'
                    app.placeOrder(app.nextorderId, contract, target_order)
  • It was working when I was using a stp order as the entry ... – Nikolaos Trader Jul 22 '20 at 00:27
  • Here is the terminal output after the order is placed. – Nikolaos Trader Jul 22 '20 at 16:53
  • openOrder id: 278 ES FUT @ GLOBEX : BUY STP LMT 40.0 PreSubmitted orderStatus - orderid: 278 status: PreSubmitted filled 0.0 remaining 40.0 lastFillPrice 0.0 openOrder id: 279 ES FUT @ GLOBEX : SELL STP 40.0 PreSubmitted orderStatus - orderid: 279 status: PreSubmitted filled 0.0 remaining 40.0 lastFillPrice 0.0 openOrder id: 280 ES FUT @ GLOBEX : SELL LMT 40.0 PreSubmitted orderStatus - orderid: 280 status: PreSubmitted filled 0.0 remaining 40.0 lastFillPrice 0.0 The next valid order id is: 281 – Nikolaos Trader Jul 22 '20 at 16:53

1 Answers1

0

Problem was there was a lot size limit and 40 exceeded it.