Get Contract

About 4 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


Option

Tiger Securities's API support 2 option contract format:

  • One is the four-factor approach, including symbol, expiry, strike, right.

  • The other is the standard OCC option contract format, fixed length of 21 bits. contains 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

get_contract Get a Contract

value get_contract(string symbol, SecType sec_type = SecType::STK, Currency currency = Currency::ALL, string exchange = "", long expiry = -1, double strike = 0, Right right = Right::ALL)

Description

Get the contract Object

Argument

ArgumentTypeDescription
symbolstrTicker symbol of the stock/equity, example: 'AAPL'
sec_typeSecurityTypeSecurtiy type, use constants defined in tigeropen.common.consts.SecurityType, example: SecurityType.STK
currencyCurrencyCurrencies, use constants defined in tigeropen.common.consts.Currency, example: Currency.USD
exchangestrExchange code. This argument is optional, example: 'CBOE'
expirystrOptions expiration date, format: 'yyyyMMdd', example: '220121'
strikefloatOptions strike price
put_callstr'PUT' / 'CALL' for options

Response

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

ArgumentTypeDescription
currencystrCurrency type
symbolstrTicker symbol of the asset
exchangestrThe code of the exchange in which the requested asset is traded
short_fee_ratefloatBorrow fee rate
shortableintMaximum quantity of shares that can be shorted currently
short_init_marginfloatCurrent marigin requirement for shorting
short_maintenance_marginfloatshort maintenance margin ratio
long_initial_marginfloatInitial margin requirement for taking a long position
long_maintenance_marginfloatMaintenance margin requirement for taking a long position

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

TradeClient.get_contracts(symbol, sec_type=SecurityType.STK, currency=None, exchange=None):

Description

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

Argument

ArgumentTypeDescription
symbolstrTicker symbol of the stock/equity, example: 'AAPL'. Maximum 50 per request
sec_typeSecurityTypeSecurtiy type, use constants defined in tigeropen.common.consts.SecurityType, example: SecurityType.STK
currencyCurrencyCurrencies, use constants defined in tigeropen.common.consts.Currency, example: Currency.USD
exchangestrExanche code. This argument is optional, example: 'CBOE'

Response

list

Each element of this list is a contract object (tigeropen.trade.domain.contract.Contract). Refer to Contract Object for details

ArgumentTypeDescription
currencystrCurrency type
symbolstrTicker symbol of the asset
exchangestrThe code of the exchange in which the requested asset is traded
short_fee_ratefloatBorrow fee rate
shortableintMaximum quantity of shares that can be shorted currently
short_marginfloaturrent marigin requirement for shorting
long_initial_marginfloatInitial margin requirement for taking a long position
long_maintenance_marginfloatMaintenance margin requirement for taking a long position

Example

Response

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

Argument

ArgumentTypeRequiredDescription
symbolsstrYessecurity code, only support one symbol now
sec_typeSecurityTypeYessecurity type support: (OPT/WAR/IOPT)
expirystrexpiry date str, format:yyyyMMdd, e.g. '20220929'
langstrNolanguage, support: zh_CN,zh_TW,en_US, default: en_US

Responselist

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

ArgumentTypeDescription
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("20230728"));
        ucout << U("quote contract: ") << res << endl;
    }

Response:

[23009/WAR/HKD, 12554/WAR/HKD, 12566/WAR/HKD, 12491/WAR/HKD, 12492/WAR/HKD, 11436/WAR/HKD, 11803/WAR/HKD, 11985/WAR/HKD, 11996/WAR/HKD, 28456/WAR/HKD, 28465/WAR/HKD, 29814/WAR/HKD, 27695/WAR/HKD, 13252/WAR/HKD, 25315/WAR/HKD, 13590/WAR/HKD]
Last update: