Get Contract

About 7 min

We refer to what is being traded in an order as a "contract". The specs of a specific contract are set by a exchange, and are used to identify a specific asset in global markets, across the exchanges. This information, and the information required to trade a certain contract, are embedded in the Contract object.

A typical contract object includes the following elements:

  • Symbol: The ticker symbol of the stock/equity. The symbol of most U.S stocks only contains letters, HK stocks and Chinese A-Shares uses numbers as symbols of stocks. For example, the symbol of Tiger Brokers (NASDAQ) is TIGR
  • Security type: Common Security types includes STK(Stocks), OPT(Options), FUT(Futures) and CASH(Forex). For example, the Security type of Tiger Brokers (NASDAQ) is TIGR
  • Exchange: The code of the exchange in which the requested asset is traded. Contracts with Security typ of STK does not require this data field, as the orders will be routed automatically to a designated exchange, However, for futures, this field is necessary

Most stocks, CFDs, indexes or Forexs can be identify by those four elements. However, some contracts like Futures and Options has more attributes in their corresponding contract objects

Here are a few common types of contracts and what elements they consist of.

Stock

Contract ContractUtil::stock_contract(const utility::string_t symbol, const utility::string_t currency,
                        const utility::string_t local_symbol, const utility::string_t exchange,
                        long contract_id) {
    return Contract(U("STK"), symbol, currency, local_symbol, exchange, contract_id);
}

Option

Tiger Securities API supports 2 options contract formats:

  • One is the four-factor approach (symbol, expiry, strike, right).
Contract ContractUtil::option_contract(
    const utility::string_t symbol, 
    const utility::string_t expiry, 
    const utility::string_t strike,
    const utility::string_t right,
    const utility::string_t currency, 
    long multiplier, 
    const utility::string_t local_symbol,
    long contract_id) 
{
    return Contract(
        U("OPT"), symbol, expiry, strike, right, 
        currency, multiplier, local_symbol, contract_id
    );
}
  • The other is the standard OCC option contract format, fixed length of 21 bits containing four parts:

    • The code of the relevant stock or ETP, e.g. (AAPL), is fixed at six characters, with the missing digits filled by spaces
    • Option expiration date, 6 digits, format: yymmdd
    • Option type,including P or C, for put or call
    • Option exercise price, the value of the price x 1000, fixed 8 digits, the first few digits are filled by 0

    options identifier

Contract ContractUtil::option_contract(
    const utility::string_t identifier, 
    long multiplier, 
    const utility::string_t currency) 
{
    utility::string_t symbol, expiry, right, strike;
    
    std::tie(symbol, expiry, right, strike) = ContractUtil::extract_option_info(identifier);

    if (!expiry.empty() && expiry.find('-') != utility::string_t::npos) {
        expiry.erase(std::remove(expiry.begin(), expiry.end(), '-'), expiry.end());
    }

    return Contract(U("OPT"), symbol, expiry, strike, right, currency, multiplier, U(""), 0);
}

get_contract Get a Contract

value get_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t currency = U(""), utility::string_t exchange = U(""), time_t expiry = -1, utility::string_t strike = U(""), utility::string_t right = U("")); value get_contract(utility::string_t symbol, SecType sec_type = SecType::STK, Currency currency = Currency::ALL, utility::string_t exchange = U(""), time_t expiry = -1, utility::string_t strike = U(""), Right right = Right::ALL);

Description

Get the contract Object

Parameters

ParameterTypeRequiredDescription
symbolutility::string_tYesTicker symbol of the stock/equity, example: 'AAPL'
sec_typeSecTypeNoSecurity type
default: SecType::STK
currencyCurrencyNoCurrencies of contract
default: Currency::ALL
exchangeutility::string_tNoExchange code. Example: 'CBOE'
expirytime_tNoOptions expiration date
default: -1
strikeutility::string_tNoOptions strike price
rightRightNo'PUT' / 'CALL' for options
default: Right::ALL

Response

Contract Object, Please see Objects for more information. Some attributes of this object are as follows

FieldTypeDescription
close_onlyboolWhether an asset or position can only be closed (sold or exited) and not opened (bought or entered)
currencyutility::string_tCurrency type,USD/HKD/CNH
identifierutility::string_tUnique Identifier: For stocks, the identifier is the same as the symbol. For options, it is a 21-character identifier, such as 'AAPL 220729C00150000'. For futures, it is the futures identifier
is_etfboolWhether it is an ETF
local_symbolutility::string_tIdentify Warrants and Callable Bull/Bear Contracts for Hong Kong Stocks (Global accounts only)
long_initial_marginfloatInitial margin for long positions
long_maintenance_marginfloatMaintenance margin for long positions
marginableboolEligible for margin trading
marketutility::string_tMarket
multiplierfloatContracts per lot
nameutility::string_tContract name
sec_typeutility::string_tSTK - Stock / OPT - Option / FUT - Futures / WAR - Warrant / IOPT - Callable Bull/Bear Contracts (CBBC)
short_fee_ratefloatShort selling fee rate
short_initial_marginfloatInitial margin ratio for short selling
short_maintenance_marginfloatMaintenance Margin Ratio for Short Selling (No value for Global account contracts)
short_marginfloatShort Selling Margin Ratio (Deprecated, use short_initial_margin)
shortableboolWhether short selling is allowed
shortable_countintRemaining amount in short-selling pool
statusutility::string_tContract status
symbolutility::string_tStock Code: For option contracts, the symbol corresponds to the underlying asset code
tickSizeslist<tickSize>Stock only, Minimum quoting unit price range, i.e., when the order price is within the begin and end range, it must meet the tickSize requirement
begin: left range of price, end: right range of price, type: TickSizeType, tickSize: minimum price unit
tradableboolWhether asset is tradable
trading_classutility::string_tContract Trading level name

Example

#include "tigerapi/trade_client.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"

using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;

class TestTradeClient {
public:
    static void test_get_contract(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_contract("AAPL");
        cout << "contract: " << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_contract(trade_client);
    }
};

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private kye xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";


    /**
     * Use TradeClient
     */
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);


    return 0;
}

Response

{
    "closeOnly": false,
    "currency": "USD",
    "identifier": "AAPL",
    "isEtf": false,
    "localSymbol": "AAPL",
    "longInitialMargin": 0.29999999999999999,
    "longMaintenanceMargin": 0.40000000000000002,
    "marginable": true,
    "market": "US",
    "multiplier": 1,
    "name": "Apple Inc",
    "secType": "STK",
    "shortFeeRate": 3.25,
    "shortInitialMargin": 0.40000000000000002,
    "shortMaintenanceMargin": 0.40000000000000002,
    "shortMargin": 0.40000000000000002,
    "shortable": 0,
    "shortableCount": 0,
    "status": 1,
    "symbol": "AAPL",
    "tickSizes": [
        {
            "begin": "0",
            "end": "1",
            "tickSize": 0.0001,
            "type": "CLOSED"
        },
        {
            "begin": "1",
            "end": "Infinity",
            "tickSize": 0.01,
            "type": "OPEN"
        }
    ],
    "tradeable": true,
    "tradingClass": "AAPL"
}

get_contracts Get Multiple Contracts

value get_contracts(const value &symbols, utility::string_t sec_type, utility::string_t currency = U(""), utility::string_t exchange = U(""), time_t expiry = -1, utility::string_t strike = U(""), utility::string_t right = U(""));

Description

Get multiple contract objects. The objects are returned as a list

Parameters

ParameterTypeRequiredDescription
symbolsutility::string_tYesTicker symbol of the stock/equity, example: 'AAPL'. Maximum 50 per request
sec_typeSecTypeYesSecurity type, example: SecType::STK
currencyCurrencyNoCurrencies, example: Currency::USD
exchangeutility::string_tNoExchange code, example: 'CBOE'
expirytime_tNoContract expiration date
strikeutility::string_tNoStrike price
rightutility::string_tNo'PUT' / 'CALL' / 'ALL'
Response

list

Each element of this list is a contract object (/include/tigerapi/model.h). Refer to Contract Object for details

FieldTypeDescription
close_onlyboolWhether an asset or position can only be closed (sold or exited) and not opened (bought or entered)
currencyutility::string_tCurrency type,USD/HKD/CNH
identifierutility::string_tUnique Identifier: For stocks, the identifier is the same as the symbol. For options, it is a 21-character identifier, such as 'AAPL 220729C00150000'. For futures, it is the futures identifier
is_etfboolWhether it is an ETF
local_symbolutility::string_tIdentify Warrants and Callable Bull/Bear Contracts for Hong Kong Stocks (Global accounts only)
long_initial_marginfloatInitial margin for long positions
long_maintenance_marginfloatMaintenance margin for long positions
marginableboolEligible for margin trading
marketutility::string_tMarket
multiplierfloatContracts per lot
nameutility::string_tContract name
sec_typeutility::string_tSTK - Stock / OPT - Option / FUT - Futures / WAR - Warrant / IOPT - Callable Bull/Bear Contracts (CBBC)
short_fee_ratefloatShort selling fee rate
short_initial_marginfloatInitial margin ratio for short selling
short_maintenance_marginfloatMaintenance Margin Ratio for Short Selling (No value for Global account contracts)
short_marginfloatShort Selling Margin Ratio (Deprecated, use short_initial_margin)
shortableboolWhether short selling is allowed
shortable_countintRemaining amount in short-selling pool
statusutility::string_tContract status
symbolutility::string_tStock Code: For option contracts, the symbol corresponds to the underlying asset code
tickSizeslist<tickSize>Stock only, Minimum quoting unit price range, i.e., when the order price is within the begin and end range, it must meet the tickSize requirement
begin: left range of price, end: right range of price, type: TickSizeType, tickSize: minimum price unit
tradableboolWhether asset is tradable
trading_classutility::string_tContract Trading level name

Example

#include "tigerapi/trade_client.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"

using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;

class TestTradeClient {
public:
    static void test_get_contracts(const std::shared_ptr<TradeClient>& trade_client) {
        value symbols = value::array();
        symbols[0] = value::string(U("AAPL"));
        symbols[1] = value::string(U("JD"));
        value res = trade_client->get_contracts(symbols, U("STK"));
        ucout << U("contracts: ") << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_contracts(trade_client);
    }
};

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private kye xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";


    /**
     * Use TradeClient
     */
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);


    return 0;
}

Response

[
  {
    "closeOnly":false,
    "contractId":1916,
    "currency":"USD",
    "identifier":"AAPL",
    "isEtf":false,
    "localSymbol":"AAPL",
    "lotSize":1,
    "market":"US",
    "multiplier":1,
    "name":"Apple",
    "secType":"STK",
    "status":1,
    "supportOvernightTrading":true, 
    "symbol":"AAPL",
    "tickSizes":
    [
      {
        "begin":"0",
        "end":"1",
        "tickSize":0.0001,
        "type":"CLOSED"
      },
      {
        "begin":"1",
        "end":"Infinity",
        "tickSize":0.01,
        "type":"OPEN"
      }
    ],
    "tradeable":true,
    "tradingClass":"AAPL"
  },
  {
    "closeOnly":false,
    "contractId":1722,
    "currency":"USD",
    "identifier":"JD",
    "isEtf":false,
    "localSymbol":"JD",
    "lotSize":1,
    "market":"US",
    "multiplier":1,
    "name":"JD.com",
    "secType":"STK",
    "status":1,
    "supportOvernightTrading":true,
    "symbol":"JD",
    "tickSizes":
    [
      {
        "begin":"0",
        "end":"1",
        "tickSize":0.0001,
        "type":"CLOSED"
      },
      {
        "begin":"1",
        "end":"Infinity",
        "tickSize":0.01,
        "type":"OPEN"
      }
    ],
    "tradeable":true,
    "tradingClass":"JD"
  }
]

Construct Contract Object Locally

Stocks:

Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));

Options

Contract contract = ContractUtil::option_contract(U("AAPL"), U("20230721"), U("185.0"), U("PUT"), U("USD"));
Contract contract = ContractUtil::option_contract(U("AAPL 230721C00185000"));

Futures

Contract contract = ContractUtil::future_contract(U("NG2308"), U("USD"));

get_quote_contract

value get_quote_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t expiry)

Parameters

ParameterTypeRequiredDescription
symbolutility::string_tYessecurity code
sec_typeSecTypeYessecurity type support: (OPT/WAR/IOPT)
expiryutility::string_tYesexpiry date str, format:yyyyMMdd, e.g. '20220929'

Responselist

Each item in the list is a contract object( refer to tigeropen.trade.domain.contract.Contract) Contract object.

ParameterTypeDescription
symbolstringsecurity code
namestringcontract name
exchangestringexchange code
marketstringtrading market
sec_typestringsecurity type
currencystringtrading currency
expirystringexpiry date str(OPT、WAR、IOPT、FUT),e.g. 20171117
rightstringoption right(OPT、WAR、IOPT), including: PUT/CALL
strikefloatstrike price
multiplierfloatmultiplier (OPT,WAR,IOPT,FUT)

Example:

    static void test_get_quote_contract(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_quote_contract(U("00700"), U("IOPT"), U("20250328"));
        ucout << U("quote contract: ") << res << endl;
    }

Response:

[
  {
    "currency":"HKD",
    "exchange":"SEHK",
    "expiry":"20250328",
    "market":"HK",
    "multiplier":5000,
    "name":"SG#TENCTRC2503A.C",
    "right":"CALL",
    "secType":"IOPT",
    "strike":"357.2",
    "symbol":"67069"
  },
  {
    "currency":"HKD",
    "exchange":"SEHK",
    "expiry":"20250328",
    "market":"HK",
    "multiplier":10000,
    "name":"MS#TENCTRC2503B.C",
    "right":"CALL",
    "secType":"IOPT",
    "strike":"356.2",
    "symbol":"67170"
  },
  {
    "currency":"HKD",
    "exchange":"SEHK",
    "expiry":"20250328",
    "market":"HK",
    "multiplier":5000,
    "name":"MS#TENCTRC2503A.C",
    "right":"CALL",
    "secType":"IOPT",
    "strike":"267.2",
    "symbol":"52228"
  }
]

Last update: