undefined

TWS RTD Server Samples

This page is provided as a demonstration of RTD formulas categorized by security type as well as syntax type. Make sure to get yourself familiar with the various available Syntaxs for RTD formula before looking into the samples.

Forex Pairs

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"EUR.USD/CASH", "Bid")

Comment: Forex Ticker is defined in format "CURRENCY1.CURRENCY2/CASH".

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=EUR","cur=USD", "exch=IDEALPRO", "sec=CASH", "qt=Bid")

Comment: For Complex Syntax, Forex Symbol is defined as the foreign currency, and the Currency is defined as the base currency.

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"EUR.USD/CASH", "Bid", "port=1234", "clientId=1")

Stocks

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"IBM")

Comment: Default values are used: Exchange = "SMART", Currency = "USD", Security Type = "STK", Topic = "Last".

=RTD("Tws.TwsRtdServerCtrl",,"IBM@ISLAND", "Bid")

Comment: Specifying the Exchange directly means requesting data from that exchange specifically.

=RTD("Tws.TwsRtdServerCtrl",,"BMO@SMART//////CAD", "Bid")

Comment: Currency = "CAD" is needed for BMO listed on TSE, but the rest of the fields can be left out as blank.

=RTD("Tws.TwsRtdServerCtrl",,"ABG.P@SMART//////EUR", "Close")

Comment: Stock symbols that contain a '.' are supported in Simple Syntax as well.

=RTD("Tws.TwsRtdServerCtrl",,"MSFT@SMART/ISLAND", "Ask")

Comment: For certain smart-routed stock contracts that have the same Symbol, Currency and Exchange, you would also need to specify the PrimaryExchange attribute to uniquely define the contract. This should be defined as the native exchange of a contract, and is good practice for all stocks.

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=IBM", "sec=STK", "exch=SMART", "cur=USD", "qt=Volume")

Comment: Generally speaking, using the Symbol, SecurityType="STK", Currency and Exchange is sufficient to define a stock.

=RTD("Tws.TwsRtdServerCtrl",,"sym=MSFT", "sec=STK", "exch=SMART", "cur=USD", "prim=ISLAND", "qt=Open")

Comment: Specifying the PrimaryExchange as a seprate string to resolve contract ambiguity.

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"MSFT@SMART", "prim=ISLAND", "qt=High", "paper")

Comment: Use the pre-defined string "paper" to connect to the default port 7497 for paper TWS sessions.

Indexes

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"SPX@CBOE//IND", "Last")

Comment: Default Currency = "USD" is used.

=RTD("Tws.TwsRtdServerCtrl",,"DAX@DTB//IND////EUR", "Last")

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=INDU","cur=USD", "exch=NYSE", "sec=IND", "qt=Close")

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"DAX@DTB//IND", "cur=EUR", "qt=Last", "host=1.2.3.4")

CFDs

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"IBDE30@SMART//CFD////EUR", "Bid")

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=IBDE30","cur=EUR", "exch=SMART", "sec=CFD", "qt=ASK")

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"IBDE30@SMART//CFD", "cur=EUR", "Bid", "gw")

Comment: Use the pre-defined string "gw" to connect to the default port 4001 for live IB Gateway sessions.

[!NOTE] Only Index CFD data can be directly queried via the API, but not equity CFD. Please directly request data for the underlying equity if you need data for an equity CFD contract.*

Futures

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"ES@GLOBEX//FUT/201712///USD", "Bid")

Comment: Use underlying Symbol and LastTradeDateOrContractMonth to define futures contract.

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"loc=ESZ7","cur=USD", "exch=GLOBEX", "sec=FUT", "qt=Ask")

Comment: The LastTradeDateOrContractMonth and underlying Symbol can be replaced with the contract's own symbol, also known as LocalSymbol (named as Symbol within the TWS' Contract Description dialog). Local Symbol is not available in Simple Syntax.

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"DAX@DTB//FUT/201706///EUR", "mult=5", "Low")

Comment: For futures that have multiplier Multipliers (e.g. DAX has 5 and 25), Simple Syntax is not adequate to define the contract uniquely. Mixed Syntax can help to add addition specification for the Multiplier.

Options

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"GOOG@SMART//OPT/20170421/C/835/USD", "Bid")

Comment: Use Symbol, LastTradeDateOrContractMonth, Right and Strike to define options contract.

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"loc=C DBK DEC 20 1600", "cur=EUR", "exch=DTB", "sec=OPT", "qt=Close")

Comment: Use LocalSymbol to define options contract.

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"SANT@MEFFRV//OPT/20190621/C/7.5/EUR", "mult=100", "tc=SANEU", "Close")

Comment: For options that have multiplier Multipliers or TradingClasses, Simple Syntax is not adequate to define the contract uniquely. Mixed Syntax can help to add addition specifications for multiplier and TradingClass properly.

Futures Options

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"ES@GLOBEX//FOP/20180316/C/1000/USD", "Close")

Comment: Futures Options follow the same rule as conventional option contracts.

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"loc=ESH8 C1000", "cur=USD", "exch=GLOBEX", "sec=FOP", "qt=Close")

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"ES@GLOBEX//FOP/20180316/C/1000/USD", "mult=50", "tc=ES", "Close")

