orderStatus()

This method is called whenever the status of an order changes. It is also fired after reconnecting to TWS if the client has any open orders.

void orderStatus(int orderId, String status, int filled, int remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, String whyHeld)

It is possible that orderStatus() may return duplicate messages. It is essential that you filter the message accordingly.

Parameter

Description

id

The order Id that was specified previously in the call to placeOrder()

status

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.

filled

Specifies the number of shares that have been executed.

remaining

Specifies the number of shares still outstanding.

avgFillPrice

The average price of the shares that have been executed. This parameter is valid only if the filled parameter value is greater than zero. Otherwise, the price parameter will be zero.

permId

The TWS id used to identify orders. Remains the same over TWS sessions.

parentId

The order ID of the parent order, used for bracket and auto trailing stop orders.

lastFilledPrice

The last price of the shares that have been executed. This parameter is valid only if the filled parameter value is greater than zero. Otherwise, the price parameter will be zero.

clientId

The ID of the client (or TWS) that placed the order. Note that TWS orders have a fixed clientId and orderId of 0 that distinguishes them from API orders.

whyHeld

This field is used to identify an order held when TWS is trying to locate shares for a short sell. The value used to indicate this is 'locate'.