Is there a way to cancel every IB order automatically after 30 minutes?

Discussion in 'Interactive Brokers' started by Daal, Sep 22, 2016.

  1. Daal

    Daal

    Sometimes I forget live orders out and when I get filled, usually I dont want the fill any longer. But I also dont want to have to manually do this, this has to be done automatically, for everything except GTC orders
     
  2. sprstpd

    sprstpd

    I'm assuming these aren't API orders because if they are you can just cancel them with code. It might be possible to cancel open orders with the API, even if you didn't use the API to submit them, but I am not 100% sure of this.

    Or have a keyboard macro program fire off Alt+T + Alt+N + Alt+O (which cancels all open orders) to the TWS window after 30 minutes. Maybe use a program like "autoit" and then use a script that involves a timer:

    https://www.autoitscript.com/forum/topic/81919-setting-up-a-timer/
     
  3. 2rosy

    2rosy

    Code:
    class KillEmAll(EWrapper):
            def __init__(self):
                    self.connection = EClientSocket()
                  
            def reqAllOpenOrders(self):
                    self.connection.reqAllOpenOrders()
    
            def openOrder(self, orderId, contract, order, state):              
                    self.connection.cancelOrder(orderId)
    untested but call reqAllOpenOrders after 30 minutes and the results comeback in openOrder
     
  4. Gldr

    Gldr

    you can define the 'time in force' in the order ticket. This will end teh ticket after the mentioned end time. Use teh GTD setting
     
    JackRab likes this.
  5. Daal

    Daal

    Where on TWS do you insert this code? any way to make GTC orders an exception?
     
  6. That's python code calling the API. If you're not a programmer it won't mean anything to you.
    As far as making TWS do it without programming the best you can do is make everything day orders. At least they'll get canceled after market close.
     
  7. JackRab

    JackRab

    like GLDR says, "time in force" in the order ticket...
     
  8. Daal

    Daal

    I will have to manually do that for every order..
     
  9. Have you looked at OCA (One Cancels All) orders? You assign the related orders to an OCA group and if 1 fills the others are canceled immediately.