0

I am currently developing a Java application for trading using Interactive Broker's API. I have encountered an issue and I am unsure what I am doing incorrectly or whether this is a bug in the API.

At this point I can currently submit my orders using the following call:

m_controller.placeOrModifyOrder( m_contract, m_order, new IOrderHandler() {

        @Override
        public void orderStatus(OrderStatus status, int filled, int remaining, double avgFillPrice, long permId, int parentId, double lastFillPrice, int clientId, String whyHeld) {
            /*dbgMsg(String.format("Status: %s - Filled: %d - Remaining: %d - Avg F px: %f - Permid: %d - Parentid: %d - Last Fill Px: %f - Client id: %d - WhyHeld: %d", 
                    status.toString(), 
                    filled, 
                    remaining,
                    avgFillPrice,
                    permId,
                    parentId,
                    lastFillPrice,
                    clientId,
                    whyHeld));*/

            System.out.println("Order Status");

        }

        @Override
        public void orderState(NewOrderState orderState) {
            m_controller.removeOrderHandler( this);
            System.out.println("Order state "+orderState.toString());

            // TODO Auto-generated method stub
            //dbgMsg(orderState.toString());
        }

        @Override
        public void handle(int errorCode, String errorMsg) {
            //dbgMsg(String.format("ORDER ERROR [%d]: %s", errorCode, errorMsg));
            System.out.println("Order Error: "+errorMsg);
        }
    });

The issue that I am encountering is that while the order is transmitted and filled on Trader Workstation through the API, I do not receive any updates for the order that has been created.

I have also verified that I am in fact receiving the order updates through the ILiveOrdersHandler which basically provides the status updates for all orders.

I do not know whether this is a programming issue on my part or an issue with the underlying API; I have also confirmed this behavior on the provided sample code from IB, by adding System.out.println() calls to the corresponding handler in their program.

Any help would be greatly appreciated.

autronix
  • 2,885
  • 2
  • 22
  • 28
  • what is orderStatus() overriding? It's supposed to be the method in the EWrapper interface. Note that some of the status changes are your responsibility to program - the 'pending' ones. – brian May 11 '15 at 19:54
  • OrderStatus is overriding the IOrderHandler interface definition in ApiController.java (lines 669 through 671), roughly in the same manner that a methedo with the same name is overriden in ILiveOrderHandler (lines 711 through 716). I can get the ILiveOrderHandler overrides to work and provide me with the order data with no problems; I encounter issues receiving data with IOrderHandler - my workaround has consisted in filtering the results of orderStatus from ILiveOrderHandler by order id in order to get a smiliar result. – autronix May 11 '15 at 20:41
  • oops, I forgot about that new ApiController. I just use the EWrapper. – brian May 11 '15 at 21:00

2 Answers2

0

Do you get a callback to orderState() ?

When you call

m_controller.removeOrderHandler(this);

you effectively remove your handler from ApiController's list of handlers, meaning that you won't get any more callbacks regarding this order-id.

If you check the source code you can see that ApiController callbacks your handler (since its associated with the order id) and after that all the live order handlers.

check out the orderStatus code for example:

    IOrderHandler handler = m_orderHandlers.get( orderId);
    if (handler != null) {
        handler.orderStatus( OrderStatus.valueOf( status), filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld);
    }

    for (ILiveOrderHandler liveOrderHandler : m_liveOrderHandlers) {
        liveOrderHandler.orderStatus(orderId, OrderStatus.valueOf( status), filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld);
    }
Peter Andersson
  • 1,947
  • 3
  • 28
  • 44
0

By deleting "m_controller.removeOrderHandler( this);" you effectively get a feedback from the callback function (EReader thread).

However, it seems for orders being filled right away (buying at the ask price, selling at the bid price) that the orderStatus method is ineffective since the order is not live anymore. Hence, one should also check the order status through the reqExecutions method for instance.

blueangel
  • 81
  • 4