Order Cancelation - IB API

Discussion in 'Automated Trading' started by Chronos.Phenomena, Oct 24, 2010.

  1. I'm looking at the page of error codes:


    There are two error codes which I use to identify un-succesful cancelation: 161 and 136.

    136 = This order cannot be cancelled.
    161 = Cancel attempted when order is not in a cancellable state. Order permId...

    there is also a generic one

    135 = Can't find order with ID

    The purpose of this is to roll back unwanted trade. For example.... if I wanted to cancel order... but in the meantime it was filled, I want to place opposite trade...

    how do you guys do this?
  2. pwa2


    after calling cancelOrder(...) you must wait for it to be acknowledged i.e. orderStatus(...) returns with status=="Cancelled" or perhaps status=="Filled" and go from there. Otherwise you will be assuming...

    The order status. Possible values include:

    · PendingSubmit - indicates that you have transmitted the order, but have not yet received confirmation that it has been accepted by the order destination. NOTE: This order status is not sent by TWS and should be explicitly set by the API developer when an order is submitted.

    · PendingCancel - indicates that you have sent a request to cancel the order but have not yet received cancel confirmation from the order destination. At this point, your order is not confirmed canceled. You may still receive an execution while your cancellation request is pending. NOTE: This order status is not sent by TWS and should be explicitly set by the API developer when an order is canceled.

    · PreSubmitted - indicates that a simulated order type has been accepted by the IB system and that this order has yet to be elected. The order is held in the IB system until the election criteria are met. At that time the order is transmitted to the order destination as specified .

    · Submitted - indicates that your order has been accepted at the order destination and is working.

    · Cancelled - indicates that the balance of your order has been confirmed canceled by the IB system. This could occur unexpectedly when IB or the destination has rejected your order.

    · Filled - indicates that the order has been completely filled.

    · Inactive - indicates that the order has been accepted by the system (simulated orders) or an exchange (native orders) but that currently the order is inactive due to system, exchange or other issues.
  3. I get the error message, but the question I have is what states are cancels permissable in? Only after the "Submitted" state? I take it you can't change your mind quickly and have a cancel in the pipe for an order that hasn't been switched to Submitted state?

    Chronos, everything I google ends up on your posts. :)