contracts: The 'contract' Object

contractsR Documentation

The contract Object

Description

In InteractiveTradeR, a contract object is simply a named character vector or list whose elements correspond to one or more of the contract parameters described below. For example:

AMD US Stock
c(symbol = "AMD", secType = "STK", currency = "USD", exchange = "SMART"),

EUR - GBP currency pair
c(symbol = "EUR", secType = "CASH", currency = "GBP", exchange = "IDEALPRO"),

US T-bill, 2.25%, 31 March 2021
c(symbol= "912828C57", secType = "BOND", exchange = "SMART", currency = "USD") , and

E-mini S&P 500 Futures
c(symbol = "ES", secType = "FUT", exchange = "GLOBEX", currency = "USD", lastTradeDateOrContractMonth = "201903")

...are all valid contract objects.

conId and exchange are Special

If a contract object is un-named and has only a single element (length(contract) == 1 ), then InteractiveTradeR will treat the contract object as though it contained a conId .

If a contract object is un-named and contains exactly two elements (length(contract) == 2 ), then InteractiveTradeR will treat the contract object as though it contained a conId and an exchange (in any order).

Because a conId is the unique identifier of any contract in IB's system, this convention makes a few useful shortcuts possible in InteractiveTradeR:

Functions (except for place_order (), below) that accept a contract argument require only that the conId be specified . In other words, req_contract_details(8314) will return the contract details for IBM US Stock, whose conId = 8314 . This syntax is much simpler than having to pass in the full basic contract information: c(symbol = "IBM", secType = "STK", currency = "USD", exchange = "SMART") .

For place_order (), the contract object must also include an exchange. Because orders require the user to specify the exchange on which the order is to be placed, the command

place_order( 8314, c( action = "BUY", account = "DU1234567", orderType = "MKT", totalQuantity = 50 ) )

would not work to buy 50 shares of IBM because the exchange isn't specified. Instead, the trader would need to include an exchange; for example, the SMART exchange:

place_order( c(8314, "SMART"), c( action = "BUY", account = "DU1234567", orderType = "MKT", totalQuantity = 50 ) )

Basic Contract Definitions

The elements that may be used to create contract objects are defined below. Order of elements does not matter in a contract object.

  • conID <numeric>: Interactive Brokers' unique numeric identifier for a specified contract

  • symbol <chr>: The exchange symbol under which the asset is traded, e.g., "FB", "AAPL", "IBM"

  • secType <chr>: Abbreviation describing security's type:

    BAG BOND CASH CMDTY FOP FUND
    combo bond forex pair commodity futures option mutual fund
    FUT IND NEWS OPT STK WAR
    futures index news option stock or ETF warrant
  • lastTradeDateOrContractMonth For options & futures, the last trading day or contract month (as applicable), in YYYYMMDD and YYYYMM format, respectively.

  • strike <numeric>: Strike price of asset, if applicable.

  • right <chr>: If applicable, the "right" parameter of a contract, e.g. "C" (right to buy, for a call), "P" (right to sell, put).

  • multiplier <numeric>: The "lot size" of a contract, if applicable; e.g., an options contract for 100 shares of underlying.

  • exchange <chr>: Destination exchange; i.e., the exchange on which the contract is to be traded.

  • currency <chr>: 3-letter abbreviation of the currency in which the contract is traded, e.g. "USD", "HKD".

  • localSymbol <chr>: The symbol under which the contract is traded in its primary exchange.

  • primaryExchange <chr>: Main exchange on which a contract is traded, e.g., "NASDAQ", "NYSE".

  • tradingClass <chr>: Code that classifies an asset based on the manner in which it is traded. Stocks, for example, have tradingClass = "NMS" denoting the United States' National Market System for equities.

  • includeExpired <logical>: If TRUE, expired options contracts may be included in the output. Does not work for expired options or other financial instruments; e.g, delisted stocks.

  • SecIdType <chr>: Specifies the type of security ID provided in SecId, the next argument; for example, ISIN or CUSIP.

  • SecId <chr>: Gives the value of the security ID whose type you specified via SecIdType. For example, a contract object specifying IBM by ISIN would contain the elements SecIdType = "ISIN and SecId = "US4592001014".

  • comboLegsDescrip <chr>: short description of combo legs, if a combo contract is being defined.

  • comboLegs <tibble>: Defines the individual contract legs for placing a Combination Order. Each row in the tibble corresponds to a contract leg. Only those columns necessary to completely specify a combo leg's identity, exchange, and order weight need to be specified – not all columns are required. For example, the following comboLegs tibble is sufficient to place a 1:1 combo order for the two stocks identified by conId:

    conId ratio action exchange
    <numeric> <numeric> <character> <character>
    43645865 1 "BUY" "SMART"
    9408 1 "SELL" "SMART"

    comboLegs may have the following columns:

    • conId <numeric>: IB's unique identifier for the contract

    • ratio <numeric>: The contract's weight in the combo order in terms of relative number of contracts; e.g., in a combo order to buy 25

    • action <character>: "BUY" or "SELL".

    • exchange <character>: Specifies exchange on which the order is intended to be placed.

    • openClose <numeric>: Only necessary for institutional (non-retail) customers. If you don't know what that is, then you're probably a retail customer and don't need to worry about this. Only takes the values 1 2, or 3, to signify opening, closing, or unknown.

    • shortSaleSlot <numeric>: Only takes the values 1 or 2 specifying the short sale service as clearing broker or third party, respectively.

    • designatedLocation <character>: If shortSaleSlot == 2 (third party), specifies the third party to service the short.

    deltaNeutralContract <tibble>: Defines the individual contract legs for what IB considers a delta neutral contract. Each row in the tibble corresponds to an underlying contract, which may be STK or FUT, upon which derivative instruments are constructed. The tibble must have three columns:

    • conId: IB's conId for the contract

    • delta: The delta value for the underlying contract

    • price: Price of the underlying


JakeVestal/InteractiveTradeR documentation built on June 5, 2024, 2:21 p.m.