Get Contract

We refer to what is being traded in an order as a "contract". The specs of a specific contract are set by an 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 stock/equity. The symbol of most U.S stocks only contains letters, HK stocks and Chinese A-Shares use numbers as stock symbols. For example, the symbol for Tiger Brokers (NASDAQ) is TIGR
  • Security type: Common Security types includes STK (Stocks), OPT (Options).

Options have 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);
}

Options

Our 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, a 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 unused digits filled by spaces
    • Option expiration date, 6 digits, format: yymmdd
    • Option type, delineated with a 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
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 Single Contract Information

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 Appendix 1: 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'.
is_etfboolWhether it is an ETF
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
short_fee_ratefloatShort selling fee rate
short_initial_marginfloatInitial margin ratio for short selling
short_maintenance_marginfloatMaintenance Margin Ratio for Short Selling
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 Call

#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;
}

Example 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 Multiple Contract Information

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 Appendix 1: Objects for more 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'.
is_etfboolWhether it is an ETF
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
short_fee_ratefloatShort selling fee rate
short_initial_marginfloatInitial margin ratio for short selling
short_maintenance_marginfloatMaintenance Margin Ratio for Short Selling
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 Call

#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(true, U("tiger_openapi_config.properties"));
    /**
     * Use TradeClient
     */
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);
    
    return 0;
}

Example 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"));

Did this page help you?