Account Changes
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
| Parameter | Type | Description |
|---|---|---|
| account | std::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
| Field | Type | Description |
|---|---|---|
| account | std::string& | User account |
| currency | std::string& | Currency. USD, HKD, etc. |
| segType | std::string& | Securities Category C: (Commodities Futures), S: (Securities Stocks) |
| availableFunds | double | Available funds, overnight liquidity |
| excessLiquidity | double | Excess liquidity, used to represent intraday risk value |
| netLiquidation | double | Total Assets (Net Liquidation Value) |
| equityWithLoan | double | Equity with loan value (asset with loan value) - Securities Segment: Cash Value + Stock Value - Futures Segment: Cash Value - Maintenance Margin |
| buyingPower | double | Buying power. An estimation of how many more dollars you can buy in stock assets. (Stock segment only) |
| cashBalance | double | Cash amount. Sum of current cash balances in all currencies |
| grossPositionValue | double | Total value of securities |
| initMarginReq | double | Initial margin requirement |
| maintMarginReq | double | Maintenance margin requirement |
| timestamp | uint64_t | timestamp |
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
| Parameter | Type | Description |
|---|---|---|
| account | std::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
| Field | Type | Description |
|---|---|---|
| account | std::string& | User account |
| symbol | std::string& | Symbol of the underlying position, such as 'AAPL', '00700', 'ES', 'CN' |
| expiry | std::string& | Only supports options, warrants, CBBCs |
| strike | std::string& | Only supports options, warrants, CBBCs |
| right | std::string& | Only supports options, warrants, CBBCs |
| identifier | std::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' |
| multiplier | uint32_t | Multiplier for futures, options, warrants and CBBC |
| market | std::string& | Market |
| currency | std::string& | Currency |
| segType | std::string& | Segment category |
| secType | std::string& | Type of security |
| position | int64_t | Number of Positions |
| positionScale | int32_t | Offset of position size |
| averageCost | double | Average price of a position |
| latestPrice | double | Last price of the position |
| marketValue | double | Market value of the position |
| unrealizedPnl | double | Unrealized P&L of the position |
| name | std::string& | Symbol name |
| timestamp | uint64_t | Timestamp |
| saleable | int64_t | Saleable quantity for Chinese A-share market stocks |
| positionQty | double | Total position quantity |
| salableQty | double | Saleable 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
| Parameter | Type | Description |
|---|---|---|
| account | std::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
| Field | Type | Description |
|---|---|---|
| id | int64_t | Order number |
| account | std::string& | User account number |
| symbol | std::string& | Symbol of the underlying position, such as 'AAPL', '00700', 'ES', 'CN' |
| expiry | std::string& | Expiration date. Only options, warrants, CBBCs are supported |
| strike | std::string& | Strike price. Only options, warrants, CBBCs are supported |
| right | std::string& | Only options, warrants, CBBCs are supported |
| identifier | std::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' |
| multiplier | uint32_t | The number of lots, futures, options, warrants, CBBC only |
| action | std::string& | Buy and Sell direction |
| market | std::string& | Market |
| currency | std::string& | Currency |
| segType | std::string& | Segment category |
| secType | std::string& | Type of security |
| orderType | std::string& | Order type.' MKT' Market Order / 'LMT' Limit Order / 'STP' Stop Loss Order / 'STP_LMT' Stop Loss Limit Order / 'TRAIL' Trailing Stop Order |
| isLong | bool | Whether the position is long |
| totalQuantity | int64_t | The number of orders placed |
| totalQuantityScale | int32_t | Offset of the number of orders placed |
| filledQuantity | int64_t | Total quantity of transactions (if the order is divided into multiple transactions, filledQuantity is the cumulative total number of transactions) |
| filledQuantityScale | int32_t | Total number of transactions offset |
| avgFillPrice | double | Average price at which the orders got filled |
| limitPrice | double | Limit price(required when orderType is 'LMT') |
| stopPrice | double | Stop price(required when orderType is 'STP') |
| realizedPnl | double | Realized profit/loss (only consolidated accounts have this field) |
| status | std::string& | Order Status |
| replaceStatus | std::string& | Order change status |
| cancelStatus | std::string& | Order cancel status |
| outsideRth | bool | Whether to allow pre and after hours trading, only for US stocks |
| canModify | bool | Whether order can be modified |
| canCancel | bool | Whether order can be cancelled |
| liquidation | bool | Whether the order is closed |
| name | std::string& | Symbol name |
| source | std::string& | Order source (from 'OpenApi', or other) |
| errorMsg | std::string& | Error message |
| attrDesc | std::string& | Order description |
| commissionAndFee | float | Total commission and fee |
| openTime | uint64_t | Timestamp when the order was placed |
| timestamp | uint64_t | Last update time |
| userMark | std::string& | Remark |
| totalCashAmount | double | total cash amount |
| filledCashAmount | double | filled 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
| Parameter | Type | Description |
|---|---|---|
| account | std::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
| Name | Type | Description |
|---|---|---|
| id | int64_t | Transaction ID |
| order_id | int64_t | Unique order id |
| account | std::string& | User account |
| symbol | std::string& | Stock ticker symbol, exmaple: 'AAPL', '00700', 'ES', 'CN' |
| identifier | std::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' |
| multiplier | uint32_t | Multiplier for options, warrants and CBBC |
| action | std::string& | "BUY" or "SELL" |
| market | std::string& | Market |
| currency | std::string& | Currency |
| segType | std::string& | Segment category |
| secType | std::string& | Type of security |
| filled_price | double | Filled price |
| filled_quantity | int64_t | Filled quantity |
| create_time | uint64_t | Create time |
| update_time | uint64_t | Update time |
| transact_time | uint64_t | Transaction time |
| timestamp | uint64_t | Timestamp |
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,
}
