Assets and Positions

Get Accounts

value TradeClient::get_accounts()

Description

Returns all accounts associated with the current developer account.

Return

A web::json::value JSON array containing account information.

Example

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

using namespace TIGER_API;

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

value accounts = trade_client.get_accounts();
ucout << accounts.serialize() << std::endl;

Response Example

{
  "code": 0,
  "message": "success",
  "timestamp": 1785528000000,
  "data": [
    {
      "account": "DU12345678",
      "capability": "RegTMargin",
      "status": "Active"
    }
  ]
}

Get Account Assets

value TradeClient::get_asset(utility::string_t account = U(""), const value &sub_accounts = value::array(), bool segment = false, bool market_value = false)

Description

Returns asset information for a standard, global, or paper trading account.

Parameters

ParameterTypeRequiredDescription
accountutility::string_tNoAccount ID; uses the configured account if omitted
sub_accountsvalueNoSub-account list (institutional users), default value::array()
segmentboolNoReturn assets by segment; default false
market_valueboolNoInclude position market values; default false

Return

web::json::value JSON object

Return Properties

PropertyTypeDescription
accountstringAccount ID
segmentsarrayAccount segment information list
-- categorystringSegment category S(Securities)/C(Futures)
-- currencystringCurrency
-- netLiquidationfloatNet liquidation value
-- equityWithLoanfloatEquity with loan value
-- initMarginfloatInitial margin
-- maintainMarginfloatMaintenance margin
-- buyingPowerfloatBuying power
-- cashBalancefloatCash balance
-- grossPositionValuefloatTotal position market value
-- unrealizedPLfloatUnrealized P&L
-- realizedPLfloatRealized P&L

Example

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

using namespace TIGER_API;

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

// Get all assets
value assets = trade_client.get_asset();
ucout << assets.serialize() << std::endl;

// Get assets with segment information
value assets_seg = trade_client.get_asset(config.account, value::array(), true);
ucout << assets_seg.serialize() << std::endl;

Get Prime Account Assets

value TradeClient::get_prime_asset(const utility::string_t &account, const utility::string_t &base_currency)

Description

Returns asset information for a standard/paper trading (Prime) account as JSON.

Parameters

ParameterTypeRequiredDescription
accountutility::string_tNoAccount ID; uses the configured account by default
base_currencyutility::string_t or CurrencyNoBase currency, default U("USD") / Currency::USD

Return

web::json::value JSON object

Example

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

value prime_asset = trade_client.get_prime_asset();
ucout << prime_asset.serialize() << std::endl;

Get a Prime Account Portfolio

PortfolioAccount TradeClient::get_prime_portfolio(const utility::string_t &account, const utility::string_t &base_currency)

Description

Returns portfolio assets for a global account as a PortfolioAccount structure, including detailed Segment and CurrencyAsset data.

Parameters

ParameterTypeRequiredDescription
accountutility::string_tNoAccount ID
base_currencyutility::string_tNoBase currency, default U("USD")

Return

PortfolioAccount object

PortfolioAccount Properties

PropertyTypeDescription
accountutility::string_tAccount ID
update_timestamplongUpdate timestamp
segmentsvector<Segment>Segment list

Segment Properties

PropertyTypeDescription
categoryutility::string_tSegment category
capabilityutility::string_tAccount capability
currencyutility::string_tCurrency
buying_powerdoubleBuying power
cash_available_for_tradedoubleCash available for trading
cash_available_for_withdrawaldoubleCash available for withdrawal
cash_balancedoubleCash balance
equity_with_loandoubleEquity with loan value
excess_liquidationdoubleExcess liquidity
gross_position_valuedoubleTotal position market value
init_margindoubleInitial margin
leveragedoubleLeverage
locked_fundsdoubleLocked funds
maintain_margindoubleMaintenance margin
net_liquidationdoubleNet liquidation value
overnight_liquidationdoubleOvernight net liquidation value
overnight_margindoubleOvernight margin
realized_pldoubleRealized P&L
total_today_pldoubleTotal P&L for the day
unrealized_pldoubleUnrealized P&L
unrealized_plby_cost_of_carrydoubleUnrealized P&L using the cost-of-carry method
currency_assetsvector<CurrencyAsset>Currency asset list

CurrencyAsset Properties

PropertyTypeDescription
currencyutility::string_tCurrency
cash_balancedoubleCash balance
cash_available_for_tradedoubleCash available for trading
gross_position_valuedoublePosition market value
stock_market_valuedoubleStock market value
option_market_valuedoubleOption market value
realized_pldoubleRealized P&L
unrealized_pldoubleUnrealized P&L

Example

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

PortfolioAccount portfolio = trade_client.get_prime_portfolio();
std::cout << "Account: " << portfolio.account << std::endl;
for (auto& seg : portfolio.segments) {
    ucout << U("Segment: ") << seg.category
          << U(" Net Liquidation: ") << seg.net_liquidation
          << std::endl;
    for (auto& asset : seg.currency_assets) {
        ucout << U("  Currency: ") << asset.currency
              << U(" Cash: ") << asset.cash_balance
              << std::endl;
    }
}

