Account Changes

About 6 min

Subscribe and Unsubscribe to Asset Changes

Subscribe method

virtual bool subscribe_asset(const std::string& account) = 0;

Unsubscribe method

virtual bool unsubscribe_asset(const std::string& account) = 0;

Parameters

ParameterTypeDescription
accountstd::string&account id to subscribe to

Return

Need to use push_client->set_asset_changed_callback to return the result of the response

Callback Data Field
Asset Change Callback

FieldTypeDescription
accountstd::string&User account
currencystd::string&Currency. USD, HKD, etc.
segTypestd::string&Securities Category C: (Commodities Futures), S: (Securities Stocks)
availableFundsdoubleAvailable funds, overnight liquidity
excessLiquiditydoubleExcess liquidity, used to represent intraday risk value
netLiquidationdoubleTotal Assets (Net Liquidation Value)
equityWithLoandoubleEquity with loan value (asset with loan value) - Securities Segment: Cash Value + Stock Value - Futures Segment: Cash Value - Maintenance Margin
buyingPowerdoubleBuying power. An estimation of how many more dollars you can buy in stock assets. (Stock segment only)
cashBalancedoubleCash amount. Sum of current cash balances in all currencies
grossPositionValuedoubleTotal value of securities
initMarginReqdoubleInitial margin requirement
maintMarginReqdoubleMaintenance margin requirement
timestampuint64_ttimestamp

Example

class TestPushClient {
private:
    std::shared_ptr<IPushClient> push_client;
    std::vector<std::string> symbols;

public:
    TestPushClient(std::shared_ptr<IPushClient> client) : push_client(client) {
        std::vector<std::string> hk_option_symbols = {"TCH.HK 20241230 410.00 CALL"};
        std::vector<std::string> future_symbols = {"CL2412"};
        symbols = future_symbols;
    }

    void connected_callback() {
        ucout << "Connected to push server" << std::endl;
        push_client->subscribe_asset(utility::conversions::to_utf8string(push_client->get_client_config().account));
    }
    
    void asset_changed_callback(const tigeropen::push::pb::AssetData& data) {
        ucout << "Asset changed:" << std::endl;
        ucout << "- cashbalance: " << data.cashbalance() << std::endl;
        ucout << "- netliquidation: " << data.netliquidation() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_connected_callback(std::bind(&TestPushClient::connected_callback, this));
        push_client->set_asset_changed_callback(std::bind(&TestPushClient::asset_changed_callback, this, std::placeholders::_1));
        
        push_client->connect();

        std::signal(SIGINT, signal_handler);  //Ctrl+C
        std::signal(SIGTERM, signal_handler); //kill
        while (keep_running)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }

        push_client->unsubscribe_asset(utility::conversions::to_utf8string(config.account));
        push_client->disconnect();
    }

    static void test_push_client(std::shared_ptr<IPushClient> push_client, ClientConfig config) {
        TestPushClient test(push_client);
        test.start_test(config);
    }

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private key xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";
    
    auto push_client = IPushClient::create_push_client(config);
    TestPushClient::test_push_client(push_client, config);


Callback data example

{
  "dataType":"Asset",
  "assetData":
  {
    "account":"111111111111",
    "segType":"S",
    "availableFunds":797832.55572773679,
    "excessLiquidity":826227.79308567208,
    "netLiquidation":944515.55984458746,
    "equityWithLoan":944494.85984458751,
    "buyingPower":3191330.2229109472,
    "cashBalance":656046.6059349241,
    "grossPositionValue":288448.25390966347,
    "initMarginReq":146662.30411685078,
    "maintMarginReq":118287.76675891539,
    "timestamp":"1732177851891"
  }
}

Subscribe and Unsubscribe to Position Changes

Subscribe method

virtual bool subscribe_position(const std::string& account) = 0;

Unsubscribe method

virtual bool unsubscribe_position(const std::string& account) = 0;

Parameters

ParameterTypeDescription
accountstd::string&account id to subscribe to

Examples

