Portfolio Account

tigerapi/model.h PortfolioAccount

Description

Account asset object, applicable to Prime/Paper accounts. Includes total assets, profit and loss, market value of holdings, cash, available funds, margin, leverage, and other related information.

Object Properties

FieldTypeDescription
accountutility::string_tcorresponding account id
update_timestamplongUpdate time, 13-digit timestamp in milliseconds
segmentsvector<Segment>Account information by trade type. The value is Segment object

Segment

tigerapi/model.h Segment

Description

Assets include the stock category, which corresponds to a segment.

Object Properties

FieldTypeDescription
categoryutility::string_tSecurities Category S: (Securities Stocks)
capabilityutility::string_tAccount Type, Margin: RegTMargin, Cash: Cash
currencyutility::string_tCurrency, such as USD, HKD
buying_powerdoublebuying power. Estimate how many more dollars you can buy in stock assets. The margin account has a maximum of four times the purchasing power of the funds (funds that are not used for margin) during the day. Up to twice the purchasing power overnight
cash_available_for_tradedoubleAmount of cash that can be traded in the current account
cash_available_for_withdrawaldoubleAmount of cash that can be withdrawn in the current account
cash_balancedoubleThe cash that can be traded, plus the cash that has been locked (such as stocks that have been purchased but not yet traded, and some other situations will also have locked cash)
equity_with_loandoubleEquity with loan value (including loan value assets). Securities Segment: cash value + stock value
excess_liquidationdoubleExcess liquidity, used to represent intraday risk value. Calculation method for securities segment: equity_with_loan - maintenance_margin_requirement.
gross_position_valuedoubleTotal value of securities: long stock value + short stock value + long option value + short option value. The above items are calculated as absolute values
init_margindoubleinitial margin requirement
leveragedoubleThe leverage multiplier currently used. When it is less than 1, it indicates that no leverage is used. When it is greater than 1, it indicates that leverage is used.
locked_fundsdoubleLocked funds
maintain_margindoubleMaintenance margin requirement
net_liquidationdoubleNet Liquidation Value
overnight_liquidationdoubleOvernight risk control value, when it is less than 0, account positions will be forced to liquidate, you need to pay attention to the risks
overnight_margindoubleOvernight margin requirement
realized_pldoubleRealized P&L
total_today_pldoubleP&L for today
unrealized_pldoublefloating profit and loss
unrealized_plby_cost_of_carrydoubleUnrealized profit and loss by cost of carry
currency_assetsvector<CurrencyAsset>Account asset information differentiated by transaction currency, is a dict with currency as key, and value as CurrencyAsset object

Currency Asset

tigerapi/model.h CurrencyAsset

Description

Assets by currency.

Object Properties

FieldTypeDescription
cash_available_for_tradedoubleThe amount of cash that can be traded in the current account
cash_balancedoubleCash that can be traded, plus the cash that has been locked (such as stocks that have been purchased but not yet traded, and some other situations will also have locked cash)
currencyutility::string_tCurrent currency
gross_position_valuedoublegross value
option_market_valuedoubleMarket value of the option
realized_pldoubleRealized profit and loss of the account
stock_market_valuedoubleThe market value of the stock
unrealized_pldoubleUnrealized profit and loss of the account

Position

tigerapi/model.h Position

Description

Account holding information. Including the contract object of the position, the number of positions, cost, profit and loss and other information.

Object Properties

FieldTypeDescription
accountutility::string_tThe corresponding account ID
contractContractContract object
positionlong longPosition quantity
average_costdoubleAverage cost with commission
market_valuedoubleMarket Cap
realized_pnldoubleRealized P&L
unrealized_pnldoubleFloating profit and loss
latest_pricedoubleMarket price
statusintStatus code
update_timestamptime_tTimestamp of update

Order

tigerapi/model.h Order

Order object. Querying an order will return this object, and the parameters for modifying an order also use this object.

Object Properties

FieldTypeDescription
contractContractContract object
accountutility::string_tThe account to which the order belongs
idunsigned long longGlobal order id
order_idlongThe account automatically increments the order number, which is obsolete
order_typeutility::string_tOrder type, 'MKT' market order/'LMT' limit order/'STP' stop order/'STP_LMT' stop limit order
actionutility::string_tTrade direction, 'BUY' / 'SELL'
total_quantitylong longOrder quantity
total_quantity_scalelongOrder quantity scale
For example, if total_quantity is 5 and total_quantity_scale is 1, then the actual order quantity is 5 * 10^-1 = 0.5
limit_pricedoubleLimit price
s_limit_priceutility::string_t
aux_pricedoubleIn stop order, it represents the price to trigger the stop order
percent_offsetdouble
time_in_forceutility::string_tValid period, valid within 'DAY'/valid until 'GTC' is revoked
outside_rthboolWhether to allow pre-market and post-market trading, exclusive to US stocks
adjust_limitdoublePrice adjustment range (default 0 means no adjustment, positive means upward adjustment, negative means downward adjustment), automatically adjust the input price to a legal price.
For example: 0.001 means upward adjustment and the adjustment range is not more than 0.1%; -0.001 means downward adjustment and the adjustment range is not more than 0.1%
user_markutility::string_t
statusOrderStatusEnumeration indicating order status
parent_idunsigned long longParent order id, currently only used for additional orders on App
open_timetime_tOrder time
reasonutility::string_tReason for a failed order
latest_timetime_tLatest transaction time
update_timetime_tOrder update time
filled_quantitylong longFilled quantity
filled_quantity_scalelongFilled quantity scale
avg_fill_pricedoubleAverage fill price including commission
realized_pnldoubleRealized Pnl
secret_keyutility::string_t
sub_idsweb::json::valueList of sub-order IDs for attached orders (this field will only have a value when attaching an order)
algo_strategyutility::string_t
commissiondoubleIncludes commission, stamp duty, securities regulatory fees, and other related charges
gstdoubleGoods and Service Tax

Build method:

Use SDK's order_util tool to generate: order_util only provides common parameters, if you need additional parameters, you can modify its attributes after generating the order object

OrderUtil::market_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity)

Parameters

ParameterTypeDescription
accountutility::string_tOrder account
contractContractContract object to trade
actionutility::string_ttrading action, 'BUY' / 'SELL'
quantitylongThe quantity of the order, which must be an integer greater than 0

Response

Order object

OrderUtil::limit_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
                       double limit_price)

Parameters

ParameterTypeDescription
accountutility::string_tOrder account
contractContractContract to trade
actionutility::string_ttrading action, 'BUY' / 'SELL'
quantitylongThe quantity of the order, which must be an integer greater than 0
limit_pricedoubleLimit price

Response

Order object

OrderUtil::stop_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
                      double aux_price)

Parameters

ParameterTypeDescription
accountutility::string_tOrder account
contractContractContract object to trade
actionutility::string_ttrading action, 'BUY' / 'SELL'
quantitylongThe quantity of the order, which must be an integer greater than 0
aux_pricedoubleThe price to trigger the stop order

Response

Order object

OrderUtil::stop_limit_order(const utility::string_t account, Contract &contract, const utility::string_t action, long quantity,
                     double limit_price, double aux_price)

Parameters

ParameterTypeDescription
accountutility::string_tOrder account
contractContractContract object to trade
actionutility::string_ttrading action, 'BUY' / 'SELL'
quantitylongThe quantity of the order, which must be an integer greater than 0
limit_pricedoubleLimit price
aux_pricedoubleThe price to trigger the stop order

Response

Order object


Contract object

tigerapi/model.h Contract

Description

A contract is a tradeable item (like a stock or options) whose terms are set by the exchange. For example, Wxy Holdings trades under the symbol WXY in the US market (market='US'). When purchasing options, other identification fields may be required. Through the contract information, we can uniquely determine a target when placing an order or obtaining market quotations. In the OpenAPI C++ SDK, contract information is stored through the tigerapi/model.h Contract object. The Contract object can be passed into the tool function to create an Order object.
Common contracts include stock contracts, options contracts etc. Most contracts include the following elements:

  • The subject code (symbol), generally the contract codes such as US stocks are English letters, and the contract codes such as Hong Kong stocks and A shares are numbers. For example, the Wxy Holdings trades under the symbol, WXY.
  • Contract type (security type), common contract types include: STK (stock), OPT (option). For example, the contract type of WXY is STK.
  • Currency type (currency), common currencies include USD (US dollar), HKD (Hong Kong dollar).
    The vast majority of stocks and indices can be uniquely identified by these four properties. Due to their nature, more complex contracts such as options require some additional information. Here are a few common types of contracts and what they consist of:

Stocks

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

Options

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

See below for specific fields and construction methods

Parameter

ParameterTypeDescription
symbolutility::string_tContract code
currencyCurrencyCurrency type
sec_typeSecTypeSecurities Type
exchangeutility::string_tExchange
local_symbolutility::string_tLocal symbol
expiryutility::string_tExpiration date (for options)
strikeutility::string_tStrike Price (for options)
rightutility::string_tOption right
multiplierintNumber per lot
contract_monthutility::string_tContract month, such as 202201, means January 2022
contract_idlongcontract id
identifierutility::string_tUnique identifier, the stock identifier is the same as the symbol, the option is a 21-digit identifier, such as: 'ABCD 220729C00150000'
marketutility::string_tMarket

Did this page help you?