Get Account Information

Account List

TradeClient.get_accounts()

Description

Fetch a list of managed accounts of the current user, along with account information. Calling from an institutional account will return the master account and all sub-accounts.

Response

list, each element is a PortfolioAccount(include/tigerapi/model.h PortfolioAccount)object

Attributes:

AttributeTypeDescription
accountutility::string_tAccount identifier
update_timestamplongLast update time
segmentsvector<Segment>Account financial segments

Example Call

#include "tigerapi/quote_client.h"
#include "tigerapi/trade_client.h"
#include <iostream>
#include <memory>
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;

int main(int argc, char* args[]) {
    
    ClientConfig config(true, U("tiger_openapi_config.properties"));

    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
   
    value res = trade_client->get_accounts();
    ucout << U("Accounts: ") << res << endl;
    
    return 0;
}

Example Response

 {
  "items":[
    {
      "account":"572386",
      "accountType":"STANDARD",
      "capability":"CASH",
      "status":"Funded"
    },
    {
      "account":"202008211444425831",
      "accountType":"PAPER",
      "capability":"RegTMargin",
      "status":"Funded"
    }
  ]
}

Get Prime/Paper Trading Account Summary

value get_prime_asset(const utility::string_t & account = U(""), const utility::string_t & base_currency = U("USD"));
value get_prime_asset(const utility::string_t &account, Currency base_currency = Currency::USD);

Description

Get account summary, including asset information and open positions, for your Prime and Paper accounts

Parameters

ParameterTypeDescription
accountstring_taccount id, if not specified, the request will use default account id configured in client_config
base_currencyCurrencyCurrency of assets
default: Currency::USD

Response

list

A list where each element is a PortfolioAccount object. If there is only one account, the method will return a list with one element.

The structure of the PortfolioAccount object is as follows (for a detailed list of data fields contained in PortfolioAccount and Segment, please refer to Appendix 1: Objects):

PortfolioAccount object
├── account: account id
├── update_timestamp: update time, timestamp in milliseconds
├── segments: account information by segments, a dict with the security category as the key, and the value as a Segment object
│ ├── 'S' means securities account, value is Segment object
│ │ ├── currency: currency, such as USD, HKD
│ │ ├── capability: Account Type, Margin: RegTMargin, Cash: Cash
│ │ ├── category': Securities Classification S: (Securities Stocks)
│ │ ├── cash_balance': cash that can be traded, plus some 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)
│ │ ├── cash_available_for_trade': The amount of cash and margin that can be traded in the current account
│ │ ├── cash_available_for_withdrawal': The amount of cash that can be withdrawn in the current account
│ │ ├── gross_position_value': total security value: long stock value + short stock value + long option value + short option value. The above items are calculated as absolute values
│ │ ├── equity_with_loan': Equity with loan value (including loan value assets). Securities Segment: Cash value + stock value
│ │ ├── net_liquidation': net liquidation value
│ │ ├── init_margin': initial margin requirement
│ │ ├── maintain_margin': maintenance margin requirement
│ │ ├── overnight_margin': overnight margin requirement
│ │ ├── unrealized_pl': floating profit and loss
│ │ ├── realized_pl': realized profit and loss
│ │ ├── excess_liquidation': Excess liquidity, used to represent intraday risk value. Calculation method for securities segment: equity_with_loan - maintenance_margin_requirement.
│ │ ├── overnight_liquidation': Overnight risk control value, when it is less than 0, account positions will be forced to liquidate, and you need to pay attention to risks
│ │ ├── buying_power': buying power. Estimate how many 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 occupited) during the day. Overnight purchasing power Up to two times. 
│ │ ├── leverage': The currently leverage, if it is less than 1, it means that the leverage is not used, and if it is greater than 1, it means the leverage multiple used
│ │ ├── currency_assets: Account asset information differentiated by transaction currency, a dict with currency as key
│ │ │ ├── 'USD' means US dollar, value is CurrencyAsset object
│ │ │ │ ├── currency': current currency, commonly used currencies include: USD-US dollar, HKD-Hong Kong dollar, SGD-Singapore dollar, CNH-RMB
│ │ │ │ ├── cash_balance': cash that can be traded, plus some 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)
│ │ │ │ ├── cash_available_for_trade': The amount of cash that can be traded in the current account
│ │ │ │ ├── gross_position_value': gross value
│ │ │ │ ├── stock_market_value': The market value of the stock
│ │ │ │ ├── option_market_value': the market value of the option
│ │ │ │ ├── unrealized_pl': floating profit and loss within the account
│ │ │ │ ├── realized_pl': realized profit and loss in the account
│ │ │ ├── 'HKD' means Hong Kong dollar, value is CurrencyAsset object
│ │ └─ └── 'CNH' means RMB, value is CurrencyAsset object

Example Call

#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;

/**
 * Calling TradeClient
 */
class TestTradeClient {
public:
    static void test_get_prime_asset(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_prime_asset();
        cout << "asset: " << res << endl;
    }

    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_prime_asset(trade_client);
    }
};

int main(int argc, char *args[]) {
    
    ClientConfig config(true, U("tiger_openapi_config.properties"));
    /**
     * Use TradeClient
     */
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);


    return 0;
}

Example Response

{
  "accountId":"572386",
  "segments":
  [
    {
      "buyingPower":8617.0200000000004,
      "capability":"CASH",
      "cashAvailableForTrade":8617.0200000000004,
      "cashBalance":8617.0200000000004,
      "category":"S",
      "consolidatedSegTypes":["SEC"],
      "currency":"USD",
      "currencyAssets":
      [
        {
          "cashAvailableForTrade":7714.4700000000003,
          "cashBalance":7714.4700000000003,
          "currency":"USD"
        },
        {
          "cashAvailableForTrade":5800.29,
          "cashBalance":5800.29,
          "currency":"HKD"
        },
        {
          "cashAvailableForTrade":1.5,
          "cashBalance":1.5,
          "currency":"NZD"
        },
        {
          "cashAvailableForTrade":1123.95,
          "cashBalance":1123.95,
          "currency":"CNH"
        },
        {
          "cashAvailableForTrade":0.12,
          "cashBalance":0.12,
          "currency":"EUR"
        }
      ],
      "equityWithLoan":8829.4200000000001,
      "excessLiquidation":8617.0200000000004,
      "grossPositionValue":212.40000000000001,
      "initMargin":212.40000000000001,
      "leverage":0.02,
      "lockedFunds":0,
      "maintainMargin":212.40000000000001,
      "netLiquidation":8829.4200000000001,
      "overnightLiquidation":8617.0200000000004,
      "overnightMargin":212.40000000000001,
      "realizedPL":0,
      "totalTodayPL":0,
      "uncollected":0,
      "unrealizedPL":-29.760000000000002,
      "unrealizedPLByCostOfCarry":-29.760000000000002
    },
    {"buyingPower":8617.0200000000004,"capability":"CASH","cashAvailableForTrade":8617.0200000000004,"cashBalance":0,
      "category":"S","consolidatedSegTypes":["SEC"],"currency":"USD","currencyAssets":[{"cashAvailableForTrade":0,"cashBalance":0,"currency":"USD"},
      {"cashAvailableForTrade":0,"cashBalance":0,"currency":"HKD"},{"cashAvailableForTrade":0,"cashBalance":0,"currency":"CNH"}],"equityWithLoan":8829.4200000000001,
      "excessLiquidation":8617.0200000000004,"grossPositionValue":0,"initMargin":212.40000000000001,"leverage":0.02,"lockedFunds":0,
      "maintainMargin":212.40000000000001,"netLiquidation":0,"overnightLiquidation":8617.0200000000004,"overnightMargin":212.40000000000001,
      "realizedPL":0.78000000000000003,"totalTodayPL":0,"uncollected":0,"unrealizedPL":0,"unrealizedPLByCostOfCarry":0}],
  "updateTimestamp":1741939073276
}

Get Position Data

value get_positions(utility::string_t account = U(""), SecType sec_type = SecType::ALL, Currency currency = Currency::ALL,
                    Market market = Market::ALL,
                    utility::string_t symbol = U(""), const value &sub_accounts = value::array(), time_t expiry = -1,
                    utility::string_t strike = U(""), Right right = Right::ALL);

value get_positions(const utility::string_t &account, const utility::string_t &sec_type = U(""), const utility::string_t &currency = U("ALL"),
                    const utility::string_t &market = U("ALL"),
                    const utility::string_t &symbol = U(""), const value &sub_accounts = value::array(), time_t expiry = -1,
                    utility::string_t strike = U(""), const utility::string_t &right = U(""));

vector<Position> 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

Get the position information of the account

Parameters

ParameterTypeRequiredDescription
accountstring_tNoaccount id, if not specified, default account id configured in client_config will be used
sec_typeSecTypeNoSecType enumeration, including STK/OPT
default: SecType::ALL.
currencyCurrencyNoCurrency enumeration, including ALL/USD/HKD/CNH
default: Currency::ALL
marketMarketNoMarket enumeration, including ALL/US
default: Market::ALL
symbolstring_tNoTicker symbol
sub_accountslist<str>NoSub account list
expirytime_tNoOptions expiration date
default: -1
strikefloatNoOptions strike price, example: 100.5
rightstring_tNo'PUT' / 'CALL' for options
default: Right::ALL

Response

list Each element is a Position object.

The structure is as follows:

ParameterTypeDescription
accountutility::string_tAccount id
contractContractContract object
positionlong longPosition quantity
average_costdoubleHolding cost
latest_pricedoubleLatest price (During trading hours, it is the market price. For US stocks outside of trading hours, the prime account uses the after-hours closing price
market_valuedoubleMarket value
realized_pnldoubleRealized profit and loss
unrealized_pnldoubleUnrealized profit and loss

Example Call

#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;

/**
 * Calling TradeClient
 */
class TestTradeClient {
public:
    static void test_get_positions(const std::shared_ptr<TradeClient>& trade_client) {
        value res = trade_client->get_positions();
        ucout << "position: " << res << endl;
    }
    static void test_trade(const std::shared_ptr<TradeClient>& trade_client) {
        TestTradeClient::test_get_positions(trade_client);
    }
};

int main(int argc, char *args[]) {

 ClientConfig config(true, U("tiger_openapi_config.properties"));
    /**
     * Use TradeClient
     */
    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_trade(trade_client);


    return 0;
}

Example Response

{
  "account":"572386",
  "averageCost":1.1932,
  "averageCostByAverage":1.1932,
  "averageCostOfCarry":1.1932,
  "categories":[],
  "comboTypeMap":{},
  "contractId":7451,
  "currency":"USD",
  "identifier":"ROSGQ",
  "lastClosePrice":0.0001,
  "latestPrice":0.0001,
  "market":"US",
  "marketValue":0.00059999999999999995,
  "multiplier":1,
  "position":6,
  "positionQty":6,
  "positionScale":0,
  "realizedPnl":0,
  "realizedPnlByAverage":0,
  "salableQty":6,
  "secType":"STK",
  "status":0,
  "symbol":"ROSGQ",
  "todayPnl":0,
  "todayPnlPercent":0,
  "unrealizedPnl":-7.1585000000000001,
  "unrealizedPnlByAverage":-7.1585000000000001,
  "unrealizedPnlByCostOfCarry":-7.1585000000000001,
  "unrealizedPnlPercent":-0.99990000000000001,
  "unrealizedPnlPercentByAverage":-0.99990000000000001,
  "unrealizedPnlPercentByCostOfCarry":-0.99990000000000001,
  "updateTimestamp":1741939624143
}

Get Prime/Paper Trading Account Historical Asset Analysis

value get_analytics_asset(utility::string_t account, utility::string_t start_date, utility::string_t end_date, utility::string_t seg_type = U("SEC"), utility::string_t currency = U("USD"), utility::string_t sub_account = U(""));

Description

Get historical asset analysis of the account

Parameters

ParameterTypeRequiredDescription
accountutility::string_tYesAccount id
start_dateutility::string_tYesstart date, format yyyy-MM-dd, like '2022-01-01'
end_dateutility::string_tYesend date, format yyyy-MM-dd, like '2022-02-01', if not passed, use current date
seg_typeutility::string_tnoAccount segment
default: U("SEC")
currencyutility::string_tnocurrency type
default: U("USD")
sub_accountutility::string_tnoSub-account (for institutional accounts only), if this field is passed, the assets of the sub-account will be returned

Response

Summary: The corresponding value is the asset analysis summary.

ParameterTypeDescription
pnlfloatProfit and Loss Amount
pnl_percentagefloatProfit and Loss Amount rate
annualized_returnfloatAnnualized rate of return (imputed)
over_user_percentagefloatPercentage of users exceeded

History: History assets

ParameterTypeDescription
dateintDate timestamp in milliseconds
pnlfloatAmount of profit or loss compared to the previous day
pnl_percentagefloatYield compared to the previous day
assetfloatTotal assets amount
cash_balancefloatCash balance
gross_position_valuefloatposition market value
depositfloatdeposit amount
withdrawalfloatwithdrawal amount

Example Call

static void test_get_analytics_asset(const std::shared_ptr<TradeClient>& trade_client) {
    value res = trade_client->get_analytics_asset(trade_client->client_config.account, U("2026-06-01"),
     U("2026-07-15"));
    ucout << U("analytics asset: ") << res << endl;
}

Example Response

analytics asset: {"history":[{"asset":1000000,"cashBalance":1000000,"date":1782273600000,"deposit":1000000,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":1000000,"cashBalance":1000000,"date":1782360000000,"deposit":0,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":1000000,"cashBalance":1000000,"date":1782446400000,"deposit":0,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":1000000,"cashBalance":1000000,"date":1782532800000,"deposit":0,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":1000000,"cashBalance":1000000,"date":1782619200000,"deposit":0,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":1000000,"cashBalance":1000000,"date":1782705600000,"deposit":0,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":1000000,"cashBalance":1000000,"date":1782792000000,"deposit":0,"grossPositionValue":0,"pnl":0,"pnlPercentage":0,"withdrawal":0},{"asset":999991.07999999996,"cashBalance":999518.45999999996,"date":1782878400000,"deposit":0,"grossPositionValue":472.62,"pnl":-8.9199999999999999,"pnlPercentage":0,"withdrawal":0},{"asset":999990.42000000004,"cashBalance":999504.42000000004,"date":1782964800000,"deposit":0,"grossPositionValue":486,"pnl":-9.5800000000000001,"pnlPercentage":0,"withdrawal":0},{"asset":999990.42000000004,"cashBalance":999504.42000000004,"date":1783051200000,"deposit":0,"grossPositionValue":486,"pnl":-9.5800000000000001,"pnlPercentage":0,"withdrawal":0},{"asset":999990.42000000004,"cashBalance":999504.42000000004,"date":1783137600000,"deposit":0,"grossPositionValue":486,"pnl":-9.5800000000000001,"pnlPercentage":0,"withdrawal":0},{"asset":999990.42000000004,"cashBalance":999504.42000000004,"date":1783224000000,"deposit":0,"grossPositionValue":486,"pnl":-9.5800000000000001,"pnlPercentage":0,"withdrawal":0},{"asset":999985.68000000005,"cashBalance":999504.42000000004,"date":1783310400000,"deposit":0,"grossPositionValue":481.25999999999999,"pnl":-14.32,"pnlPercentage":0,"withdrawal":0},{"asset":999952.82999999996,"cashBalance":999504.42000000004,"date":1783396800000,"deposit":0,"grossPositionValue":448.41000000000003,"pnl":-47.170000000000002,"pnlPercentage":0,"withdrawal":0},{"asset":999949.31999999995,"cashBalance":999504.42000000004,"date":1783483200000,"deposit":0,"grossPositionValue":444.89999999999998,"pnl":-50.68,"pnlPercentage":-0.01,"withdrawal":0},{"asset":999960.90000000002,"cashBalance":999504.42000000004,"date":1783569600000,"deposit":0,"grossPositionValue":456.48000000000002,"pnl":-39.100000000000001,"pnlPercentage":0,"withdrawal":0},{"asset":999940.31999999995,"cashBalance":999504.42000000004,"date":1783656000000,"deposit":0,"grossPositionValue":435.89999999999998,"pnl":-59.68,"pnlPercentage":-0.01,"withdrawal":0},{"asset":999940.31999999995,"cashBalance":999504.42000000004,"date":1783742400000,"deposit":0,"grossPositionValue":435.89999999999998,"pnl":-59.68,"pnlPercentage":-0.01,"withdrawal":0},{"asset":999940.31999999995,"cashBalance":999504.42000000004,"date":1783828800000,"deposit":0,"grossPositionValue":435.89999999999998,"pnl":-59.68,"pnlPercentage":-0.01,"withdrawal":0},{"asset":999921.83999999997,"cashBalance":999504.42000000004,"date":1783915200000,"deposit":0,"grossPositionValue":417.42000000000002,"pnl":-78.159999999999997,"pnlPercentage":-0.01,"withdrawal":0},{"asset":999912.66000000003,"cashBalance":999504.42000000004,"date":1784001600000,"deposit":0,"grossPositionValue":408.24000000000001,"pnl":-87.340000000000003,"pnlPercentage":-0.01,"withdrawal":0}],"summary":{"annualizedReturn":-0.16,"overUserPercentage":0,"pnl":-87.340000000000003,"pnlPercentage":-0.01}}

Get Maximum Tradable Quantity

value get_estimate_tradable_quantity(Order &order, utility::string_t seg_type = U("SEC"))

Description

Query the maximum buy/sell quantity for a specific asset under the account, including stocks and options.

Parameters

FieldsTypeDescription
orderOrderOrder to be queried
seg_typeutility::string_tSegment type
default: U("SEC")

Order

Only limit or stop orders are supported

Response

FieldsTypeDescription
position_quantityfloatPosition (held) quantity
tradable_position_quantityfloatQuantity available for trading
tradable_quantityfloatCash Tradable Quantity (If action is 'buy', returns the quantity available for purchase; otherwise, returns the quantity available for sale)

Example Call

#include "tigerapi/quote_client.h"
#include "tigerapi/trade_client.h"
#include "tigerapi/contract_util.h"
#include "tigerapi/order_util.h"
#include <iostream>
#include <memory>
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;

class TestTradeClient {
public:
    static void test_get_estimate_tradable_quantity(const std::shared_ptr<TradeClient>& trade_client) {
        Contract contract = ContractUtil::stock_contract(U("ABCD"), U("USD"));
        Order order = OrderUtil::limit_order(contract, U("BUY"), 1, 310.0);
        value res = trade_client->get_estimate_tradable_quantity(order);
        ucout << U("estimate tradable quantity: ") << res << endl;
    };
};

int main(int argc, char* args[]) {

    ClientConfig config(true, U("tiger_openapi_config.properties"));

    std::shared_ptr<TradeClient> trade_client = std::make_shared<TradeClient>(config);
    TestTradeClient::test_get_estimate_tradable_quantity(trade_client);
    
        return 0;
};

Example Response

  {"financingQuantity":33320,"positionQuantity":0,"tradablePositionQuantity":0,"tradableQuantity":9998}

Did this page help you?