- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies
Lesson 3 of 6
In this lesson, we’re going to define Excel DDE, run the DdeSocketBridge batch file, access market data using a blank spreadsheet and walk-through a sample DDE spreadsheet exploring syntax.
What is DDE?
The Dynamic Data Exchange (DDE) protocol is another method provided by Microsoft that allows inter-process communication between Windows applications.
For the purposes of IBKR, this allows communication between TWS and Excel using standard DDE control strings.
Differences between legacy DDE connection and new DDE socket bridge
Running the new socket bridge and new sample
This can be done by modifying the batch file: runDdeSocketBridge.bat.
Open runDdeSocketBridge.bat in Editor/Notepad and modify to have: echo off if not exist "DdeSocketBridge.jar" goto :error java -Djava.library.path=.srcmainresources -jar DdeSocketBridge.jar -myDDE -p7497 goto :end :error echo DdeSocketBridge.jar is not found :end
Lets start with a blank spreadsheet and subscribe to ticker symbol AMZN and request the bid, ask and last price.
As defined previously – make sure that the runDdeSocketBridge is running by double clicking on the .bat (batch) file.
Market Data retrieval requires at least two different DDE links:
The formula to start the request will need to provide TWS with enough information so that TWS can identify which instrument we are interested in.
I am going to specify the stock AMZN with this formula:
twsuser
The user name with which you logged into the TWS
requestId
The request unique identifier (any positive integer)
symbol
The contract symbol
sectype
The asset class of the contract
exchange
the listing exchange or venue we want to query the data from
currency
The contract currency
=Stwsserver|tik!'id2?req?AMZN_STK_SMART_USD_~/'
Now for the second request to receive the bid price:
twsuser
The user name used in the first request – twsserver
requestId
The request identifier used in the first request – 2
Tick type – bid price
Now – I’ll also request the ask and last price.
This is how you request market data from TWS using Excel DDE. Next, we’ll open a sample spreadsheet provided in the TWS API download which contains a variety of examples.
=Stwsserver|tik!id2?bid
Now let’s navigate to the samples folder to open the new sample DDE spreadsheet, NewTwsDde.xls.
As you can see, the sample spreadsheet/workbook consists of multiple tabs which for the different API functionalities.
In TWS you can right click on the instrument of interest, then go to “Financial Instrument Info”, then “Description”.
Functionality for the rest of the spreadsheet
There is a lot of functionality throughout in the Excel tabs and it would take some time to go through each and everyone one of them during this lesson.
We encourage you to review the corresponding documentation for each tab of interest on our github guide. For example, for the “historicalData” tab, and the “Account” tab.
How to port legacy DDE sheets and formulas
The new socket bridge is backwards compatible with legacy DDE Excel sheets and formulas. You only need to change the username in the DDE formulas to the socket bridge username, whether this is entered by a macro button like in the sample spreadsheets or directly in the formula bar.
=Ssample123|tik!'id1?req?EUR_CASH_IDEALPRO_USD_~/'
=Stwsserver|tik!'id1?req?EUR_CASH_IDEALPRO_USD_~/'
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!
The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Interactive Brokers, its affiliates, or its employees.
Throughout the lesson, please keep in mind that the examples discussed are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.
I am having trouble connecting the TWS to Excel, when I press start, in the Basic tick types it says server error validating the request, no security definition has been found for the request, and there is an incorrect generic tick list. Did I miss a step?
Hello, thank you for reaching out. It is possible to reset your presets in IBKR Desktop following these steps:
Log in to IBKR Desktop.
Click Portfolio
Click Settings> Trading. This will bring you to Trading Presets
Click your desired security.
Click Revert to Defaults
Resetting your presets will transfer across platforms. We hope this helps!
I should have asked my question here. =Stwsserver|tik!’id2?req?AMZN_STK_SMART_USD_~/’ establishes the link to the data, and the =Stwsserver|tik!id2?bid formulas in the page grab the bid, ask and last. This is great. What I want to be able to do is grab AMZN, STK, SMART and USD as fields on the page like B2, C2, D2 and E2. I’ll search your sample spreadsheet to see where I can find it. But breaking out of the quotes and using something like =Stwsserver|tik!’id2?req?’ & B2 & ‘_’ & C2 & ‘_’ & D2 & ‘_’ & E2 & ‘_~/’ didn’t work.
Hello Mark. Please create a web ticket for this inquiry; we have a category specifically for “API.” One of our API experts will be happy to guide you! https://spr.ly/IBKR_TicketCampus
We also have a user guide for the APIs (and other trading platforms) on our website: https://spr.ly/IBKR_UserGuideCampus