Get Positions

value TradeClient::get_positions(utility::string_t account, SecType sec_type, Currency currency, Market market, utility::string_t symbol, const value &sub_accounts, time_t expiry, utility::string_t strike, Right right)

vector<Position> TradeClient::get_position_list(
    utility::string_t account = U(""), utility::string_t sec_type = U(""),
    utility::string_t currency = U("ALL"), utility::string_t market = U("ALL"),
    utility::string_t symbol = U(""), const value &sub_accounts = value::array(),
    time_t expiry = -1, utility::string_t strike = U(""),
    utility::string_t right = U(""))

Description

Returns account positions. Overloads accept either enum or string parameters.

Parameters (Enum Version)

ParameterTypeRequiredDescription
accountutility::string_tNoAccount ID
sec_typeSecTypeNoContract type, default SecType::ALL
currencyCurrencyNoCurrency, default Currency::ALL
marketMarketNoMarket, default Market::ALL
symbolutility::string_tNoSymbol, default empty
sub_accountsvalueNoSub-account list
expirytime_tNoOption expiry timestamp, default -1
strikeutility::string_tNoOption strike price
rightRightNoOption direction, default Right::ALL

Parameters (String Version)

ParameterTypeRequiredDescription
accountutility::string_tNoAccount ID
sec_typeutility::string_tNoContract type, e.g., U("STK")
currencyutility::string_tNoCurrency, default U("ALL")
marketutility::string_tNoMarket, default U("ALL")
symbolutility::string_tNoSymbol
sub_accountsvalueNoSub-account list
expirytime_tNoOption expiry timestamp
strikeutility::string_tNoOption strike price
rightutility::string_tNoOption direction, e.g., U("PUT")/U("CALL")

Return

web::json::value JSON array, or vector<Position> position object list (using get_position_list method)

Position Object Properties

PropertyTypeDescription
accountutility::string_tAccount ID
contractContractContract object
positionlong longPosition quantity
average_costdoubleAverage cost
latest_pricedoubleLatest price
market_valuedoublePosition market value
unrealized_pnldoubleUnrealized P&L
realized_pnldoubleRealized P&L

Example

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

// Get all positions (JSON format)
value positions = trade_client.get_positions();
ucout << positions.serialize() << std::endl;

// Get positions for a specific symbol (enum version)
value pos_aapl = trade_client.get_positions(
    config.account,
    SecType::STK,
    Currency::ALL,
    Market::ALL,
    U("AAPL")
);
ucout << pos_aapl.serialize() << std::endl;

// Get position object list
vector<Position> pos_list = trade_client.get_position_list();
for (auto& pos : pos_list) {
    ucout << pos.contract.symbol << U(" position: ") << pos.position
          << U(" avg_cost: ") << pos.average_cost << std::endl;
}

Response Example

{
  "code": 0,
  "message": "success",
  "timestamp": 1785528000000,
  "data": [
    {
      "account": "DU12345678",
      "symbol": "AAPL",
      "position": 100,
      "averageCost": 150.25,
      "latestPrice": 308.91,
      "marketValue": 30891.0,
      "unrealizedPnl": 15866.0,
      "secType": "STK",
      "currency": "USD"
    }
  ]
}

Get Asset Analytics

value TradeClient::get_analytics_asset(utility::string_t account, utility::string_t start_date, utility::string_t end_date, utility::string_t seg_type, utility::string_t currency, utility::string_t sub_account)

Description

Returns account asset analytics, including historical changes in asset value.

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount ID
start_dateutility::string_tYesStart date, format "yyyy-MM-dd"
end_dateutility::string_tYesEnd date, format "yyyy-MM-dd"
seg_typeutility::string_tNoAccount segment, U("SEC")/U("FUT"), default U("SEC")
currencyutility::string_tNoCurrency, default U("USD")
sub_accountutility::string_tNoSub-account, default empty

Return

web::json::value JSON object

Example

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

value analytics = trade_client.get_analytics_asset(
    config.account,
    U("2024-01-01"),
    U("2024-06-30")
);
ucout << analytics.serialize() << std::endl;

Estimate Tradable Quantity

value TradeClient::get_estimate_tradable_quantity(Order &order, utility::string_t seg_type)

Description

Estimates the maximum quantity of a symbol that the current account can trade. Construct an Order object and pass it to the method.

Parameters

ParameterTypeRequiredDescription
orderOrder&YesOrder object (containing contract, direction, price, etc.)
seg_typeutility::string_tNoAccount segment, default U("SEC")

Return

web::json::value JSON object

Example

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

using namespace TIGER_API;

ClientConfig config(false, U("your_config_directory_path"));
TradeClient trade_client(config);

Contract contract = ContractUtil::stock_contract(U("AAPL"), U("USD"));
Order order = OrderUtil::limit_order(config.account, contract, U("BUY"), 100, 150.0);

value result = trade_client.get_estimate_tradable_quantity(order);
ucout << result.serialize() << std::endl;

What’s Next

Did this page help you?