Skip to content

Commit dd780d7

Browse files
committed
kickout callback
1 parent a878220 commit dd780d7

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,19 @@ class TestPushClient {
469469
push_client->subscribe_tick(symbols);
470470
}
471471

472+
void error_callback(const tigeropen::push::pb::Response& data) {
473+
ucout << "Error callback: " << std::endl;
474+
ucout << "- code: " << data.code() << std::endl;
475+
ucout << "- msg: " << utility::conversions::to_string_t(data.msg()) << std::endl;
476+
}
477+
478+
void kickout_callback(const tigeropen::push::pb::Response& data) {
479+
ucout << "Kickout callback: " << std::endl;
480+
ucout << "- code: " << data.code() << std::endl;
481+
ucout << "- msg: " << utility::conversions::to_string_t(data.msg()) << std::endl;
482+
483+
}
484+
472485
void position_changed_callback(const tigeropen::push::pb::PositionData& data) {
473486
ucout << "Position changed:" << std::endl;
474487
ucout << "- symbol: " << utility::conversions::to_string_t(data.symbol()) << std::endl;
@@ -542,6 +555,8 @@ class TestPushClient {
542555

543556
void start_test(ClientConfig config) {
544557
push_client->set_connected_callback(std::bind(&TestPushClient::connected_callback, this));
558+
push_client->set_error_callback(std::bind(&TestPushClient::error_callback, this, std::placeholders::_1));
559+
push_client->set_kickout_callback(std::bind(&TestPushClient::kickout_callback, this, std::placeholders::_1));
545560
push_client->set_position_changed_callback(std::bind(&TestPushClient::position_changed_callback, this, std::placeholders::_1));
546561
push_client->set_order_changed_callback(std::bind(&TestPushClient::order_changed_callback, this, std::placeholders::_1));
547562
push_client->set_asset_changed_callback(std::bind(&TestPushClient::asset_changed_callback, this, std::placeholders::_1));
@@ -579,11 +594,29 @@ class TestPushClient {
579594
}
580595
};
581596

582-
int main()
583-
{
597+
int main(int argc, char* argv[]) {
598+
// // 初始化日志
599+
// START_EASYLOGGINGPP(argc, argv);
600+
//
601+
// 配置日志
602+
el::Configurations defaultConf;
603+
defaultConf.setToDefault();
604+
605+
// 只显示WARNING和ERROR级别的日志
606+
defaultConf.set(el::Level::Global, el::ConfigurationType::Enabled, "true");
607+
defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "false");
608+
defaultConf.set(el::Level::Info, el::ConfigurationType::Enabled, "true");
609+
defaultConf.set(el::Level::Warning, el::ConfigurationType::Enabled, "true");
610+
defaultConf.set(el::Level::Error, el::ConfigurationType::Enabled, "true");
611+
612+
// 应用配置
613+
el::Loggers::reconfigureLogger("default", defaultConf);
614+
584615
//Set Tiger OpenAPI SDK configuration
585616
bool sand_box = false;
586617
ClientConfig config = ClientConfig(false, U("../openapi_cpp_test/"));
618+
// config.set_server_url(U("http://127.0.0.1:8085/gateway"));
619+
// config.set_server_public_key(SANDBOX_TIGER_PUBLIC_KEY);
587620
// config.private_key = U("");
588621
// config.tiger_id = U("");
589622
// config.account = U("");
@@ -593,13 +626,13 @@ int main()
593626
//Create a push client instance
594627
auto push_client = IPushClient::create_push_client(config);
595628
//Run some push test cases
596-
// TestPushClient::test_push_client(push_client, config);
629+
TestPushClient::test_push_client(push_client, config);
597630

598631
/**
599632
* QuoteClient
600633
*/
601-
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
602-
TestQuoteClient::test_quote(quote_client);
634+
// std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
635+
// TestQuoteClient::test_quote(quote_client);
603636

604637
/**
605638
* TradeClient

include/tigerapi/client_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ namespace TIGER_API {
103103
this->socket_port = port;
104104
}
105105

106+
void set_server_public_key(const utility::string_t &key) {
107+
this->server_public_key = key;
108+
}
109+
106110
const utility::string_t& get_server_url() {
107111
return this->server_url;
108112
}

include/tigerapi/push_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace TIGER_API
4343
virtual void set_subscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) = 0;
4444
virtual void set_unsubscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) = 0;
4545
virtual void set_error_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) = 0;
46+
virtual void set_kickout_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) = 0;
4647

4748
virtual void set_asset_changed_callback(const std::function<void(const tigeropen::push::pb::AssetData&)>& cb) = 0;
4849
virtual bool subscribe_asset(const std::string& account) = 0;

include/tigerapi/push_socket/push_client_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ namespace TIGER_API
2929

3030
virtual void set_subscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
3131
virtual void set_unsubscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
32-
virtual void set_error_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
33-
32+
virtual void set_error_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb ) override;
33+
virtual void set_kickout_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb) override;
34+
3435
virtual void set_asset_changed_callback(const std::function<void(const tigeropen::push::pb::AssetData&)>& cb) override;
3536
virtual bool subscribe_asset(const std::string& account) override;
3637
virtual bool unsubscribe_asset(const std::string& account) override;
@@ -97,6 +98,7 @@ namespace TIGER_API
9798
std::function<void(const tigeropen::push::pb::Response& subscribe_response)> subscribe_callback_;
9899
std::function<void(const tigeropen::push::pb::Response& unsubscribe_response)> unsubscribe_callback_;
99100
std::function<void(const tigeropen::push::pb::Response& error_response)> error_callback_;
101+
std::function<void(const tigeropen::push::pb::Response& kickout_response)> kickout_callback_;
100102
std::function<void(const tigeropen::push::pb::AssetData& asset_data)> asset_changed_;
101103
std::function<void(const tigeropen::push::pb::PositionData& position_data)> position_changed_;
102104
std::function<void(const tigeropen::push::pb::OrderStatusData& order_status_data)> order_changed_;

src/push_socket/push_client_impl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ void TIGER_API::PushClientImpl::set_inner_error_callback(const std::function<voi
7373
}
7474
}
7575

76+
void TIGER_API::PushClientImpl::set_kickout_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb)
77+
{
78+
kickout_callback_ = cb;
79+
}
80+
7681
void TIGER_API::PushClientImpl::set_subscribe_callback(const std::function<void(const tigeropen::push::pb::Response&)>& cb)
7782
{
7883
subscribe_callback_ = cb;
@@ -378,6 +383,16 @@ void TIGER_API::PushClientImpl::on_message(const std::shared_ptr<tigeropen::push
378383
else if (frame->command() == tigeropen::push::pb::SocketCommon_Command_HEARTBEAT) {
379384
LOG(DEBUG) << "heartbeat";
380385
}
386+
else if (frame->command() == tigeropen::push::pb::SocketCommon_Command_ERRORINFO) {
387+
if (frame->code() == 4001 && kickout_callback_) {
388+
kickout_callback_(*frame);
389+
}
390+
else if (error_callback_) {
391+
error_callback_(*frame);
392+
} else {
393+
LOG(ERROR) << frame->DebugString();
394+
}
395+
}
381396
else if (frame->code() == static_cast<int>(ResponseType::GET_SUB_SYMBOLS_END)) {
382397
if (query_subscribed_symbols_changed_) {
383398
query_subscribed_symbols_changed_(*frame);

0 commit comments

Comments
 (0)