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
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Account ID; uses the configured account if omitted |
| sub_accounts | value | No | Sub-account list (institutional users), default value::array() |
| segment | bool | No | Return assets by segment; default false |
| market_value | bool | No | Include position market values; default false |
Return
web::json::value JSON object
Return Properties
| Property | Type | Description |
|---|---|---|
| account | string | Account ID |
| segments | array | Account segment information list |
| -- category | string | Segment category S(Securities)/C(Futures) |
| -- currency | string | Currency |
| -- netLiquidation | float | Net liquidation value |
| -- equityWithLoan | float | Equity with loan value |
| -- initMargin | float | Initial margin |
| -- maintainMargin | float | Maintenance margin |
| -- buyingPower | float | Buying power |
| -- cashBalance | float | Cash balance |
| -- grossPositionValue | float | Total position market value |
| -- unrealizedPL | float | Unrealized P&L |
| -- realizedPL | float | Realized 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Account ID; uses the configured account by default |
| base_currency | utility::string_t or Currency | No | Base 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Account ID |
| base_currency | utility::string_t | No | Base currency, default U("USD") |
Return
PortfolioAccount object
PortfolioAccount Properties
| Property | Type | Description |
|---|---|---|
| account | utility::string_t | Account ID |
| update_timestamp | long | Update timestamp |
| segments | vector<Segment> | Segment list |
Segment Properties
| Property | Type | Description |
|---|---|---|
| category | utility::string_t | Segment category |
| capability | utility::string_t | Account capability |
| currency | utility::string_t | Currency |
| buying_power | double | Buying power |
| cash_available_for_trade | double | Cash available for trading |
| cash_available_for_withdrawal | double | Cash available for withdrawal |
| cash_balance | double | Cash balance |
| equity_with_loan | double | Equity with loan value |
| excess_liquidation | double | Excess liquidity |
| gross_position_value | double | Total position market value |
| init_margin | double | Initial margin |
| leverage | double | Leverage |
| locked_funds | double | Locked funds |
| maintain_margin | double | Maintenance margin |
| net_liquidation | double | Net liquidation value |
| overnight_liquidation | double | Overnight net liquidation value |
| overnight_margin | double | Overnight margin |
| realized_pl | double | Realized P&L |
| total_today_pl | double | Total P&L for the day |
| unrealized_pl | double | Unrealized P&L |
| unrealized_plby_cost_of_carry | double | Unrealized P&L using the cost-of-carry method |
| currency_assets | vector<CurrencyAsset> | Currency asset list |
CurrencyAsset Properties
| Property | Type | Description |
|---|---|---|
| currency | utility::string_t | Currency |
| cash_balance | double | Cash balance |
| cash_available_for_trade | double | Cash available for trading |
| gross_position_value | double | Position market value |
| stock_market_value | double | Stock market value |
| option_market_value | double | Option market value |
| realized_pl | double | Realized P&L |
| unrealized_pl | double | Unrealized 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)
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Account ID |
| sec_type | SecType | No | Contract type, default SecType::ALL |
| currency | Currency | No | Currency, default Currency::ALL |
| market | Market | No | Market, default Market::ALL |
| symbol | utility::string_t | No | Symbol, default empty |
| sub_accounts | value | No | Sub-account list |
| expiry | time_t | No | Option expiry timestamp, default -1 |
| strike | utility::string_t | No | Option strike price |
| right | Right | No | Option direction, default Right::ALL |
Parameters (String Version)
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Account ID |
| sec_type | utility::string_t | No | Contract type, e.g., U("STK") |
| currency | utility::string_t | No | Currency, default U("ALL") |
| market | utility::string_t | No | Market, default U("ALL") |
| symbol | utility::string_t | No | Symbol |
| sub_accounts | value | No | Sub-account list |
| expiry | time_t | No | Option expiry timestamp |
| strike | utility::string_t | No | Option strike price |
| right | utility::string_t | No | Option 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
| Property | Type | Description |
|---|---|---|
| account | utility::string_t | Account ID |
| contract | Contract | Contract object |
| position | long long | Position quantity |
| average_cost | double | Average cost |
| latest_price | double | Latest price |
| market_value | double | Position market value |
| unrealized_pnl | double | Unrealized P&L |
| realized_pnl | double | Realized 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | Yes | Account ID |
| start_date | utility::string_t | Yes | Start date, format "yyyy-MM-dd" |
| end_date | utility::string_t | Yes | End date, format "yyyy-MM-dd" |
| seg_type | utility::string_t | No | Account segment, U("SEC")/U("FUT"), default U("SEC") |
| currency | utility::string_t | No | Currency, default U("USD") |
| sub_account | utility::string_t | No | Sub-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
| Parameter | Type | Required | Description |
|---|---|---|---|
| order | Order& | Yes | Order object (containing contract, direction, price, etc.) |
| seg_type | utility::string_t | No | Account 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;Updated 8 days ago
