Get Account Information

get_accounts

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_assets

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_positions

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_analytics_asset

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(""));



Did this page help you?