DDE speed with IB

Discussion in 'Trading Software' started by the_dude, Jan 17, 2002.

  1. [This was in another thread, but probably wasn't the best place for it since nobody answered :) ]


    I used the DDE link once about 2 months ago with ensign windows (out to excel pro 2000) to see if it really worked, which it did, but it seemed to be a little slow, i.e. the quotes would appear in ensign/esignal, but it would take 1/2 second or so for them to appear on the spreadsheet in excel. Was my experience indicative of the DDE link itself, or was the delay most likely introduced by ensign submitting the data to excel?

    Can someone who uses the DDE link with IB to submit orders please let me know if it is fast? I trade only volatile, pseudoliquid nasdaq stocks, so any slowdown between excel and TWS, whether it is due to the DDE link or simply computer-related (due to the extra processing involved in running excel) is unacceptable. My computer speed is no issue; it is fast.

    Thank you.

    PS - If DDE/excel are fast enough, does anyone know of a good source to quickly learn the VB code you need to create orders?
     
  2. BeenHere

    BeenHere

    I have been playing with the IB DDE for several weeks now. I find no appreciable delay between my VB app and TWS.

    I'm sure there are others on this forum who would be more qualified that I, but I can post the plain jane VB code to this thread if others wish, or I can send it to you in a PM.

    BH
     
  3. Jaba122

    Jaba122

    Been Here

    Could you please send me the code via PM? I will appreciate it very much

    Jaba.
     
  4. Thanks been here,

    You can either send it to me via PM or post it on the thread, whatever you'd like.

    -dude
     
  5. BeenHere

    BeenHere

    I have received numerous requests for the IB DDE order snippet. Here it is.

    I'm going to assume that you know VB and only need the code. Here is the snippet that will allow you to place and then cancel a generic buy limit order for CSCO for $18.00 from VB

    Place three labels on a form. Name one label "LblControl" one LblCancel and one "LblStatus".

    Place two command buttons on a form ("Order" and "Cancel")

    ########################
    In the click event of the Order button, place the following code.

    LblControl.LinkMode = 0

    LblControl.LinkTopic = YOUR_IB_USERNAME & "|ord"
    comment: the topic string will not need to be concatenated as shown...that was only done to separate the username variable for demonstration purposes.

    LblControl.LinkItem = "idXXX?place?BUY_100_CSCO_STK_BEST_LMT_18_"
    comment: the immediately previous string will be on the same VB editor line no matter how it appears here. XXX = any unique ID number not already in use (I keep my ID numbers in my own database so my app can reference them)

    LblControl.LinkMode = 1

    LblStatus.LinkMode = 0
    LblStatus.LinkTopic = = YOUR_IB_USERNAME & "|ord"
    LblStatus.LinkItem = "idXXX?status"
    LblStatus.LinkMode = 1

    ########################
    In the click event of the Cancel button, place the following code.

    LblCancel.LinkMode = 0
    LblCancel.LinkTopic = = YOUR_IB_USERNAME & "|ord"
    LblCancel.LinkItem = "idXXX?cancel"
    LblCancel.LinkMode = 1

    ########################

    With the above code, the Order and Cancel buttons will function for ONE round (XXX will need to be incremented for continued use)

    LblStatus will reflect the current state of the order ("submitted", "cancelled", etc).

    Of course for the above to work, TWS DDE will need to be enabled and the .DLL downloaded (downloading Excel spreadsheet will insure you have the DLL.) If you have a CSCO ticker up in TWS when you execute this, you will see the order appear and then cancel and disappear.
     
  6. One thing to consider is that Excel isn't exactly a speed demon. Excel doesn't multi-thread, so with lots of quotes coming in, Excel will likely get slow and unresponsive.

    I doubt it's an issue with 10 to 20 symbols, but I ran into usability limitations in Excel a DDE feed of more than 20 symbols.

    The issue is that DDE servers simply deletes data that isn't processed fast enough (by the client), so while it may appear that you can use DDE with lots of quotes, in reality it is likely that lots of data simply never makes it into Excel. Remember that DDE is a broadcast protocol, and does not guarantee delivery or confirm receipt.
     
  7. dozu888

    dozu888

    Appreciate your help BeenHere, do you have any code to receive quotes from the DDE server? Thanks much
     
  8. BeenHere

    BeenHere

    Yup...I'll collect them and post them in a bit.
     
  9. BeenHere

    BeenHere

    OK, here is a very generic snippet of code to get bid/ask/price/etc data for CSCO from IB TWS from VB. The following assumes that you know how to use VB. It also assumes that you read and understand my previous snippet as it relates to the username and idXXX issues.

    On a form, place six labels. Name them:

    LblControl
    LblBid
    LblBidSize
    LblAsk
    LblAskSize
    LblLast

    Place two command buttons on the form...one "Start" and one "Stop".

    ###################################
    In the click event of the "Start" button place the following code.

    LblControl.LinkMode = 0
    LblControl.LinkTopic = YOUR_IB_USERNAME & "|tik"
    LblControl.LinkItem = "idXXX?req?CSCO_STK_BEST"
    LblControl.LinkMode = 1

    LblBid.LinkMode = 0
    LblBid.LinkTopic = YOUR_IB_USERNAME & "|tik"
    LblBid.LinkItem = "idXXX?bid"
    LblBid.LinkMode = 1

    LblBidSize.LinkMode = 0
    LblBidSize.LinkTopic = YOUR_IB_USERNAME & "|tik"
    LblBidSize.LinkItem = "idXXX?bidSize"
    LblBidSize.LinkMode = 1

    LblAsk.LinkMode = 0
    LblAsk.LinkTopic = YOUR_IB_USERNAME & "|tik"
    LblAsk.LinkItem = "idXXX?ask"
    LblAsk.LinkMode = 1

    LblAskSize.LinkMode = 0
    LblAskSize.LinkTopic = YOUR_IB_USERNAME & "|tik"
    LblAskSize.LinkItem = "idXXX?askSize"
    LblAskSize.LinkMode = 1

    LblLast.LinkMode = 0
    LblLast.LinkTopic = YOUR_IB_USERNAME & "|tik"
    LblLast.LinkItem = "idXXX?last"
    LblLast.LinkMode = 1

    ###################################
    In the click event of the "Stop" button place the following code.

    LblControl.LinkMode = 2
    LblBid.LinkMode = 2
    LblBidSize.LinkMode = 2
    LblAsk.LinkMode = 2
    LblAskSize.LinkMode = 2
    LblLast.LinkMode = 2

    LblBid.Caption = ""
    LblBidSize.Caption = ""
    LblAsk.Caption = ""
    LblAskSize.Caption = ""
    LblLast.Caption = ""

    ##################################

    Pressing the Start button will cause a CSCO ticker to show up in IB. It will initiate a DDE link between TWS and the assigned labels and now their values will change with the IB values. Pressing the Stop button will end the process and cause the ticker line to disappear.

    BEWARE:
    It took a lot of whacking to figure out that the Object Linkmode value must be set to a value of 2 to end the DDE exchange. According to VB documentation you should be able to return it to a value of zero to accomplish this. While zero will often accomplish the task of ending the exchange and removing the ticker line, somehow the IB counter still thinks it's there and you will eventually hit the 40 ticker IB limit even if there are no tickers open. Returning the value to 2 when done and then to zero just before reinitiation and then to 1 when the Topic and Item are set (by above code does all this as written) will keep things running smoothly.

    Good luck.
     
  10. Jaba122

    Jaba122

    that's a bit off-topic but I need to ask it anyway. Is it possible to create (write) a completely different program in C/C++ and link it to IB TWS through DDE? Or it has to be Excel and Visual Basic affair? I have some experience with C/C++ programming, created a few nice utilities, etc, so this language would be much better for me. Thanx in advance

    Jaba
     
    #10     Jan 17, 2002