IB TWS+Excel DDE trade execution issues

Discussion in 'Automated Trading' started by travis, Nov 3, 2006.

  1. travis


    I have a few questions concerning trade executions going from Excel to IB's TWS platform (via DDE).

    As far as I know IB doesn't permit Excel to tell TWS to "close" a trade for example but can just say BUY or SELL, and not, more correctly "OPEN BUY", "CLOSE BUY", "OPEN SELL" and "CLOSE SELL".

    This has caused me a big loss when my system, due to some bug (that I am trying to find and solve), has tried closing a short position twice, by saying "buy" and correctly closing it, and then again "buy", and opening an unwanted long position, which stayed open all day, and caused me losing 100 points on the YM.

    First of all, obviously, I have to solve the bug that causes such repeated orders, but I would like to know if there are other precautions I can take.

    Is there a way for example to say "close trade", instead of having to just say each time "buy 1" or "sell 1"? This way if I closed a trade twice it would just give me error and do nothing. Much better than having it open a trade in the wrong direction.

    Do you have any suggestions on how to constantly monitor your position with the broker (in TWS) and make sure it matches your position on the excel workbook?

    There are several ways I am sure, and I have seen the account sheet on the sample IB workbook, but do you have advice on what the best method is? Thank you.
  2. bidask


    you need to show us how you have coded the triggers to buy
  3. Yes... I have to deal with same issues in my ATS hooked up to IB API.

    IB does not differentiate between a "sell" and a "short sell"...
    In terms of information you get through the API.

    You have to have entire sub-systems:

    (1) To manage your positions.. and keep your Blotter synched with IB.

    (2) To manage you orders... and keep it synched with IB.

    (3) To keep track of executions... which obviously changes #1.

    This is not trivial.

    We are talking 1000s of lines of code...
    And a lot of thought going into elegant, robust, and fast system design.
    By the time my ATS is pretty much done... it will be about 20,000 lines of VB6 code.
    (I have a degree and > 20 years experience... and this is the trickiest project I've ever developed for myself).

    IB does not make things easy.
    I have re-written parts of my code 3-4 times.

    In theory, you can do it with VBA with limitations...
    But VB6 or VB.NET that controls the Excel front-end is infinitely superior with no real limitations.

    Except for very specific questions... this is waaaaaaay beyond the scope of ET threads.
  4. The best way to look at it...
    Is that you are developing a complete REPLACEMENT for the IB TWS platform...
    But a custom platform that AUTOMATES the specific trading that you already do.

    If you cannot design and code a TWS equivalent from scratch...
    Then you cannot design and code a professional level ATS system.

    Many who try...
    End up with klunky, error-prone, and limited systems with questionable value.
  5. travis


    Thank you very much for the very detailed replies.

    I will try to simplify my problems and solutions as much as possible, because I don't have the knowledge required to write the powerful code and program you are talking about. I will keep you updated in case I come up with anything good (and simple) on this problem.