class TestPushClient {
private:
    std::shared_ptr<IPushClient> push_client;
    std::vector<std::string> symbols;

public:
    TestPushClient(std::shared_ptr<IPushClient> client) : push_client(client) {
        std::vector<std::string> hk_option_symbols = {"TCH.HK 20241230 410.00 CALL"};
        std::vector<std::string> future_symbols = {"CL2412"};
        symbols = future_symbols;
    }
    
    void connected_callback() {
        ucout << "Connected to push server" << std::endl;
        push_client->subscribe_position(utility::conversions::to_utf8string(push_client->get_client_config().account));

    }
    
    void position_changed_callback(const tigeropen::push::pb::PositionData& data) {
        ucout << "Position changed:" << std::endl;
        ucout << "- symbol: " << utility::conversions::to_string_t(data.symbol()) << std::endl;
        ucout << "- positionqty: " << data.positionqty() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_position_changed_callback(std::bind(&TestPushClient::position_changed_callback, this, std::placeholders::_1));
        
        push_client->connect();

        std::signal(SIGINT, signal_handler);  //Ctrl+C
        std::signal(SIGTERM, signal_handler); //kill
        while (keep_running)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }

        push_client->unsubscribe_position(utility::conversions::to_utf8string(config.account));
        push_client->disconnect();
    }

    static void test_push_client(std::shared_ptr<IPushClient> push_client, ClientConfig config) {
        TestPushClient test(push_client);
        test.start_test(config);
    }

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private key xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";
    
    auto push_client = IPushClient::create_push_client(config);
    TestPushClient::test_push_client(push_client, config);

return
Need to use push_client->set_position_changed_callback to return the result of the response

FieldTypeDescription
accountstd::string&User account
symbolstd::string&Symbol of the underlying position, such as 'AAPL', '00700', 'ES', 'CN'
expirystd::string&Only supports options, warrants, CBBCs
strikestd::string&Only supports options, warrants, CBBCs
rightstd::string&Only supports options, warrants, CBBCs
identifierstd::string&The identifier of the underlying asset. The identifier for stocks is the same as the symbol. For futures, it will have the contract month, e.g. 'CN2201'
multiplieruint32_tMultiplier for futures, options, warrants and CBBC
marketstd::string&Market
currencystd::string&Currency
segTypestd::string&Segment category
secTypestd::string&Type of security
positionint64_tNumber of Positions
positionScaleint32_tOffset of position size
averageCostdoubleAverage price of a position
latestPricedoubleLast price of the position
marketValuedoubleMarket value of the position
unrealizedPnldoubleUnrealized P&L of the position
namestd::string&Symbol name
timestampuint64_tTimestamp
saleableint64_tSaleable quantity for Chinese A-share market stocks
positionQtydoubleTotal position quantity
salableQtydoubleSaleable quantity

Callback data example Stock position change push

{
  "account": "1111111",
  "symbol": "BILI",
  "identifier": "BILI",
  "multiplier": 1,
  "market": "US",
  "currency": "USD",
  "segType": "S",
  "secType": "STK",
  "position": 100,
  "averageCost": 80,
  "latestPrice": 19.83,
  "marketValue": 1983,
  "unrealizedPnl": -6017,
  "timestamp": 1677745420121
}

Subscribe and Unsubscribe to Order Status Changes

Subscribe method

virtual bool subscribe_order(const std::string& account) = 0;

Unsubscribe method

virtual bool unsubscribe_order(const std::string& account) = 0;

Parameters

ParameterTypeDescription
accountstd::string&account id to subscribe to

Example

class TestPushClient {
private:
    std::shared_ptr<IPushClient> push_client;
    std::vector<std::string> symbols;

public:
    TestPushClient(std::shared_ptr<IPushClient> client) : push_client(client) {
        std::vector<std::string> hk_option_symbols = {"TCH.HK 20241230 410.00 CALL"};
        std::vector<std::string> future_symbols = {"CL2412"};
        symbols = future_symbols;
    }
    
    void connected_callback() {
        ucout << "Connected to push server" << std::endl;
        push_client->subscribe_order(utility::conversions::to_utf8string(push_client->get_client_config().account));

    }
    
