• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Complex Syntax

Complex Syntax provides the most flexibility that it allows users to customize all formula strings individually, where each string only represent one single parameter. There is no rule for the sequence of the appearance of each parameter.

=RTD(ProgID, Server, String1, String2, String3...)


  • ProgID = "Tws.TwsRtdServerCtrl"
  • Server = "" (empty string)

For exmaple, the formula below will request the Ask Size for SPY@ARCA:

=RTD("Tws.TwsRtdServerCtrl",,"sym=SPY", "sec=STK", "exch=ARCA", "qt=AskSize")

The formula below will request the Bid price for SPY:

=RTD("Tws.TwsRtdServerCtrl",,"sym=ES", "sec=FUT", "exch=GLOBEX", "cur=USD", "exp=201712", "qt=Bid")

Complex Syntax Strings

See table below for a full list available Complex Syntax strings:

NameString SyntaxDescription
Contract ID"conid="The unique contract ID generated by IB. Can be found at TWS Contract Description .
Symbol"sym="The contract symbol.
SecurityType"sec="The type of security, e.g. 'STK', 'FUT' and so on.
LastTradeDateOrContractMonth"exp="Format 'YYYYMMDD' is used for defining the Last Trade Date, while format 'YYYYMM' is used for defining the Contract Month.
Strike"strike="The strike price for an option contract.
Right"right="'C' or 'P' for an option contract.
Multiplier"mult="The contract multiplier.
Exchange"exch="The exchange where to get market data from. For equities, 'SMART' means top data from all possible exchanges.
PrimaryExchange"prim="The primary exchange of the contract. It is mostly specified when an contract ambiguity occurs for equity symbols that are listed on multiple exchanges.
Currency"cur="The currency the contract is traded in.
LocalSymbol"loc="The local symbol of the contract. Note the Local Symbol is mostly used for futures and options, and is different from the Symbol.
TradingClass"tc="The trading class of the contract.
Combo"cmb="Combo contract has to be defined using Complex Syntax or Mixed Syntax. The syntax for defining the combo is:


,where combo legs are separated by ';' and individual leg parameters are separated by '#'. See more Spread Samples .
DeltaNeutralContract"und="Delta-Neutral Contract. The syntax for defining the delta-neutral contract is:


, where delta-neutral contract parameters are separated by '#'.
MktDataOptions"opt="Currently not supported.
GenericTickList"genticks="A comma separated Ids of available Generic Tick Types.
Topic"qt="Topic of market data request.
Host"host="Host IP address.
Port"port="Socket port.
ClientId"clientid="The client ID for socket connection. Note that the client ID is used for identify multiple simultaneous API connections to the same TWS. It was originally designed for API users who would like to manage their strategies separately from different API programs. Since the TWS RTD Server API is currently only supported for real-time market data, there is no need to use multiple client IDs.

Additional Info

See also: