Ib Api

Discussion in 'Automated Trading' started by nitro, Oct 15, 2006.

  1. nitro

    nitro

    Does anyone know if axTws1_tickPrice and axTws1_tickSize messages in Interactive Brokers API are blocking or nonblocking (asynchronous)?

    Thanks.

    nitro
     
  2. ActiveX events are synchronous by default. I don't know for sure, but would wonder why IB would go out of their way to make that call async.
     
  3. nitro

    nitro

    Thanks for the response. What about the sockets version? Do you know if it is async?

    Also, do you know about the relative performance of each when used from C#? I found this, but I don't see any documentation:

    http://finance.groups.yahoo.com/group/TWSAPI/

    I guess I gotta look at the source...

    nitro
     
  4. vikana

    vikana Moderator

    I'm not sure i agree with the answer above. I use Java, and there everything in async: meaning that the methods get called entirely at the discretion of TWS and I have to deal with the events whatever order they come.
     
  5. Why does it matter if it is blocking or nonblocking? Whether it blocks affects the caller, but does not directly affect your client program. It would matter if the TWS ActiveX control runs in the same thread as your main app. In that case your user interface would become unresponsive while you were processing an event from TWS. Is this what you see happening?
     
  6. nitro

    nitro

    Perhaps there is some confusion, but if in fact the call to axTws1_tickPrice or axTws1_tickSize do not happen on their own threads, then it is imperative that you return to the datafeed dispatcher as soon as possible.

    If the call is non-blocking (on it's own thread), then doing something like this is ok:

    in pseudocode

    Code:
    axTws1_tickPrice(object sender, AxTWSLib._DTwsEvents_tickPriceEvent e)
    {
       doSomeComplexCalculation();
    }
    
    if axTws1_tickPrice does block (is running on the APIs main data gathering thread), you better do something like this:

    Code:
    HandleComplexCalc(Params p)
    {
       doSomeComplexCalculation();
    }
    
    axTws1_tickPrice(object sender, AxTWSLib._DTwsEvents_tickPriceEvent e)
    { 					      
       ThreadPool.QueueUserWorkItem(this.HandleComplexCalc, params);
    }
    
    The idea is to return to IBs data handling logic as soon as possible so that you do not drop quotes. That means getting your own code on it's own thread ASAP if the IB API doesn't launch it there to begin with.

    I am 90% sure that it is blocking, as data feed handlers have to serialize data.

    nitro
     
  7. dpeck

    dpeck

    I am using c# based on their C++ sample. The API will return data serially so yes you do want to get it onto your own thread.

    As for performance, I have a strategy that randomly buys and sells with a two tick stop and profit target. In the paper trading account I have traded this strategy against 21 futures contracts averaging 2,000-2,200 trades an hour while debugging. For comparison I have a Dell Precision 670 with a 3GHz Zeon, single core, 1 GB RAM and RAID 1.


    Doug