@@ -455,15 +455,26 @@ void signal_handler(int signal)
455455
456456class TestPushClient {
457457private:
458- // 保存 push_client 实例作为成员变量
459458 std::shared_ptr<IPushClient> push_client;
459+ std::vector<std::string> symbols;
460460
461461public:
462- TestPushClient (std::shared_ptr<IPushClient> client) : push_client(client) {}
462+ TestPushClient (std::shared_ptr<IPushClient> client) : push_client(client) {
463+ std::vector<std::string> hk_option_symbols = {" TCH.HK 20241230 410.00 CALL" };
464+ std::vector<std::string> future_symbols = {" CL2412" };
465+ symbols = future_symbols;
466+ }
463467
464- // 将回调方法改为非静态成员函数
465468 void connected_callback () {
466469 ucout << " Connected to push server" << std::endl;
470+ push_client->subscribe_position (push_client->get_client_config ().account );
471+ push_client->subscribe_order (push_client->get_client_config ().account );
472+ push_client->subscribe_asset (push_client->get_client_config ().account );
473+ // push_client->query_subscribed_symbols();
474+ push_client->subscribe_quote (symbols);
475+ // push_client->subscribe_kline(symbols);
476+ // push_client->subscribe_quote_depth(symbols);
477+ push_client->subscribe_tick (symbols);
467478 }
468479
469480 void position_changed_callback (const tigeropen::push::pb::PositionData& data) {
@@ -473,27 +484,61 @@ class TestPushClient {
473484 }
474485
475486 void order_changed_callback (const tigeropen::push::pb::OrderStatusData& data) {
487+ // example: {"dataType":"OrderStatus","orderStatusData":{"id":"37129891133115200","account":"123123123","symbol":"PDD","identifier":"PDD","multiplier":1,
488+ // "action":"BUY","market":"US","currency":"USD","segType":"S","secType":"STK","orderType":"LMT","isLong":true,"totalQuantity":"1","limitPrice":50,
489+ // "status":"PendingSubmit","replaceStatus":"NONE","cancelStatus":"NONE","outsideRth":true,"canModify":true,"canCancel":true,"name":"PDD Holdings","source":"openapi","openTime":"1732177851000","timestamp":"1732177851874"}}
476490 ucout << " Order changed:" << std::endl;
477491 ucout << " - id: " << data.id () << std::endl;
492+ ucout << " - status: " << data.status () << std::endl;
493+ ucout << " - avgfillprice: " << data.avgfillprice () << std::endl;
478494 }
479495
480496 void asset_changed_callback (const tigeropen::push::pb::AssetData& data) {
497+ // example: {"dataType":"Asset","assetData":{"account":"111111111111","segType":"S","availableFunds":797832.55572773679,
498+ // "excessLiquidity":826227.79308567208,"netLiquidation":944515.55984458746,"equityWithLoan":944494.85984458751,"buyingPower":3191330.2229109472,
499+ // "cashBalance":656046.6059349241,"grossPositionValue":288448.25390966347,"initMarginReq":146662.30411685078,"maintMarginReq":118287.76675891539,"timestamp":"1732177851891"}}
481500 ucout << " Asset changed:" << std::endl;
482501 ucout << " - cashbalance: " << data.cashbalance () << std::endl;
502+ ucout << " - netliquidation: " << data.netliquidation () << std::endl;
483503 }
484504
485505 void tick_changed_callback (const TradeTick& data) {
486506 ucout << " TradeTick changed: " << std::endl;
487507 ucout << " - data: " << data.to_string () << std::endl;
488508 }
489509
510+ void full_tick_changed_callback (const tigeropen::push::pb::TickData& data) {
511+ ucout << " Full TickData changed: " << std::endl;
512+ ucout << " - symbol: " << data.symbol () << std::endl;
513+ ucout << " - tick size: " << data.ticks_size () << std::endl;
514+ }
515+
516+ void query_subscribed_symbols_changed_callback (const tigeropen::push::pb::Response& data) {
517+ ucout << " QuerySubscribedSymbols changed: " << std::endl;
518+ ucout << " - data: " << data.msg () << std::endl;
519+ }
520+
490521 void quote_changed_callback (const tigeropen::push::pb::QuoteBasicData& data) {
491522 ucout << " BasicQuote changed: " << std::endl;
492523 ucout << " - symbol: " << data.symbol () << std::endl;
493524 ucout << " - latestPrice: " << data.latestprice () << std::endl;
494525 ucout << " - volume: " << data.volume () << std::endl;
495526 }
496527
528+ void quote_bbo_changed_callback (const tigeropen::push::pb::QuoteBBOData& data) {
529+ ucout << " BBOQuote changed: " << std::endl;
530+ ucout << " - symbol: " << data.symbol () << std::endl;
531+ ucout << " - bidPrice: " << data.bidprice () << std::endl;
532+ ucout << " - askPrice: " << data.askprice () << std::endl;
533+ }
534+
535+ void quote_depth_changed_callback (const tigeropen::push::pb::QuoteDepthData& data) {
536+ ucout << " QuoteDepth changed: " << std::endl;
537+ ucout << " - symbol: " << data.symbol () << std::endl;
538+ ucout << " - ask price size: " << data.ask ().price_size () << std::endl;
539+ ucout << " - bid price size: " << data.bid ().price_size () << std::endl;
540+ }
541+
497542 void kline_changed_callback (const tigeropen::push::pb::KlineData& data) {
498543 ucout << " Kline changed: " << std::endl;
499544 ucout << " - symbol: " << data.symbol () << std::endl;
@@ -503,27 +548,21 @@ class TestPushClient {
503548 ucout << " - close: " << data.close () << std::endl;
504549 }
505550
506- void start_test () {
507- push_client->connect ();
508-
509- // sleep 10 seconds
510- std::this_thread::sleep_for (std::chrono::seconds (10 ));
511-
512- // 使用 std::bind 绑定成员函数
551+ void start_test (ClientConfig config) {
513552 push_client->set_connected_callback (std::bind (&TestPushClient::connected_callback, this ));
514553 push_client->set_position_changed_callback (std::bind (&TestPushClient::position_changed_callback, this , std::placeholders::_1));
515554 push_client->set_order_changed_callback (std::bind (&TestPushClient::order_changed_callback, this , std::placeholders::_1));
516555 push_client->set_asset_changed_callback (std::bind (&TestPushClient::asset_changed_callback, this , std::placeholders::_1));
517556 push_client->set_tick_changed_callback (std::bind (&TestPushClient::tick_changed_callback, this , std::placeholders::_1));
557+ push_client->set_full_tick_changed_callback (std::bind (&TestPushClient::full_tick_changed_callback, this , std::placeholders::_1));
558+ push_client->set_query_subscribed_symbols_changed_callback (std::bind (&TestPushClient::query_subscribed_symbols_changed_callback, this , std::placeholders::_1));
518559 push_client->set_quote_changed_callback (std::bind (&TestPushClient::quote_changed_callback, this , std::placeholders::_1));
560+ push_client->set_quote_bbo_changed_callback (std::bind (&TestPushClient::quote_bbo_changed_callback, this , std::placeholders::_1));
561+ push_client->set_quote_depth_changed_callback (std::bind (&TestPushClient::quote_depth_changed_callback, this , std::placeholders::_1));
519562 push_client->set_kline_changed_callback (std::bind (&TestPushClient::kline_changed_callback, this , std::placeholders::_1));
520- push_client->subscribe_position (" " );
521- push_client->subscribe_order (" " );
522- push_client->subscribe_asset (" " );
523563
524- std::vector<std::string> symbols = {" NVDA" , " 00700" };
525- push_client->subscribe_tick (symbols);
526- push_client->subscribe_quote (symbols);
564+
565+ push_client->connect ();
527566
528567 std::signal (SIGINT, signal_handler); // Ctrl+C
529568 std::signal (SIGTERM, signal_handler); // kill
@@ -532,12 +571,19 @@ class TestPushClient {
532571 std::this_thread::sleep_for (std::chrono::seconds (1 ));
533572 }
534573
574+ push_client->unsubscribe_quote (symbols);
575+ push_client->unsubscribe_kline (symbols);
576+ push_client->unsubscribe_quote_depth (symbols);
577+ push_client->unsubscribe_tick (symbols);
578+ push_client->unsubscribe_asset (config.account );
579+ push_client->unsubscribe_position (config.account );
580+ push_client->unsubscribe_order (config.account );
535581 push_client->disconnect ();
536582 }
537583
538- static void test_push_client (std::shared_ptr<IPushClient> push_client) {
584+ static void test_push_client (std::shared_ptr<IPushClient> push_client, ClientConfig config ) {
539585 TestPushClient test (push_client);
540- test.start_test ();
586+ test.start_test (config );
541587 }
542588};
543589
@@ -551,35 +597,18 @@ int main()
551597 // config.tiger_id = U("");
552598 // config.account = U("");
553599
554-
600+ config. use_full_tick = true ;
555601
556602#else
557603 config.private_key = U("");
558604 config.tiger_id = U("");
559605 config.account = U("");
560606 #endif
561607
562-
563-
564- // std::string input;
565- // while (true)
566- // {
567- // std::cout << "Enter command (type 'exit' to quit): ";
568- // std::getline(std::cin, input);
569- //
570- // if (input == "exit") {
571- // std::cout << "Exiting loop." << std::endl;
572- // // push_client->disconnect();
573- // break;
574- // }
575- // // Process other commands or input here
576- // std::cout << "You entered: " << input << std::endl;
577- // }
578-
579608 // config.lang = U("en_US");
580609
581610 auto push_client = IPushClient::create_push_client (config);
582- TestPushClient::test_push_client (push_client);
611+ TestPushClient::test_push_client (push_client, config );
583612 /* *
584613 * QuoteClient
585614 */
0 commit comments