    void order_changed_callback(const tigeropen::push::pb::OrderStatusData& data) {
        ucout << "Order changed:" << std::endl;
        ucout << "- id: " << data.id() << std::endl;
        ucout << "- status: " << utility::conversions::to_string_t(data.status()) << std::endl;
        ucout << "- avgfillprice: " << data.avgfillprice() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_order_changed_callback(std::bind(&TestPushClient::order_changed_callback, this, std::placeholders::_1));
        
        push_client->connect();

        std::signal(SIGINT, signal_handler);  //Ctrl+C
        std::signal(SIGTERM, signal_handler); //kill
        while (keep_running)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }

        push_client->unsubscribe_order(utility::conversions::to_utf8string(config.account));
        push_client->disconnect();
    }

    static void test_push_client(std::shared_ptr<IPushClient> push_client, ClientConfig config) {
        TestPushClient test(push_client);
        test.start_test(config);
    }

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private key xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";
    
    auto push_client = IPushClient::create_push_client(config);
    TestPushClient::test_push_client(push_client, config);

return
Need to use push_client->set_order_changed_callback response to return the results

FieldTypeDescription
idint64_tOrder number
accountstd::string&User account number
symbolstd::string&Symbol of the underlying position, such as 'AAPL', '00700', 'ES', 'CN'
expirystd::string&Expiration date. Only options, warrants, CBBCs are supported
strikestd::string&Strike price. Only options, warrants, CBBCs are supported
rightstd::string&Only options, warrants, CBBCs are supported
identifierstd::string&The identifier of the underlying asset. The identifier for stocks is the same as the symbol. For futures, it will have the contract month, e.g. 'CN2201'
multiplieruint32_tThe number of lots, futures, options, warrants, CBBC only
actionstd::string&Buy and Sell direction
marketstd::string&Market
currencystd::string&Currency
segTypestd::string&Segment category
secTypestd::string&Type of security
orderTypestd::string&Order type.' MKT' Market Order / 'LMT' Limit Order / 'STP' Stop Loss Order / 'STP_LMT' Stop Loss Limit Order / 'TRAIL' Trailing Stop Order
isLongboolWhether the position is long
totalQuantityint64_tThe number of orders placed
totalQuantityScaleint32_tOffset of the number of orders placed
filledQuantityint64_tTotal quantity of transactions (if the order is divided into multiple transactions, filledQuantity is the cumulative total number of transactions)
filledQuantityScaleint32_tTotal number of transactions offset
avgFillPricedoubleAverage price at which the orders got filled
limitPricedoubleLimit price(required when orderType is 'LMT')
stopPricedoubleStop price(required when orderType is 'STP')
realizedPnldoubleRealized profit/loss (only consolidated accounts have this field)
statusstd::string&Order Status
replaceStatusstd::string&Order change status
cancelStatusstd::string&Order cancel status
outsideRthboolWhether to allow pre and after hours trading, only for US stocks
canModifyboolWhether order can be modified
canCancelboolWhether order can be cancelled
liquidationboolWhether the order is closed
namestd::string&Symbol name
sourcestd::string&Order source (from 'OpenApi', or other)
errorMsgstd::string&Error message
attrDescstd::string&Order description
commissionAndFeefloatTotal commission and fee
openTimeuint64_tTimestamp when the order was placed
timestampuint64_tLast update time
userMarkstd::string&Remark
totalCashAmountdoubletotal cash amount
filledCashAmountdoublefilled cash amount

Callback data example Stock order push example

{
  "dataType":"OrderStatus",
  "orderStatusData":
  {
    "id":"37129891133115200",
    "account":"123123123",
    "symbol":"PDD",
    "identifier":"PDD",
    "multiplier":1, 
    "action":"BUY",
    "market":"US",
    "currency":"USD",
    "segType":"S",
    "secType":"STK",
    "orderType":"LMT",
    "isLong":true,
    "totalQuantity":"1",
    "limitPrice":50, 
    "status":"PendingSubmit",
    "replaceStatus":"NONE",
    "cancelStatus":"NONE",
    "outsideRth":true,
    "canModify":true,
    "canCancel":true,
    "name":"PDD Holdings",
    "source":"openapi",
    "openTime":"1732177851000",
    "timestamp":"1732177851874"
  }
}

