Get Contract

Contract Overview

A contract refers to the trading object or underlying asset (e.g., a stock or an option). Contracts are standardized by exchanges. For example, to purchase Tiger Brokers stock, you can uniquely identify it using the symbol TIGR and market information (i.e., market='US', US market). With contract information, we can uniquely determine an underlying asset when placing orders or fetching market data. Common contracts include stock contracts, option contracts, and futures contracts.

Most contracts (such as stocks, CFDs, indices, or forex) can be uniquely identified by the following four basic properties:

  • Symbol: US and UK stock symbols are typically alphabetic, while HK and A-share symbols are numeric. For example, Tiger Brokers' symbol is TIGR.
  • Security Type (sec_type): Common types include STK (Stock), OPT (Option), FUT (Futures), CASH (Forex). For example, Tiger Brokers stock has sec_type STK.
  • Currency: Common currencies include USD (US Dollar) and HKD (Hong Kong Dollar).
  • Exchange: Generally not used for STK contracts as orders are auto-routed. Futures contracts typically require the exchange field.

get_contract Get Single Contract Info

value TradeClient::get_contract(utility::string_t symbol, utility::string_t sec_type, utility::string_t currency, utility::string_t exchange, time_t expiry, utility::string_t strike, utility::string_t right)

value TradeClient::get_contract(utility::string_t symbol, SecType sec_type, Currency currency, utility::string_t exchange, time_t expiry, utility::string_t strike, Right right)

Description

Query single contract information required for trading. This method provides both string and enum overloaded versions.

Parameters (String Version)

ParameterTypeRequiredDescription
symbolutility::string_tYesStock symbol, e.g., U("AAPL")
sec_typeutility::string_tYesSecurity type, e.g., U("STK"), U("OPT"), U("FUT")
currencyutility::string_tNoCurrency, e.g., U("USD"), U("HKD")
exchangeutility::string_tNoExchange, e.g., U("CBOE")
expirytime_tNoContract expiry timestamp (milliseconds), default -1
strikeutility::string_tNoStrike price (for options)
rightutility::string_tNoPut/Call (for options), U("PUT") or U("CALL")

Parameters (Enum Version)

ParameterTypeRequiredDescription
symbolutility::string_tYesStock symbol
sec_typeSecTypeNoSecurity type, default SecType::STK
currencyCurrencyNoCurrency, default Currency::ALL
exchangeutility::string_tNoExchange
expirytime_tNoContract expiry timestamp, default -1
strikeutility::string_tNoStrike price
rightRightNoOption direction, default Right::ALL

Return

web::json::value JSON object containing contract information

Object Properties

PropertyTypeDescription
identifierstringUnique identifier. For stocks, same as symbol; for options, a 21-character identifier
symbolstringStock symbol
sec_typestringSTK Stock / OPT Option / FUT Futures / WAR Warrant / IOPT CBBC, etc.
namestringContract name
currencystringCurrency, e.g., USD/HKD/CNH
exchangestringExchange
expirystringExpiry date (options and futures)
strikefloatStrike price (options)
multiplierfloatMultiplier, quantity per lot
put_callstringCALL or PUT (options)
marketstringMarket, e.g., US/HK/CN
min_tickfloatMinimum tick size
tickSizesarrayTick size price ranges
shortableboolWhether shortable
marginableboolWhether marginable
lot_sizefloatMinimum tradable quantity per transaction

Example

#include "tigerapi/trade_client.h"
#include "tigerapi/client_config.h"

using namespace TIGER_API;

ClientConfig config(false, U("/path/to/your/properties/"));
TradeClient trade_client(config);

// Stock contract
value contract = trade_client.get_contract(U("AAPL"), U("STK"));
ucout << contract.serialize() << std::endl;

// Futures contract
value fut_contract = trade_client.get_contract(U("ES2306"), U("FUT"));
ucout << fut_contract.serialize() << std::endl;

Return Example

