undefined

Basic Contracts

FX Pairs

** Python **

contract = Contract()
contract.symbol = "EUR"
contract.secType = "CASH"
contract.currency = "GBP"
contract.exchange = "IDEALPRO"

** Java **

Contract contract = new Contract();
contract.symbol("EUR");
contract.secType("CASH");
contract.currency("GBP");
contract.exchange("IDEALPRO");

Stocks

** Python **

contract = Contract()
contract.symbol = "IBKR"
contract.secType = "STK"
contract.currency = "USD"
#In the API side, NASDAQ is always defined as ISLAND in the exchange field
contract.exchange = "ISLAND"

** Java **

Contract contract = new Contract();
contract.symbol("IBKR");
contract.secType("STK");
contract.currency("USD");
//In the API side, NASDAQ is always defined as ISLAND
contract.exchange("ISLAND");

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

** Python **

contract = Contract()
contract.symbol = "MSFT"
contract.secType = "STK"
contract.currency = "USD"
contract.exchange = "SMART"
#Specify the Primary Exchange attribute to avoid contract ambiguity 
#(there is an ambiguity because there is also a MSFT contract with primary exchange = "AEB")
contract.primaryExchange = "ISLAND"

** Java **

Contract contract = new Contract();
contract.symbol("MSFT");
contract.secType("STK");
contract.currency("USD");
contract.exchange("SMART");
// Specify the Primary Exchange attribute to avoid contract ambiguity
// (there is an ambiguity because there is also a MSFT contract with primary exchange = "AEB")
contract.primaryExch("ISLAND");

For the purpose of requesting market data, the routing exchange and primary exchange can be specified in a single 'exchange' field if they are separated by a valid component exchange separator, for instance exchange = "SMART:ARCA". The default separators available are colon ":" and slash "/". Other component exchange separators can be defined using the field defined in LYNX Global Configuration under API -> Settings. The component exchange separator syntax in LYNX API versions prior to 971 can only be used to request market data and not to place orders.

Indexes

ISINs for indices which are available in LYNX's database are available in the API as of version 965+.

** Python **

contract = Contract()
contract.symbol = "DAX"
contract.secType = "IND"
contract.currency = "EUR"
contract.exchange = "DTB"

** Java **

Contract contract = new Contract();
contract.symbol("DAX");
contract.secType("IND");
contract.currency("EUR");
contract.exchange("DTB");

CFDs

** Python **

contract = Contract()
contract.symbol = "IBNL25"
contract.secType = "CFD"
contract.currency = "EUR"
contract.exchange = "SMART"

** Java **

Contract contract = new Contract();
contract.symbol("IBDE30");
contract.secType("CFD");
contract.currency("EUR");
contract.exchange("SMART");

Futures

A regular futures contract is commonly defined using an expiry and the symbol field defined as the symbol of the underlying. Historical data for futures is available up to 2 years after they expire by setting the include Expired flag within the Contract class to True.

** Python **

contract = Contract()
contract.symbol = "ES"
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "201909"

** Java **

Contract contract = new Contract();
contract.symbol("ES");
contract.secType("FUT");
contract.currency("USD");
contract.exchange("GLOBEX");
contract.lastTradeDateOrContractMonth("201803");

By contract the 'local symbol' field is for the future itself (the Symbol within the LYNX Contract Description dialog). Since a local symbol uniquely defines a future, an expiry is not necessary.

** Python **

contract = Contract()
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.localSymbol = "ESM9"

** Java **

Contract contract = new Contract();
contract.localSymbol("ESU6");
contract.secType("FUT");
contract.currency("USD");
contract.exchange("GLOBEX");

Occasionally, you can expect to have more than a single future contract for the same underlying with the same expiry. To rule out the ambiguity, the contract's multiplier can be given as shown below:

** Python **

contract = Contract()
contract.symbol = "DAX"
contract.secType = "FUT"
contract.exchange = "DTB"
contract.currency = "EUR"
contract.lastTradeDateOrContractMonth = "201906"
contract.multiplier = "5"

** Java **

Contract contract = new Contract();
contract.symbol("DAX");
contract.secType("FUT");
contract.currency("EUR");
contract.exchange("DTB");
contract.lastTradeDateOrContractMonth("201609");
contract.multiplier("5");

Continuous futures are available from the API with LYNX API v971 and higher. Continuous futures cannot be used with real time data or to place orders, but only for historical data.

** Python **

contract = Contract()
contract.symbol = "ES"
contract.secType = "CONTFUT"
contract.exchange = "GLOBEX"

** Java **

Contract contract = new Contract();
contract.symbol("ES");
contract.secType("CONTFUT");
contract.exchange("GLOBEX");

The security type "FUT+CONTFUT" can be used to request contract details about the futures and continuous futures on an underlying. This security type cannot be used with other functionality.

** Python **

contract = Contract()
contract.symbol = "ES"
contract.secType = "FUT+CONTFUT"
contract.exchange = "GLOBEX"

** Java **

Contract contract = new Contract();
contract.symbol("ES");
contract.secType("FUT+CONTFUT");
contract.exchange("GLOBEX");

Options

Options, like futures, also require an expiration date plus a strike and a multiplier:

