其他
大约 2 分钟
连接成功
virtual void set_connected_callback(const std::function<void()>& cb) = 0;
说明
连接成功的回调
示例
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;
}
void start_test(ClientConfig config) {
push_client->set_connected_callback(std::bind(&TestPushClient::connected_callback, this));
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->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";
//enable full tick
config.use_full_tick = true;
auto push_client = IPushClient::create_push_client(config);
TestPushClient::test_push_client(push_client, config);
断开连接
virtual void set_disconnected_callback(const std::function<void()>& cb) = 0;
说明
连接断开的回调
示例
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 disconnected_callback() {
ucout << "Successfully disconnected" << std::endl;
}
void start_test(ClientConfig config) {
push_client->set_disconnected_callback(std::bind(&TestPushClient::disconnected_callback, this));
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->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";
//enable full tick
config.use_full_tick = true;
auto push_client = IPushClient::create_push_client(config);
TestPushClient::test_push_client(push_client, config);
连接出错
virtual void set_error_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) = 0;
说明
连接出错的回调
示例
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 error_callback(const tigeropen::push::pb::Response& data) {
ucout << "Error callback: " << std::endl;
ucout << "- code: " << data.code() << std::endl;
ucout << "- msg: " << utility::conversions::to_string_t(data.msg()) << std::endl;
}
void start_test(ClientConfig config) {
push_client->set_error_callback(std::bind(&TestPushClient::error_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->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";
//enable full tick
config.use_full_tick = true;
auto push_client = IPushClient::create_push_client(config);
TestPushClient::test_push_client(push_client, config);