Quote Push

Quote Push Subscription

The C++ SDK implements quote push subscription through IPushClient. Push uses the Protobuf protocol for data transmission, and callback functions are triggered asynchronously.

Initialize Push Client

#include "tigerapi/push_client.h"
#include "tigerapi/client_config.h"

using namespace TIGER_API;

ClientConfig config(false, U("/path/to/your/properties/"));
auto push_client = IPushClient::create_push_client(config);

// Set connected/disconnected callbacks
push_client->set_connected_callback([]() {
    std::cout << "Connected" << std::endl;
});

push_client->set_disconnected_callback([]() {
    std::cout << "Disconnected" << std::endl;
});

// Set error callback
push_client->set_inner_error_callback([](std::string err) {
    std::cout << "Error: " << err << std::endl;
});

// Establish connection
push_client->connect();

subscribe_quote Subscribe to Stock Quotes

unsigned int IPushClient::subscribe_quote(const std::vector<std::string> &symbols)

Description

Subscribe to real-time stock quote push

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesSymbol code list

Callback Setup

Use set_quote_changed_callback to set quote change callback:

push_client->set_quote_changed_callback([](const tigeropen::push::pb::QuoteBasicData& data) {
    std::cout << "Symbol: " << data.symbol()
              << " Price: " << data.latestprice()
              << " Volume: " << data.volume()
              << std::endl;
});

Example

std::vector<std::string> symbols = {"AAPL", "TSLA"};
push_client->subscribe_quote(symbols);

unsubscribe_quote Unsubscribe from Stock Quotes

unsigned int IPushClient::unsubscribe_quote(const std::vector<std::string> &symbols)

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesSymbol code list

subscribe_future_quote Subscribe to Futures Quotes

unsigned int IPushClient::subscribe_future_quote(const std::vector<std::string> &symbols)

Description

Subscribe to real-time futures quote push. Uses the same set_quote_changed_callback as stock quotes.

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesFutures contract code list, e.g., CL2312

subscribe_option_quote Subscribe to Option Quotes

unsigned int IPushClient::subscribe_option_quote(const std::vector<std::string> &symbols)

Description

Subscribe to real-time option quote push

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesOption identifier list

subscribe_quote_depth Subscribe to Depth Quotes

unsigned int IPushClient::subscribe_quote_depth(const std::vector<std::string> &symbols)

Description

Subscribe to depth quote (order book) push

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesSymbol code list

Callback Setup

push_client->set_quote_depth_changed_callback([](const tigeropen::push::pb::QuoteDepthData& data) {
    std::cout << "Depth data received" << std::endl;
});

unsubscribe_quote_depth Unsubscribe from Depth Quotes

unsigned int IPushClient::unsubscribe_quote_depth(const std::vector<std::string> &symbols)


subscribe_kline Subscribe to K-line

unsigned int IPushClient::subscribe_kline(const std::vector<std::string> &symbols)

Description

Subscribe to K-line data push

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesSymbol code list

Callback Setup

push_client->set_kline_changed_callback([](const tigeropen::push::pb::KlineData& data) {
    std::cout << "Kline data received" << std::endl;
});

unsubscribe_kline Unsubscribe from K-line

unsigned int IPushClient::unsubscribe_kline(const std::vector<std::string> &symbols)


subscribe_tick Subscribe to Trade Ticks

unsigned int IPushClient::subscribe_tick(const std::vector<std::string> &symbols)

Description

Subscribe to tick-by-tick trade data push

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesSymbol code list

Callback Setup

// Using TradeTick object callback
push_client->set_tick_changed_callback([](const TradeTick& data) {
    std::cout << "Symbol: " << data.symbol << " ticks: " << data.ticks.size() << std::endl;
});

// Or using full Protobuf TickData callback
push_client->set_full_tick_changed_callback([](const tigeropen::push::pb::TickData& data) {
    std::cout << "Full tick data received" << std::endl;
});

unsubscribe_tick Unsubscribe from Trade Ticks

unsigned int IPushClient::unsubscribe_tick(const std::vector<std::string> &symbols)