Bonds

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"912828C57@SMART//BOND", "Bid")

Comment: Bonds can be specified by defining the Symbol as the CUSIP. Currency = "USD" is used as default here.

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=912828C57","cur=USD", "exch=SMART", "sec=BOND", "qt=Bid")
=RTD("Tws.TwsRtdServerCtrl",,"conid=147554578", "exch=SMART", "qt=Ask")

Comment: Bonds can also be defined with the ConId and Exchange as with any security type.

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"912828C57@SMART, "sec=BOND", "Bid", "gwpaper")

Comment: Use the pre-defined string "gwpaper" to connect to the default port 4002 for paper IB Gateway sessions.

Mutual Funds

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"VINIX@FUNDSERV//FUND", "Close")

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=VINIX","cur=USD", "exch=FUNDSERV", "sec=FUND", "qt=Close")

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"VINIX@FUNDSERV//FUND", "Bid", "host=1.2.3.4", "port=1234", "clientId=1")

Commodities

Simple Syntax

=RTD("Tws.TwsRtdServerCtrl",,"XAUUSD@SMART//CMDTY", "Bid")

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=XAUUSD","cur=USD", "exch=SMART", "sec=CMDTY", "qt=Ask")

Mixed Syntax

=RTD("Tws.TwsRtdServerCtrl",,"XAUUSD@SMART//CMDTY", "Last", "port=1234", "clientId=1")

Spreads

Spread contracts, also known as combos or combinations, combine two or more instruments. To define a combination contract it is required to know the Contract ID of the combo legs. The ConId can be easily found in the Contract Description page in TWS. The spread contract's symbol can be either the symbol of one of the contract legs or, for two-legged combinations the symbols of both legs separated by a comma as shown in the examples below.

Simple Syntax is not sufficient to define spread contracts. You need to use either Complex Syntax or Mixed Syntax . As a reminder, here is the string formula for defining the Combo Legs:

"cmb=###;###;"

Stock Spread

Buy 1 IBKR@SMART + Sell 1 MCD@SMART:

Complex Syntax

=RTD("Tws.TwsRtdServerCtrl",,"sym=IBKR,MCD", "exch=SMART", "cur=USD", "sec=BAG", "cmb=43645865#1#BUY#SMART;9408#1#SELL#SMART;", "Bid")

Mixed Syntax

=RTD("tws.twsrtdserverctrl",,"IBKR,MCD@SMART//BAG////USD", "cmb=43645865#1#BUY#SMART;9408#1#SELL#SMART;", "Bid")

[!NOTE] EFPs are simply defined as a bag contract of stock and corresponding SSF with a ratio of 100:1.*

Futures Spread

Buy 1 VXJ7@CFE + Sell 1 VXK7@CFE:

Complex Syntax

=RTD("tws.twsrtdserverctrl",,"sym=VIX", "exch=CFE", "cur=USD", "sec=BAG", "cmb=249139906#1#BUY#CFE;252623425#1#SELL#CFE;", "Bid")

Mixed Syntax

=RTD("tws.twsrtdserverctrl",,"VIX@CFE//BAG////USD", "cmb=249139906#1#BUY#CFE;252623425#1#SELL#CFE;", "Bid")

Options Spread

Buy 1 DBK May19'17 15 CALL @DTB + Sell 1 DBK May19'17 16 CALL @DTB:

Complex Syntax

=RTD("tws.twsrtdserverctrl",,"sym=DBK", "exch=DTB", "cur=EUR", "sec=BAG", "cmb=270579950#1#BUY#DTB;270579957#1#SELL#DTB;", "Bid")

Mixed Syntax

=RTD("tws.twsrtdserverctrl",,"DBK@DTB//BAG////EUR", "cmb=270579950#1#BUY#DTB;270579957#1#SELL#DTB;", "Bid")

Inter-Commodity Futures Spread

For Inter-Commodity futures, the 'Local Symbol' field in TWS is used for the 'Symbol' field in the TWS Contract Description.

Buy 1 CL May'17 @NYMEX + Sell 1 BZ Jun'17 @NYMEX:

Complex Syntax

=RTD("tws.twsrtdserverctrl",,"sym=CL.BZ", "exch=NYMEX", "cur=USD", "sec=BAG", "cmb=55977404#1#BUY#NYMEX;55807026#1#SELL#NYMEX;", "Bid")

Mixed Syntax

=RTD("tws.twsrtdserverctrl",,"CL.BZ@NYMEX//BAG////USD", "cmb=55977404#1#BUY#NYMEX;55807026#1#SELL#NYMEX;", "Bid")

[!NOTE] Please be mindful of the fact that Inter-commodity Futures contracts are spread contracts offered by the exchange directly, and the contract definition is different from regular combo contracts. Please make sure all the contract attributes are specified in accordance with TWS Contract Description page.

Sample Spreadsheet

A sample RTD spreadsheet is provided within the API installation directory. By default, you will be able to find it under C:\TWS API\samples\ExcelTwsRtdServer.xls. There's also a Simple RTD Sheet available for download from our LYNX Quick Guide to Excel RTD