pythontwsib-api

How to automatically cancel an order if it is not filled after a minute?


I want to automatically cancel orders in IBKR's IB API if they are not filled after a minute. They are parent orders, so I can't just use cancelOrder after sleeping for 60 seconds or the child order will also be cancelled.


Solution

  • You can add a time in force condition when the order is placed.

    See https://interactivebrokers.github.io/tws-api/order_conditions.html

    and Interactive Brokers time-in-force order through python api

    order = Order()
    order.goodTillDate = "20200923 15:13:20 EST"
    order.tif = "GTD"