Other Push Events
This page documents connection events and request-result callbacks. See Client Lifecycle for client creation, connection, disconnection, and heartbeat handling.
Connection Established
void IPushClient::set_connected_callback(const std::function<void()> &cb)Registers a no-argument callback that runs after the TLS handshake and authentication frame are sent. It does not wait for server authentication and does not confirm any subscription. It runs again after automatic reconnect, but the SDK does not restore previous subscriptions.
push_client->set_connected_callback([]() { std::cout << "connected\n"; });Connection Closed
void IPushClient::set_disconnected_callback(const std::function<void()> &cb)Registers a no-argument disconnection callback. Do not destroy the client from a callback executing on its worker thread.
push_client->set_disconnected_callback([]() { std::cout << "disconnected\n"; });Transport Error
void IPushClient::set_inner_error_callback(
const std::function<void(std::string)> &cb)Receives transport-level string errors. This is the only error callback that accepts std::string.
push_client->set_inner_error_callback([](std::string message) {
std::cerr << message << '\n';
});Subscription Result
void IPushClient::set_subscribe_callback(
const std::function<void(const tigeropen::push::pb::Response&)> &cb)Receives asynchronous subscription-completion responses. A subscription method immediately returns a locally assigned request ID; Response.id() correlates the response with that ID. Outer Response.code() is 112, which identifies completion of subscribe processing rather than business success. Response.msg() is normally JSON containing the business code and message, but exception paths may return plain text. Only successfully parsed JSON with an inner code == 0 confirms success. Returning an ID does not mean the subscription succeeded and the ID is not a market-data sequence number.
#include "cpprest/json.h"
unsigned int pending_id = 0;
push_client->set_subscribe_callback([&](const tigeropen::push::pb::Response& response) {
if (response.id() == pending_id) {
try {
const auto result = web::json::value::parse(
utility::conversions::to_string_t(response.msg()));
std::cout << "business code: " << result.at(U("code")).as_integer()
<< ", message: " << response.msg() << '\n';
} catch (const web::json::json_exception&) {
std::cerr << "subscription error: " << response.msg() << '\n';
}
}
});
pending_id = push_client->subscribe_quote({"AAPL"});Response fields
| Field/accessor | Protobuf type | Description |
|---|---|---|
command() | SocketCommon.Command | Response command |
id() | uint32 | Request ID correlated with the method return value |
code() | int32 | Protocol response type; 112 for subscribe completion and 113 for unsubscribe completion |
msg() | string | Normally a JSON business result, but exception paths may return plain text; inner JSON code == 0 indicates success |
body() | PushData | Optional response body |
The callback exposes these Protobuf fields. Optional values depend on the response; inspect the callback object before reading body().
Unsubscription Result
void IPushClient::set_unsubscribe_callback(
const std::function<void(const tigeropen::push::pb::Response&)> &cb)Uses the same correlation semantics: match Response.id() to the request ID returned by the unsubscribe method and parse the inner business code in Response.msg(). Outer Response.code() == 113 only identifies completion of unsubscribe processing.
push_client->set_unsubscribe_callback([](const tigeropen::push::pb::Response& response) {
std::cout << response.id() << " " << response.code() << '\n';
});
const unsigned int request_id = push_client->unsubscribe_quote({"AAPL"});Server Error
void IPushClient::set_error_callback(
const std::function<void(const tigeropen::push::pb::Response&)> &cb)Receives protocol/server errors. The callback parameter is Response; inspect Response.id(), code(), and msg().
push_client->set_error_callback([](const tigeropen::push::pb::Response& response) {
std::cerr << response.id() << " " << response.code() << " " << response.msg() << '\n';
});Connection Replaced
void IPushClient::set_kickout_callback(
const std::function<void(const tigeropen::push::pb::Response&)> &cb)Receives the protocol response when a newer session replaces this connection. The callback parameter is Response.
push_client->set_kickout_callback([](const tigeropen::push::pb::Response& response) {
std::cerr << "kickout: " << response.msg() << '\n';
});Subscribed-Symbol Query Result
void IPushClient::set_query_subscribed_symbols_changed_callback(
const std::function<void(
const tigeropen::push::pb::Response& query_subscribed_symbols_response)> &cb)Use with query_subscribed_symbols(). The method returns a request ID, Response.id() correlates the result, and the subscription data is in the response body.
push_client->set_query_subscribed_symbols_changed_callback(
[](const tigeropen::push::pb::Response& response) {
std::cout << response.id() << " " << response.body().DebugString();
});
const unsigned int request_id = push_client->query_subscribed_symbols();Heartbeat
void IPushClient::set_heartbeat_callback(const std::function<void()> &cb)Registers a no-argument callback for received heartbeats. Use it for connection-health observation, not as a replacement for the disconnection callback.
push_client->set_heartbeat_callback([]() { std::cout << "heartbeat\n"; });Permissions and Limits
Callbacks execute asynchronously; captured objects must outlive callback execution. Request IDs correlate messages only within this client connection. Market streams require the relevant market data access, while account streams require account access permission. Runtime subscription registration is separate and remains subject to the applicable symbol quota and frequency limits.
Updated about 1 month ago
