Assets and Positions
get_accounts Get Account List
value TradeClient::get_accounts()
Description
Get all accounts under the current developer
Return
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("/path/to/your/properties/"));
TradeClient trade_client(config);
value accounts = trade_client.get_accounts();
ucout << accounts.serialize() << std::endl;get_asset Get Account Assets
value TradeClient::get_asset(utility::string_t account, const value &sub_accounts, bool segment, bool market_value)
Description
Get account asset information (applicable to Standard/Global/Paper accounts)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Fund account, uses default account if not provided |
| sub_accounts | value | No | Sub-account list (institutional users), default value::array() |
| segment | bool | No | Whether to return segmented assets, default false |
| market_value | bool | No | Whether to include position market value, default false |
Return
web::json::value JSON object
Return Properties
| Property | Type | Description |
|---|---|---|
| account | string | Fund account |
| 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("/path/to/your/properties/"));
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_asset Get Prime Account Assets
value TradeClient::get_prime_asset(const utility::string_t &account, const utility::string_t &base_currency)
Description
Get Global (Prime) account asset information, returns JSON format
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Fund account, uses 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("/path/to/your/properties/"));
TradeClient trade_client(config);
value prime_asset = trade_client.get_prime_asset();
ucout << prime_asset.serialize() << std::endl;get_prime_portfolio Get Prime Account Portfolio
PortfolioAccount TradeClient::get_prime_portfolio(const utility::string_t &account, const utility::string_t &base_currency)
Description
Get Global account portfolio asset information, returns PortfolioAccount struct (containing Segment and CurrencyAsset detailed data)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Fund account |
| base_currency | utility::string_t | No | Base currency, default U("USD") |
Return
PortfolioAccount object
PortfolioAccount Properties
| Property | Type | Description |
|---|---|---|
| account | utility::string_t | Fund account |
| 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 |
| maintain_margin | double | Maintenance margin |
| net_liquidation | double | Net liquidation value |
| realized_pl | double | Realized P&L |
| unrealized_pl | double | Unrealized P&L |
| 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("/path/to/your/properties/"));
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 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)
Description
Get account position information. This method provides multiple overloaded versions supporting both enum and string parameter types.
Parameters (Enum Version)
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | No | Fund account |
| 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 | Fund account |
| 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 | Fund account |
| 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("/path/to/your/properties/"));
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;
}get_analytics_asset 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
Get account asset analytics data, including historical asset changes
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | utility::string_t | Yes | Fund account |
| 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("/path/to/your/properties/"));
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;get_estimate_tradable_quantity Get Estimated Tradable Quantity
value TradeClient::get_estimate_tradable_quantity(Order &order, utility::string_t seg_type)
Description
Estimate the maximum tradable quantity for a given symbol in the current account. An Order object must be constructed and passed in.
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("/path/to/your/properties/"));
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 1 day ago