Subscribe and Unsubscribe to Transactions

Subscribe method

virtual bool subscribe_transaction(const std::string& account) = 0;

Unsubscribe method

virtual bool unsubscribe_transaction(const std::string& account) = 0;

Parameters

ParameterTypeDescription
accountstd::string&account id to subscribe to

Return

Need to use push_client->set_transaction_changed_callback to return the result of the response

Callback Data Field

NameTypeDescription
idint64_tTransaction ID
order_idint64_tUnique order id
accountstd::string&User account
symbolstd::string&Stock ticker symbol, exmaple: 'AAPL', '00700', 'ES', 'CN'
identifierstd::string&The identifier of the underlying asset. The identifier for stocks is the same as the symbol. For futures, it will have the contract month, e.g. 'CN2201'
multiplieruint32_tMultiplier for options, warrants and CBBC
actionstd::string&"BUY" or "SELL"
marketstd::string&Market
currencystd::string&Currency
segTypestd::string&Segment category
secTypestd::string&Type of security
filled_pricedoubleFilled price
filled_quantityint64_tFilled quantity
create_timeuint64_tCreate time
update_timeuint64_tUpdate time
transact_timeuint64_tTransaction time
timestampuint64_tTimestamp

Example

class TestPushClient {
private:
    std::shared_ptr<IPushClient> push_client;
    std::vector<std::string> symbols;

public:
    TestPushClient(std::shared_ptr<IPushClient> client) : push_client(client) {
        std::vector<std::string> hk_option_symbols = {"TCH.HK 20241230 410.00 CALL"};
        std::vector<std::string> future_symbols = {"CL2412"};
        symbols = future_symbols;
    }

    void connected_callback() {
        ucout << "Connected to push server" << std::endl;
        push_client->subscribe_transaction(utility::conversions::to_utf8string(push_client->get_client_config().account));
    }
    
    void transaction_changed_callback(const tigeropen::push::pb::OrderTransactionData& data) {
        ucout << "Transaction changed:" << std::endl;
        ucout << "- Transaction Id: " << data.id() << std::endl;
        ucout << "- Transaction Time: " << data.transactTime() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_connected_callback(std::bind(&TestPushClient::connected_callback, this));
        push_client->set_transaction_changed_callback(std::bind(&TestPushClient::transaction_changed_callback, this, std::placeholders::_1));
        
        push_client->connect();

        std::signal(SIGINT, signal_handler);  //Ctrl+C
        std::signal(SIGTERM, signal_handler); //kill
        while (keep_running)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }

        push_client->unsubscribe_transaction(utility::conversions::to_utf8string(config.account));
        push_client->disconnect();
    }

    static void test_push_client(std::shared_ptr<IPushClient> push_client, ClientConfig config) {
        TestPushClient test(push_client);
        test.start_test(config);
    }

int main(int argc, char *args[]) {
    cout << "Tiger Api main" << endl;
    /************************** set config **********************/
    ClientConfig config = ClientConfig(true);

    config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
                         "xxxxxx private key xxxxxxxx"
                         "-----END RSA PRIVATE KEY-----";
    config.tiger_id = "Tiger ID";
    config.account = "Account ID";
    
    auto push_client = IPushClient::create_push_client(config);
    TestPushClient::test_push_client(push_client, config);


Callback data example

{
  "id": 2999543887211111111,
  "orderId": 29995438111111111,
  "account": "11111111",
  "symbol": "ZC",
  "identifier": "ZC2305",
  "multiplier": 5000,
  "action": "BUY",
  "market": "US",
  "currency": "USD",
  "segType": "C",
  "secType": "FUT",
  "filledPrice": 6.385,
  "filledQuantity": 1,
  "createTime": 1677746237303,
  "updateTime": 1677746237303,
  "transactTime": 1677746237289,
  "timestamp": 1677746237313,
}

Last update: