Questions regarding IB API

Discussion in 'App Development' started by leonbrag215, Aug 19, 2017.

  1. Hi guys,

    I am a software engineer by trade, and currently building an automated trading platform on my spare time.

    And so I have recently joined IB and downloaded their 9.72 API samples.

    I have started inspecting the C# implementation, and I have to say it seems to be poorly written by today's standards.

    Instead of using a producer/consumer queue which is also available in the .Net framework (BlockingCollection<T>) they had implemented one by themselves with a Queue<T> and a low level locking mechanism.
    And thus they lock the queue every enqueue/dequeue which is wasteful compared to modern implementations.

    But this is actually beside the point, just an observation after a very quick dive into their code.

    What really concerns me is that every call to the actual server has to go through the Gateway or TWS.
    And so I am not sure how do they implement this logic internally since this is a blackbox essentially.

    I have several questions that I hope you guys could answer regarding the Gateway to IB servers communication:

    1. Does the gateway poll the IB server for updates if a market data stream is requested, or does the server push all updates for all requested stocks.

    2. If the data is polled what is the polling frequency?

    3. If the data is pushed, is there a push frequency as well (if for instance changes are aggregated and pushed every 0.5 seconds)?

    4. Pretty sure I know the answer to this but I need to make sure:
    Are all tick changes sent to the gateway?
    For instance if there were 100 prices changes in 0.5 seconds are all 100 changes sent to the gateway?

    5. This is a bit unrelated but if you guys also worked with TD Ameritrade API, is it also limited to 100 concurrent market streams (without extra fee)? and also how was working with their API in general?
     
  2. Pavel Koryakin

    Pavel Koryakin Vendor

    1. I think they push. No reason to implement polling. Even web solution uses websockets for last several years.
    2. I would vote for that they have some time slices. But from another point of view, the subscription limit is only 200 instruments, so even if they will send everything it won't be too much for any connection.
     
    leonbrag215 likes this.
  3. DaveV

    DaveV

    I have been using the IB API for 8 years, and it has never occurred to me to care how they work internally or whether they are using the latest programming standards or is their code laced with a million gotos. I have been writing code for 39 years; I even wrote part of the Nasdaq system, though I doubt that any code that I wrote still survives there.

    At this time in my life all I ask of an API is does it work, and what is the interface.

    To directly answer your questions:
    4) All tick changes are not sent to the gateway. It seems to be a time slice, though I have never measure the frequency. I also subscribe to NxCore and IQFeed, and about 60% of the time the IB API quote precedes the NxCore quote, and 90% of the time IB precedes IQFeed.

    The 100 concurrent market streams is only a minimum, and depends on your level of trading. The more you trade (i.e. equity executions), the more free concurrent streams you are allowed. Also, you can purchase more streams; if memory serves right, it is $30 per month per 100.
     
  4. That's a common complaint. But, as DaveV noted above, some of us have been using IB API for many years, and it works well.

    It's a server push, i.e. Exchange->IBServer->IBGateway->API->yourCode

    Yes, changes are aggregated. The push frequency depends on the instrument. For example, for the U.S. futures, it's about 3 to 4 updates per second.

    No, not all tick changes are sent to the gateway. The are aggregated.
     
    Last edited: Aug 19, 2017
    leonbrag215 likes this.
  5. InvBox

    InvBox

    Use socket level instead of C#. C# wrapper is a buggy and poor implemented.
     
    Pavel Koryakin likes this.
  6. Thanks for the assistance guys, it was really helpful.

    InvBox, is the socket level implementation available in their samples?
     
  7. InvBox

    InvBox

    leonbrag215 likes this.
  8. @leonbrag215 you might be able to get more information at the TWSAPI group at groups.io Your questions have been asked and discussed several times over there.
     
    leonbrag215 likes this.
  9. Thanks I will take a look
     
    #10     Aug 21, 2017