subscribe_market Subscribe to Entire Market

unsigned int IPushClient::subscribe_market(const std::string &market)

Description

Subscribe to quote push for the entire market

Parameters

ParameterTypeRequiredDescription
marketstringYesMarket, e.g., "US", "HK"

unsubscribe_market Unsubscribe from Entire Market

unsigned int IPushClient::unsubscribe_market(const std::string &market)


subscribe_stock_top Subscribe to Stock Rankings

unsigned int IPushClient::subscribe_stock_top(const std::string &market, const std::vector<std::string> &indicators)

Description

Subscribe to stock ranking data push

Parameters

ParameterTypeRequiredDescription
marketstringYesMarket, e.g., "US", "HK"
indicatorsvector<string>NoRanking indicator list, default empty

Callback Setup

push_client->set_stock_top_changed_callback([](const tigeropen::push::pb::StockTopData& data) {
    std::cout << "Stock top data received" << std::endl;
});

subscribe_option_top Subscribe to Option Rankings

unsigned int IPushClient::subscribe_option_top(const std::string &market, const std::vector<std::string> &indicators)

Description

Subscribe to option ranking data push

Parameters

ParameterTypeRequiredDescription
marketstringYesMarket
indicatorsvector<string>NoRanking indicator list

Callback Setup

push_client->set_option_top_changed_callback([](const tigeropen::push::pb::OptionTopData& data) {
    std::cout << "Option top data received" << std::endl;
});

subscribe_cc Subscribe to Cryptocurrency Quotes

unsigned int IPushClient::subscribe_cc(const std::vector<std::string> &symbols)

Description

Subscribe to real-time cryptocurrency quote push

Parameters

ParameterTypeRequiredDescription
symbolsvector<string>YesCryptocurrency symbol list

unsubscribe_cc Unsubscribe from Cryptocurrency Quotes

unsigned int IPushClient::unsubscribe_cc(const std::vector<std::string> &symbols)


query_subscribed_symbols Query Subscribed Symbols

unsigned int IPushClient::query_subscribed_symbols()

Description

Query the list of all currently subscribed symbols

Callback Setup

push_client->set_query_subscribed_symbols_changed_callback([](const tigeropen::push::pb::Response& resp) {
    std::cout << "Subscribed symbols: " << resp.DebugString() << std::endl;
});

push_client->query_subscribed_symbols();

Full Example

#include <iostream>
#include <thread>
#include <chrono>
#include "tigerapi/push_client.h"
#include "tigerapi/client_config.h"

using namespace TIGER_API;

int main() {
    ClientConfig config(false, U("/path/to/your/properties/"));
    auto push_client = IPushClient::create_push_client(config);

    // Connection callbacks
    push_client->set_connected_callback([]() {
        std::cout << "Connected" << std::endl;
    });

    push_client->set_disconnected_callback([]() {
        std::cout << "Disconnected" << std::endl;
    });

    // Subscribe success/failure callback
    push_client->set_subscribe_callback([](const tigeropen::push::pb::Response& resp) {
        std::cout << "Subscribe result: " << resp.DebugString() << std::endl;
    });

    // Quote change callback
    push_client->set_quote_changed_callback([](const tigeropen::push::pb::QuoteBasicData& data) {
        std::cout << "Symbol: " << data.symbol()
                  << " Price: " << data.latestprice()
                  << std::endl;
    });

    // Tick-by-tick trade callback
    push_client->set_tick_changed_callback([](const TradeTick& data) {
        std::cout << "Tick: " << data.symbol << " count: " << data.ticks.size() << std::endl;
    });

    // Connect
    push_client->connect();

    // Subscribe
    std::vector<std::string> symbols = {"AAPL", "TSLA"};
    push_client->subscribe_quote(symbols);
    push_client->subscribe_tick(symbols);

    // Wait for push data
    std::this_thread::sleep_for(std::chrono::seconds(60));

    // Unsubscribe and disconnect
    push_client->unsubscribe_quote(symbols);
    push_client->unsubscribe_tick(symbols);
    push_client->disconnect();

    return 0;
}