** Python **

contract = Contract()
contract.symbol = "GOOG"
contract.secType = "OPT"
contract.exchange = "BOX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20190315"
contract.strike = 1180
contract.right = "C"
contract.multiplier = "100"

** Java **

Contract contract = new Contract();
contract.symbol("GOOG");
contract.secType("OPT");
contract.currency("USD");
contract.exchange("BOX");
contract.lastTradeDateOrContractMonth("20170120");
contract.right("C");
contract.strike(615);
contract.multiplier("100");

It is not unusual to find many option contracts with an almost identical description (i.e. underlying symbol, strike, last trading date, multiplier, etc.). Adding more details such as the trading class will help:

** Python **

contract = Contract()
contract.symbol = "SANT"
contract.secType = "OPT"
contract.exchange = "MEFFRV"
contract.currency = "EUR"
contract.lastTradeDateOrContractMonth = "20190621"
contract.strike = 7.5
contract.right = "C"
contract.multiplier = "100"
contract.tradingClass = "SANEU"

** Java **

Contract contract = new Contract();
contract.symbol("SANT");
contract.secType("OPT");
contract.currency("EUR");
contract.exchange("MEFFRV");
contract.lastTradeDateOrContractMonth("20190621");
contract.right("C");
contract.strike(7.5);
contract.multiplier("100");
contract.tradingClass("SANEU");

The OCC options symbol can be used to define an option contract in the API through the option's 'local symbol' field.

** Python **

contract = Contract()
#Watch out for the spaces within the local symbol!
contract.localSymbol = "C DBK  DEC 20  1600"
contract.secType = "OPT"
contract.exchange = "DTB"
contract.currency = "EUR"

** Java **

Contract contract = new Contract();
//Watch out for the spaces within the local symbol!
contract.localSymbol("C DBK  DEC 20  1600");
contract.secType("OPT");
contract.exchange("DTB");
contract.currency("EUR");

Futures Options

[!WARNING|style:flat|label:Important] In LYNX API versions prior to 972, if defining a futures option that has a price magnifier using the strike price, the strike will be the strike price displayed in TWS divided by the price magnifier. (e.g. displayed in dollars not cents for ZW) In TWS versions 972 and greater, the strike prices will be shown in TWS and the API the same way (without a price magnifier applied) For some futures options (e.g GE) it will be necessary to define a trading class, or use the local symbol, or conId.

** Python **

contract = Contract()
contract.symbol = "ES"
contract.secType = "FOP"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20190315"
contract.strike = 2900
contract.right = "C"
contract.multiplier = "50"

** Java **

Contract contract = new Contract();
contract.symbol("ES");
contract.secType("FOP");
contract.currency("USD");
contract.exchange("GLOBEX");
contract.lastTradeDateOrContractMonth("20180316");
contract.right("C");
contract.strike(2800);
contract.multiplier("50");

Bonds

Bonds can be specified by defining the symbol as the CUSIP or ISIN.

** Python **

contract = Contract()
# enter CUSIP as symbol
contract.symbol= "912828C57"
contract.secType = "BOND"
contract.exchange = "SMART"
contract.currency = "USD"

** Java **

Contract contract = new Contract();
// enter CUSIP as symbol
contract.symbol("912828C57");
contract.secType("BOND");
contract.exchange("SMART");
contract.currency("USD");

Bonds can also be defined with the conId and exchange as with any security type.

** Python **

contract = Contract()
contract.conId = 15960357
contract.exchange = "SMART"

** Java **

Contract contract = new Contract();
contract.conid(285191782);
contract.exchange("SMART");

Mutual Funds

Trading Mutual Funds is not currently fully-supported from the API. Note: Mutual Funds orders cannot be placed in paper accounts from any trading system.

** Python **

contract = Contract()
contract.symbol = "VINIX"
contract.secType = "FUND"
contract.exchange = "FUNDSERV"
contract.currency = "USD"

** Java **

Contract contract = new Contract();
contract.symbol("VINIX");
contract.secType("FUND");
contract.exchange("FUNDSERV");
contract.currency("USD");

Commodities

** Python **

contract = Contract()
contract.symbol = "XAUUSD"
contract.secType = "CMDTY"
contract.exchange = "SMART"
contract.currency = "USD"

** Java **

Contract contract = new Contract();
contract.symbol("XAUUSD");
contract.secType("CMDTY");
contract.exchange("SMART");
contract.currency("USD");

Dutch Warrants and Structured Products

To unambiguously define a Dutch Warrant or Structured Product (IOPTs) the conId or localSymbol field must be used.

  • It is important to note that if reqContractDetails is used with an incompletely-defined IOPT contract definition, that thousands of results can be returned and the API connection broken.

  • IOPT contract definitions will often change and it will be necessary to restart TWS or LYNX Gateway to download the new contract definition.

** Python **

  contract = Contract()
  contract.localSymbol = "B881G"
  contract.secType = "IOPT"
  contract.exchange = "SBF"
  contract.currency = "EUR"

** Java **

  Contract contract = new Contract();
  contract.localSymbol("B881G");
  contract.secType("IOPT");
  contract.exchange("SBF");
  contract.currency("EUR");