• C#
  • Java
  • VB
  • C++
  • Python
Contact us
DDE Socket Bridge API

The Dynamic Data Exchange protocol is a method of inter-process communication developed by Microsoft to establish communication between Windows applications running on the same computer. The DDE API is available for Windows computers to create a means of communication between Microsoft Excel and TWS or IB Gateway.

Interactive Brokers does not offer any programming assistance and therefore it is strongly advised to anyone willing to use any of the TWS DDE API to become familiar with the technologies involved such as the DDE protocol and VBA.

Beginning in API v975, a new DDE API is offered which connects to TWS via a DDE socket bridge that uses the open source Java - DDE interoperability library JDDE. The newer API has some advantages over the legacy DDE API:

  • Compatibility with either 32 or 64 bit TWS (The legacy DDE API is only compatible with 32 bit TWS)
  • Additional functionality matching other socket-based APIs, especially in regards to multiple account structures
  • Full range of market data tick types

The DDE socket bridge API is fully backwards compatible with spreadsheets created for the legacy DDE API.

Unlike in the legacy DDE API, the username to be used in Excel DDE spreadsheets is determined by the DDE server launched independently, and not by the username used in TWS. The default username is twsserver, but this can be changed in the runDdeSocketBridge.bat file. The folder C:\TWS API\samples\DdeSocketBridge included with the API for Windows v975+ installation contains the source code for the new DDE connections.


Requirements for the DDE Socket Bridge API

  • Windows OS
  • Microsoft Excel
  • TWS API v975 or higher installed to the C: drive
  • Excel must be set to the US convention for commas and periods. That is, commas denote thousands and periods denote decimals.

Steps to launch DDE server

  1. Launch TWS or IB Gateway

  2. If using TWS with the API, the socket-based connections must be enabled at: Global Configuration -> API -> Settings -> "Enable ActiveX and Socket Clients" Enable API connections

  3. Note the socket port setting at Global Configuration -> API -> Settings -> Socket Port. The default value for the DDESocketBridge is 7496.

  4. Navigate to C:\TWS API\samples\DdeSocketBridge. If you launch runDdeSocketBridge.bat directly it will default socket port 7496, Excel formula user twsserver.
    • The default socket port used by DdeSocketBridge of 7496 and/or the default username twsserver can be changed by modifying runDdeSocketBridge.bat as follows:

      java -Djava.library.path=. -jar DdeSocketBridge.jar -p{the socket port which has been setup in API settings} -s{TWS login user name or any other string}

  5. There should be a popup window that shows Connected! confirming that the DDESocketBridge has connected to TWS. If not check that the API is enabled and that the socket port is set correctly.

  6. An Excel spreadsheet can now connect to the DDE API if formulas are entered with the correct syntax. A good place to start is the Tutorial
    Note: the default username which should be used is twsserver.
    There is a new sample spreadsheet at: C:\TWS API\samples\Excel\newTwsDDE.xls

Note: Other programs running on the same computer which use DDE can interfere with the communication between Excel and TWS and cause Excel to 'hang' or 'freeze' after making the initial request. The only solution to this problem is to close other programs using DDE one-by-one to find the culprit. Programs which are known to cause this issue include Google Chrome, Microsoft OneNote, Skype and Adobe Creative Cloud.

The Legacy DDE API is described here: Legacy DDE API