{
  "contractId": 1916,
  "symbol": "AAPL",
  "currency": "USD",
  "secType": "STK",
  "exchange": null,
  "localSymbol": "AAPL",
  "multiplier": 1.0,
  "name": "Apple",
  "shortInitialMargin": 0.35,
  "shortMaintenanceMargin": 0.3,
  "longInitialMargin": 0.3,
  "longMaintenanceMargin": 0.25,
  "identifier": "AAPL",
  "primaryExchange": "NASDAQ",
  "market": "US",
  "tickSizes": [
    {"begin": "0", "end": "1", "type": "CLOSED", "tickSize": 0.0001},
    {"begin": "1", "end": "Infinity", "type": "OPEN", "tickSize": 0.01}
  ],
  "tradingClass": "AAPL",
  "status": 1,
  "marginable": true,
  "trade": true,
  "lotSize": 1.0
}

get_contracts Get Multiple Contract Info

value TradeClient::get_contracts(const value &symbols, utility::string_t sec_type, utility::string_t currency, utility::string_t exchange, time_t expiry, utility::string_t strike, utility::string_t right)

Description

Query multiple contract information, returned as a JSON array

Parameters

ParameterTypeRequiredDescription
symbolsvalueYesStock symbol array. Max 50 per request
sec_typeutility::string_tNoSecurity type, default U("STK")
currencyutility::string_tNoCurrency
exchangeutility::string_tNoExchange
expirytime_tNoContract expiry timestamp, default -1
strikeutility::string_tNoStrike price
rightutility::string_tNoOption direction

Return

web::json::value JSON array

Example

ClientConfig config(false, U("/path/to/your/properties/"));
TradeClient trade_client(config);

value symbols = value::array();
symbols[0] = value::string(U("AAPL"));
symbols[1] = value::string(U("TSLA"));

value contracts = trade_client.get_contracts(symbols, U("STK"));
ucout << contracts.serialize() << std::endl;

Local Contract Object Construction

The C++ SDK provides the ContractUtil utility class to build contract objects locally without making network requests.

Stock

#include "tigerapi/contract_util.h"

using namespace TIGER_API;

// US stock
Contract contract = ContractUtil::stock_contract(U("TIGR"), U("USD"));

// HK stock
Contract contract = ContractUtil::stock_contract(U("00700"), U("HKD"));

Option

#include "tigerapi/contract_util.h"

using namespace TIGER_API;

// Method 1: Using four elements
Contract contract = ContractUtil::option_contract(
    U("AAPL"),          // symbol
    U("20240621"),       // expiry
    U("190"),            // strike
    U("CALL"),           // right
    U("USD"),            // currency
    100                  // multiplier
);

// Method 2: Using OCC identifier
Contract contract = ContractUtil::option_contract(U("AAPL  240621C00190000"));

// Parse option identifier
auto [symbol, expiry, right, strike] = ContractUtil::extract_option_info(U("AAPL  240621C00190000"));

Futures

#include "tigerapi/contract_util.h"

using namespace TIGER_API;

// Using contract code
Contract contract = ContractUtil::future_contract(U("CL2312"), U("USD"));

// Using full parameters
Contract contract = ContractUtil::future_contract(
    U("CL"),             // symbol
    U("USD"),            // currency
    U("20231220"),       // expiry
    U("NYMEX"),          // exchange
    U("202312"),         // contract_month
    1000                 // multiplier
);

Contract Object

The C++ SDK Contract struct contains the following main properties:

PropertyTypeDescription
contract_idlongContract ID
symbolutility::string_tSymbol code
sec_typeutility::string_tSecurity type
currencyutility::string_tCurrency
exchangeutility::string_tExchange
marketutility::string_tMarket
expiryutility::string_tExpiry date
strikeutility::string_tStrike price
rightutility::string_tOption direction PUT/CALL
multiplierintMultiplier
contract_monthutility::string_tContract month (futures)
local_symbolutility::string_tLocal identifier
identifierutility::string_tUnique identifier

What’s Next