• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Basic Contracts

FX Pairs

  • Contract contract = new Contract();
    contract.Symbol = "EUR";
    contract.SecType = "CASH";
    contract.Currency = "GBP";
    contract.Exchange = "IDEALPRO";
  • Contract contract = new Contract();
    contract.symbol("EUR");
    contract.secType("CASH");
    contract.currency("GBP");
    contract.exchange("IDEALPRO");
  • Dim contract As Contract = New Contract
    contract.Symbol = "EUR"
    contract.SecType = "CASH"
    contract.Currency = "GBP"
    contract.Exchange = "IDEALPRO"
  • Contract contract;
    contract.symbol = "EUR";
    contract.secType = "CASH";
    contract.currency = "GBP";
    contract.exchange = "IDEALPRO";
  • 1  contract = Contract()
    2  contract.symbol = "EUR"
    3  contract.secType = "CASH"
    4  contract.currency = "GBP"
    5  contract.exchange = "IDEALPRO"

Stocks

  • Contract contract = new 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";
  • Contract contract = new Contract();
    contract.conid(46636665);
    contract.secType("STK");
    //contract.currency("USD");
    //In the API side, NASDAQ is always defined as ISLAND
    contract.exchange("SEHK");
  • Dim contract As Contract = New Contract
    contract.Symbol = "IBKR"
    contract.SecType = "STK"
    contract.Currency = "USD"
    '! In the API side, NASDAQ Is always defined as ISLAND for routing purposes
    contract.Exchange = "ISLAND"
  • Contract contract;
    contract.symbol = "IBKR";
    contract.secType = "STK";
    contract.currency = "USD";
    //In the API side, NASDAQ is always defined as ISLAND
    contract.exchange = "ISLAND";
  • 1  contract = Contract()
    2  contract.symbol = "IBKR"
    3  contract.secType = "STK"
    4  contract.currency = "USD"
    5  #In the API side, NASDAQ is always defined as ISLAND in the exchange field
    6  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:

  • 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";
  • 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");
  • Dim Contract As 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"
  • Contract contract;
    contract.symbol = "AAPL";
    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";
  • 1  contract = Contract()
    2  contract.symbol = "MSFT"
    3  contract.secType = "STK"
    4  contract.currency = "USD"
    5  contract.exchange = "SMART"
    6  #Specify the Primary Exchange attribute to avoid contract ambiguity
    7  #(there is an ambiguity because there is also a MSFT contract with primary exchange = "AEB")
    8  contract.primaryExchange = "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 TWS Global Configuration under API -> Settings. The component exchange separator syntax in TWS 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 IB's database are available in the API as of TWS 965+.

  • Contract contract = new Contract();
    contract.Symbol = "DAX";
    contract.SecType = "IND";
    contract.Currency = "EUR";
    contract.Exchange = "DTB";
  • Contract contract = new Contract();
    contract.symbol("DAX");
    contract.secType("IND");
    contract.currency("EUR");
    contract.exchange("DTB");
  • Dim contract As Contract = New Contract
    contract.Symbol = "DAX"
    contract.SecType = "IND"
    contract.Currency = "EUR"
    contract.Exchange = "DTB"
  • Contract contract;
    contract.symbol = "DAX";
    contract.secType = "IND";
    contract.currency = "EUR";
    contract.exchange = "DTB";
  • 1  contract = Contract()
    2  contract.symbol = "DAX"
    3  contract.secType = "IND"
    4  contract.currency = "EUR"
    5  contract.exchange = "DTB"

CFDs

  • Contract contract = new Contract();
    contract.Symbol = "IBDE30";
    contract.SecType = "CFD";
    contract.Currency = "EUR";
    contract.Exchange = "SMART";
  • Contract contract = new Contract();
    contract.symbol("IBDE30");
    contract.secType("CFD");
    contract.currency("EUR");
    contract.exchange("SMART");
  • Dim contract As Contract = New Contract
    contract.Symbol = "IBDE30"
    contract.SecType = "CFD"
    contract.Currency = "EUR"
    contract.Exchange = "SMART"
  • Contract contract;
    contract.symbol = "IBDE30";
    contract.secType = "CFD";
    contract.currency = "EUR";
    contract.exchange = "SMART";
  • 1  contract = Contract()
    2  contract.symbol = "IBDE30"
    3  contract.secType = "CFD"
    4  contract.currency = "EUR"
    5  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 includeExpired flag within the Contract class to True.

  • Contract contract = new Contract();
    contract.Symbol = "ES";
    contract.SecType = "FUT";
    contract.Exchange = "GLOBEX";
    contract.Currency = "USD";
    contract.LastTradeDateOrContractMonth = "201803";
  • Contract contract = new Contract();
    contract.symbol("ES");
    contract.secType("FUT");
    contract.currency("USD");
    contract.exchange("GLOBEX");
    contract.lastTradeDateOrContractMonth("201803");
  • Dim contract As Contract = New Contract
    contract.Symbol = "ES"
    contract.SecType = "FUT"
    contract.Exchange = "GLOBEX"
    contract.Currency = "USD"
    contract.LastTradeDateOrContractMonth = "201803"
  • Contract contract;
    contract.symbol = "ES";
    contract.secType = "FUT";
    contract.exchange = "GLOBEX";
    contract.currency = "USD";
    contract.lastTradeDateOrContractMonth = "201803";
  • 1  contract = Contract()
    2  contract.symbol = "ES"
    3  contract.secType = "FUT"
    4  contract.exchange = "GLOBEX"
    5  contract.currency = "USD"
    6  contract.lastTradeDateOrContractMonth = "201803"

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

  • Contract contract = new Contract();
    contract.SecType = "FUT";
    contract.Exchange = "GLOBEX";
    contract.Currency = "USD";
    contract.LocalSymbol = "ESU6";
  • Contract contract = new Contract();
    contract.localSymbol("ESU6");
    contract.secType("FUT");
    contract.currency("USD");
    contract.exchange("GLOBEX");
  • Dim contract As Contract = New Contract
    contract.SecType = "FUT"
    contract.Exchange = "GLOBEX"
    contract.Currency = "USD"
    contract.LocalSymbol = "ESU6"
  • Contract contract;
    contract.secType = "FUT";
    contract.exchange = "GLOBEX";
    contract.currency = "USD";
    contract.localSymbol = "ESZ6";
  • 1  contract = Contract()
    2  contract.secType = "FUT"
    3  contract.exchange = "GLOBEX"
    4  contract.currency = "USD"
    5  contract.localSymbol = "ESU6"

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:

  • Contract contract = new Contract();
    contract.Symbol = "DAX";
    contract.SecType = "FUT";
    contract.Exchange = "DTB";
    contract.Currency = "EUR";
    contract.LastTradeDateOrContractMonth = "201609";
    contract.Multiplier = "5";
  • Contract contract = new Contract();
    contract.symbol("DAX");
    contract.secType("FUT");
    contract.currency("EUR");
    contract.exchange("DTB");
    contract.lastTradeDateOrContractMonth("201609");
    contract.multiplier("5");
  • Dim contract As Contract = New Contract()
    contract.Symbol = "DAX"
    contract.SecType = "FUT"
    contract.Exchange = "DTB"
    contract.Currency = "EUR"
    contract.LastTradeDateOrContractMonth = "201609"
    contract.Multiplier = "5"
  • Contract contract;
    contract.symbol = "DAX";
    contract.secType = "FUT";
    contract.exchange = "DTB";
    contract.currency = "EUR";
    contract.lastTradeDateOrContractMonth = "201609";
    contract.multiplier = "5";
  • 1  contract = Contract()
    2  contract.symbol = "DAX"
    3  contract.secType = "FUT"
    4  contract.exchange = "DTB"
    5  contract.currency = "EUR"
    6  contract.lastTradeDateOrContractMonth = "201609"
    7  contract.multiplier = "5"

A project is under development to allow for continuous futures from the API to receive historical data, real time bars, or contract details (requires TWS v966+). Continuous futures cannot be used with real time data or to place orders. To request historical data with continuous futures it is recommended to use TWS Build 971 or higher.

  • Contract contract = new Contract();
    contract.Symbol = "ES";
    contract.SecType = "CONTFUT";
    contract.Exchange = "GLOBEX";
  • Contract contract = new Contract();
    contract.symbol("ES");
    contract.secType("CONTFUT");
    contract.exchange("GLOBEX");
  • Dim contract As Contract = New Contract()
    contract.Symbol = "ES"
    contract.SecType = "CONTFUT"
    contract.Exchange = "GLOBEX"
  • Contract contract;
    contract.symbol = "ES";
    contract.secType = "CONTFUT";
    contract.exchange = "GLOBEX";
  • 1  contract = Contract()
    2  contract.symbol = "ES"
    3  contract.secType = "CONTFUT"
    4  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.

  • Contract contract = new Contract();
    contract.Symbol = "ES";
    contract.SecType = "FUT+CONTFUT";
    contract.Exchange = "GLOBEX";
  • Contract contract = new Contract();
    contract.symbol("ES");
    contract.secType("FUT+CONTFUT");
    contract.exchange("GLOBEX");
  • Dim contract As Contract = New Contract()
    contract.Symbol = "ES"
    contract.SecType = "FUT+CONTFUT"
    contract.Exchange = "GLOBEX"
  • Contract contract;
    contract.symbol = "ES";
    contract.secType = "FUT+CONTFUT";
    contract.exchange = "GLOBEX";
  • 1  contract = Contract()
    2  contract.symbol = "ES"
    3  contract.secType = "FUT+CONTFUT"
    4  contract.exchange = "GLOBEX"

Options

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

  • Contract contract = new Contract();
    contract.Symbol = "GOOG";
    contract.SecType = "OPT";
    contract.Exchange = "BOX";
    contract.Currency = "USD";
    contract.LastTradeDateOrContractMonth = "20170120";
    contract.Strike = 615;
    contract.Right = "C";
    contract.Multiplier = "100";
  • 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");
  • Dim contract As Contract = New Contract
    contract.Symbol = "GOOG"
    contract.SecType = "OPT"
    contract.Exchange = "BOX"
    contract.Currency = "USD"
    contract.LastTradeDateOrContractMonth = "20170120"
    contract.Strike = 615
    contract.Right = "C"
    contract.Multiplier = "100"
  • Contract contract;
    contract.symbol = "GOOG";
    contract.secType = "OPT";
    contract.exchange = "BOX";
    contract.currency = "USD";
    contract.lastTradeDateOrContractMonth = "20170120";
    contract.strike = 615;
    contract.right = "C";
    contract.multiplier = "100";
  • 1  contract = Contract()
    2  contract.symbol = "GOOG"
    3  contract.secType = "OPT"
    4  contract.exchange = "BOX"
    5  contract.currency = "USD"
    6  contract.lastTradeDateOrContractMonth = "20170120"
    7  contract.strike = 615
    8  contract.right = "C"
    9  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:

  • Contract contract = new 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";
  • 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");
  • Dim contract As Contract = New 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"
  • 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";
  • 1  contract = Contract()
    2  contract.symbol = "SANT"
    3  contract.secType = "OPT"
    4  contract.exchange = "MEFFRV"
    5  contract.currency = "EUR"
    6  contract.lastTradeDateOrContractMonth = "20190621"
    7  contract.strike = 7.5
    8  contract.right = "C"
    9  contract.multiplier = "100"
    10  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.

  • 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";
  • 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");
  • Dim contract As 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"
  • 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";
  • 1  contract = Contract()
    2  #Watch out for the spaces within the local symbol!
    3  contract.localSymbol = "C DBK DEC 20 1600"
    4  contract.secType = "OPT"
    5  contract.exchange = "DTB"
    6  contract.currency = "EUR"

Futures Options

Futures options follow the same rules as conventional option contracts:

  • Contract contract = new Contract();
    contract.Symbol = "ES";
    contract.SecType = "FOP";
    contract.Exchange = "GLOBEX";
    contract.Currency = "USD";
    contract.LastTradeDateOrContractMonth = "20180316";
    contract.Strike = 2800;
    contract.Right = "C";
    contract.Multiplier = "50";
  • 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");
  • Dim contract As Contract = New Contract
    contract.Symbol = "ES"
    contract.SecType = "FOP"
    contract.Exchange = "GLOBEX"
    contract.Currency = "USD"
    contract.LastTradeDateOrContractMonth = "20180316"
    contract.Strike = 2800
    contract.Right = "C"
    contract.Multiplier = "50"
  • Contract contract;
    contract.symbol = "ES";
    contract.secType = "FOP";
    contract.exchange = "GLOBEX";
    contract.currency = "USD";
    contract.lastTradeDateOrContractMonth = "20180316";
    contract.strike = 2800;
    contract.right = "C";
    contract.multiplier = "50";
  • 1  contract = Contract()
    2  contract.symbol = "SPX"
    3  contract.secType = "FOP"
    4  contract.exchange = "GLOBEX"
    5  contract.currency = "USD"
    6  contract.lastTradeDateOrContractMonth = "20180315"
    7  contract.strike = 1025
    8  contract.right = "C"
    9  contract.multiplier = "250"

Bonds

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

  • Contract contract = new Contract();
    // enter CUSIP as symbol
    contract.Symbol = "912828C57";
    contract.SecType = "BOND";
    contract.Exchange = "SMART";
    contract.Currency = "USD";
  • Contract contract = new Contract();
    // enter CUSIP as symbol
    contract.symbol("912828C57");
    contract.secType("BOND");
    contract.exchange("SMART");
    contract.currency("USD");
  • Dim Contract As Contract = New Contract
    ' enter CUSIP as symbol
    contract.symbol= "912828C57"
    contract.secType = "BOND"
    contract.exchange = "SMART"
    contract.currency = "USD"
  • Contract contract;
    // enter CUSIP as symbol
    contract.symbol= "912828C57";
    contract.secType = "BOND";
    contract.exchange = "SMART";
    contract.currency = "USD";
  • 1  contract = Contract()
    2  # enter CUSIP as symbol
    3  contract.symbol= "912828C57"
    4  contract.secType = "BOND"
    5  contract.exchange = "SMART"
    6  contract.currency = "USD"

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

  • Contract contract = new Contract();
    contract.ConId = 285191782;
    contract.Exchange = "SMART";
  • Contract contract = new Contract();
    contract.conid(285191782);
    contract.exchange("SMART");
  • Dim Contract As Contract = New Contract
    Contract.ConId = 285191782
    Contract.exchange = "SMART"
  • Contract contract;
    contract.conId = 285191782;
    contract.exchange = "SMART";
  • 1  contract = Contract()
    2  contract.conId = 15960357
    3  contract.exchange = "SMART"

Mutual Funds

Mutual Fund orders are not currently supported from the API. Note: Mutual Funds cannot be traded in paper accounts, in TWS or the API.

  • Contract contract = new Contract();
    contract.Symbol = "VINIX";
    contract.SecType = "FUND";
    contract.Exchange = "FUNDSERV";
    contract.Currency = "USD";
  • Contract contract = new Contract();
    contract.symbol("VINIX");
    contract.secType("FUND");
    contract.exchange("FUNDSERV");
    contract.currency("USD");
  • Dim Contract As Contract = New Contract
    Contract.symbol = "VINIX"
    Contract.secType = "FUND"
    Contract.exchange = "FUNDSERV"
    Contract.currency = "USD"
  • Contract contract;
    contract.symbol = "VINIX";
    contract.secType = "FUND";
    contract.exchange = "FUNDSERV";
    contract.currency = "USD";
  • 1  contract = Contract()
    2  contract.symbol = "VINIX"
    3  contract.secType = "FUND"
    4  contract.exchange = "FUNDSERV"
    5  contract.currency = "USD"

Commodities

  • Contract contract = new Contract();
    contract.Symbol = "XAUUSD";
    contract.SecType = "CMDTY";
    contract.Exchange = "SMART";
    contract.Currency = "USD";
  • Contract contract = new Contract();
    contract.symbol("XAUUSD");
    contract.secType("CMDTY");
    contract.exchange("SMART");
    contract.currency("USD");
  • Dim Contract As Contract = New Contract
    Contract.symbol = "XAUUSD"
    Contract.secType = "CMDTY"
    Contract.exchange = "SMART"
    Contract.currency = "USD"
  • Contract contract;
    contract.symbol = "XAUUSD";
    contract.secType = "CMDTY";
    contract.exchange = "SMART";
    contract.currency = "USD";
  • 1  contract = Contract()
    2  contract.symbol = "XAUUSD"
    3  contract.secType = "CMDTY"
    4  contract.exchange = "SMART"
    5  contract.currency = "USD"

Dutch Warrants

Dutch Warrants (IOPTs) can be defined with the local symbol or contract ID (conid), but not the ISIN.

  • Contract contract = new Contract();
    contract.LocalSymbol = "B881G";
    contract.SecType = "IOPT";
    contract.Exchange = "SBF";
    contract.Currency = "EUR";
  • Contract contract = new Contract();
    contract.localSymbol("B881G");
    contract.secType("IOPT");
    contract.exchange("SBF");
    contract.currency("EUR");
  • Dim contract As Contract = New Contract()
    contract.LocalSymbol = "B881G"
    contract.SecType = "IOPT"
    contract.Exchange = "SBF"
    contract.Currency = "EUR"
  • Contract contract;
    contract.localSymbol = "B881G";
    contract.secType = "IOPT";
    contract.exchange = "SBF";
    contract.currency = "EUR";
  • 1  contract = Contract()
    2  contract.localSymbol = "B881G"
    3  contract.secType = "IOPT"
    4  contract.exchange = "SBF"
    5  contract.currency = "EUR"