行情变动

大约 12 分钟

订阅行情

订阅方法

virtual bool subscribe_quote(const std::vector<std::string>& symbols) = 0

取消方法

virtual bool unsubscribe_quote(const std::vector<std::string>& symbols) = 0;

说明

股票行情的订阅与取消接口,返回的数据为实时更新,即每次价格或挂单数据更新就会有数据推送 回调接口返回结果类型为基本行情 QuoteBasicData 对象, 最优报价 QuoteBBOData 对象

本接口为异步返回,使用push_client->set_quote_changed_callback 响应基本行情 QuoteBasicData 对象; 使用 push_client->set_quote_bbo_changed_callback 响应最优报价 QuoteBBOData 对象

参数

参数名类型描述
symbolsstd::vector<std::string>List of securities codes, e.g. ['AAPL', 'BABA'], English codes should be in upper case

返回数据

CAUTION

股票行情回调数据有两种类型:交易数据和盘口数据,两种类型数据返回的字段不一样

示例

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;
        push_client->subscribe_quote(symbols);
    }
    
    void quote_changed_callback(const tigeropen::push::pb::QuoteBasicData& data) {
        ucout << "BasicQuote changed: " << std::endl;
        ucout << "- symbol: " << utility::conversions::to_string_t(data.symbol()) << std::endl;
        ucout << "- latestPrice: " << data.latestprice() << std::endl;
        ucout << "- volume: " << data.volume() << std::endl;
    }

    void quote_bbo_changed_callback(const tigeropen::push::pb::QuoteBBOData& data) {
        ucout << "BBOQuote changed: " << std::endl;
        ucout << "- symbol: " << utility::conversions::to_string_t(data.symbol()) << std::endl;
        ucout << "- bidPrice: " << data.bidprice() << std::endl;
        ucout << "- askPrice: " << data.askprice() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_quote_changed_callback(std::bind(&TestPushClient::quote_changed_callback, this, std::placeholders::_1));
        push_client->set_quote_bbo_changed_callback(std::bind(&TestPushClient::quote_bbo_changed_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->unsubscribe_quote(symbols);
        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";
    
    auto push_client = IPushClient::create_push_client(config);
    TestPushClient::test_push_client(push_client, config);

回调数据示例

symbol: "00700"
type: BASIC
timestamp: 1677742483530
serverTimestamp: 1677742483586
avgPrice: 365.37
latestPrice: 363.8
latestPriceTimestamp: 1677742483369
latestTime: "03-02 15:34:43"
preClose: 368.8
volume: 12674730
amount: 4630947968
open: 368.2
high: 369
low: 362.4
marketStatus: "Trading"
mi {
  p: 363.8
  a: 365.37
  t: 1677742440000
  v: 27300
  h: 364
  l: 363.6
}

/include/openapi_pb/pb_source/QuoteBBOData.pb.h 数据示例:

symbol: "01810"
type: BBO
timestamp: 1677741267291
serverTimestamp: 1677741267329
askPrice: 12.54
askSize: 397600
askTimestamp: 1677741266304
bidPrice: 12.52
bidSize: 787400
bidTimestamp: 1677741266916

订阅深度行情

订阅方法virtual bool subscribe_quote_depth(const std::vector<std::string>& symbols) = 0;

取消方法

virtual bool unsubscribe_quote_depth(const std::vector<std::string>& symbols) = 0;

说明

订阅深度行情,只支持美股和港股的股票,美股期权和期货 。美股深度行情推送频率为300ms,港股深度行情推送频率为2s,返回最高40档的买卖盘挂单数据, 返回的数据为实时更新,即挂单数据更新就会有数据推送。 本接口为异步返回,使用push_client->set_quote_depth_changed_callback 响应深度行情 QuoteDepthData (/include/openapi_pb/pb_source/QuoteDepthData.pb.h) 对象;

参数

参数名类型描述
symbolsconst std::vector<std::string>证券代码列表,如 ['AAPL', 'BABA']

示例

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;
        push_client->subscribe_quote_depth(symbols);
    }
    
    void quote_depth_changed_callback(const tigeropen::push::pb::QuoteDepthData& data) {
        ucout << "QuoteDepth changed: " << std::endl;
        ucout << "- symbol: " << utility::conversions::to_string_t(data.symbol()) << std::endl;
        ucout << "- ask price size: " << data.ask().price_size() << std::endl;
        ucout << "- bid price size: " << data.bid().price_size() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_quote_depth_changed_callback(std::bind(&TestPushClient::quote_depth_changed_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->unsubscribe_quote_depth(symbols);
        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";
    
    auto push_client = IPushClient::create_push_client(config);
    TestPushClient::test_push_client(push_client, config);

回调数据

CAUTION

此接口最多只会推送买卖前 40 档数据

数据结构如下:

参数名类型描述
symbolstd::string&股票标的
timestampuint_64深度数据时间
askOrderBook卖盘数据
bidOrderBook买盘数据

OrderBook的数据结构如下:

参数名类型描述
pricedouble每档价格
volumeint64_t挂单量
orderCountuint32_t订单数(只有港股有)
exchangestd::string&交易所
timeint64_t期权交易所挂单时间戳只有期权有值

回调数据示例

深度行情 items 数据示例,相邻档位价格可能一样, 其中 count 是可选的

symbol: "00700"
timestamp: 1677742734822
ask {
  price: 363.8
  price: 364
  price: 364.2
  price: 364.4
  price: 364.6
  price: 364.8
  price: 365
  price: 365.2
  price: 365.4
  price: 365.6
  volume: 26900
  volume: 14800
  volume: 15200
  volume: 31500
  volume: 15800
  volume: 7700
  volume: 29400
  volume: 6300
  volume: 6000
  volume: 5500
  orderCount: 27
  orderCount: 20
  orderCount: 19
  orderCount: 22
  orderCount: 14
  orderCount: 10
  orderCount: 20
  orderCount: 12
  orderCount: 10
  orderCount: 11
}
bid {
  price: 363.6
  price: 363.4
  price: 363.2
  price: 363
  price: 362.8
  price: 362.6
  price: 362.4
  price: 362.2
  price: 362
  price: 361.8
  volume: 9400
  volume: 19900
  volume: 35300
  volume: 74200
  volume: 26300
  volume: 16700
  volume: 22500
  volume: 21100
  volume: 40500
  volume: 5600
  orderCount: 16
  orderCount: 23
  orderCount: 36
  orderCount: 79
  orderCount: 30
  orderCount: 32
  orderCount: 31
  orderCount: 34
  orderCount: 143
  orderCount: 26
}


订阅逐笔成交数据

订阅方法virtual bool subscribe_tick(const std::vector<std::string>& symbols) = 0;

取消方法

virtual bool unsubscribe_tick(const std::vector<std::string>& symbols) = 0;

说明

逐笔成交订阅推送接口是异步接口,通过实现 push_client->subscribe_tick 接口可以获得异步请求结果。 由于tick数据需要处理压缩格式,回调数据类型与其他行情不同,不是原始的protobuf类型,而是转换后的 /include/openapi_pb/pb_source/TradeTickData.pb.h TickData 股票和期货均使用该方法。

同时,修改配置 client_config.use_full_tick = true, 开启全量 tick 模式, 并在 PushClient 初始化时传入 client_config=client_config

逐笔推送频率为200ms,采用快照方式推送,每次推送最新的50条逐笔记录.

参数

参数名类型描述
symbolsconst std::vector<std::string>证券代码列表,如 ['AAPL', 'BABA']

示例

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;
        push_client->subscribe_tick(symbols);
    }
    
    void tick_changed_callback(const TradeTick& data) {
        ucout << "TradeTick changed: " << std::endl;
        ucout << "- data: " << utility::conversions::to_string_t(data.to_string()) << std::endl;
    }
    
    void full_tick_changed_callback(const tigeropen::push::pb::TickData& data) {
        ucout << "Full TickData changed: " << std::endl;
        ucout << "- symbol: " << utility::conversions::to_string_t(data.symbol()) << std::endl;
        ucout << "- tick size: " << data.ticks_size() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_tick_changed_callback(std::bind(&TestPushClient::tick_changed_callback, this, std::placeholders::_1));
        push_client->set_full_tick_changed_callback(std::bind(&TestPushClient::full_tick_changed_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->unsubscribe_tick(symbols);
        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);

回调数据 TradeTick数据结构如下:

参数名类型描述
symbolstd::string&股票标的、期货标的
typestd::string&STK/FUT
condstd::string&
snint64_t
priceBaseint64_t
priceOffsetint32_t
timeint64_t
priceint64_t
volumeint64_t
partCodestd::string&
quoteLevelstd::string&数据来自的行情权限级别(对于美股,usQuoteBasic的逐笔数据量比usStockQuote的要少);期货没有级别区分
timestampuint64_t数据时间戳
secTypestd::string&
mergedVolsTradeTickData.MergedVol

ticks的数据结构如下:

参数名类型描述
snint64_t逐笔序号
timeint64_t交易时间戳
pricefloat成交价
volumeint32_t成交量
typestd::string&*表示无变化,+表示上涨,-表示下跌(期货不可用)
condstd::string&每笔数据的成交条件列表,如果为空表示为自动对盘成交
partCodestd::string&每笔交易的交易所code(仅美股股票)

回调数据示例

symbol: "NVDA"
ticks {
  sn: 2381
  time: 1712669401076
  price: 874.1
  volume: 10
  type: "*"
  partCode: "t"
}
ticks {
  sn: 2382
  time: 1712669401076
  price: 874.1
  volume: 11
  type: "*"
  partCode: "t"
}
ticks {
  sn: 2383
  time: 1712669401076
  price: 874.1
  volume: 3
  type: "*"
  partCode: "t"
}
timestamp: 1712669403808
source: "NLS"

查询已订阅的标的列表

virtual void query_subscribed_symbols() = 0;

说明 查询已订阅的标的列表

本接口为异步返回, 需要使用push_client->set_query_subscribed_symbols_changed_callback响应返回结果

参数

回调数据

回调数据结构如下:

FieldTypeDescription
limit订阅行情标的(股票、期权、期货)限制最大数
used已订阅行情标的(股票、期权、期货)数
tradeTickLimit订阅逐笔成交股票限制最大数
tradeTickUsed已订阅逐笔成交股票数
askBidLimit订阅深度行情股票限制最大数
askBidUsed已订阅深度行情股票数
klineLimit
klineUsed
subscribedSymbols已订阅行情标的(股票、期权、期货)标的
subscribedTradeTickSymbols已订阅逐笔成交股票标的
subscribedAskBidSymbols已订阅深度行情股票标的
subscribedMarketQuote
subscribedKlineSymbols

示例

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;
        push_client->subscribe_quote(symbols);
    }

    void query_subscribed_symbols_changed_callback(const tigeropen::push::pb::Response& data) {
        ucout << "QuerySubscribedSymbols changed: " << std::endl;
        ucout << "- data: " << utility::conversions::to_string_t(data.msg()) << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_query_subscribed_symbols_changed_callback(std::bind(&TestPushClient::query_subscribed_symbols_changed_callback, this, std::placeholders::_1));
        push_client->set_position_changed_callback(std::bind(&TestPushClient::position_changed_callback, this, std::placeholders::_1));
        push_client->set_asset_changed_callback(std::bind(&TestPushClient::asset_changed_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->unsubscribe_quote(symbols)
        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);

回调数据示例

{
  "limit":2000,
  "used":40,
  "tradeTickLimit":2000,
  "tradeTickUsed":2,
  "askBidLimit":500,
  "askBidUsed":2,
  "klineLimit":2000,
  "klineUsed":2,
  "subscribedSymbols":
  [
    "AAPL","09939","09618","01810","TSLA","META","QRTEP","00992","03988","08437","TSM","09888","03022","XOM","A","AVGO",
    "CVX","BRK.B","01398","00700","00345","09999","MSFT","03690","09992","TLT","SQ","NFLX","NVDA","00013","AZPN","01024",
    "00012","06955","09988","02390","NIO","TQQQ","FFIE","AMZN"
  ],
  "subscribedTradeTickSymbols":
  [
    "NVDA","TSM"
  ],
  "subscribedAskBidSymbols":
  [
    "NVDA","TSM"
  ],
  "subscribedMarketQuote":
  [
    "US_StockTop"
  ],
  "subscribedKlineSymbols":
  [
    "NVDA","TSM"
  ]
}


订阅期权行情

订阅方法virtual bool subscribe_option_quote(const std::vector<std::string>& symbols) = 0;

参数

参数名类型描述
symbolsconst std::vector<std::string>由期权四要素组成, 空格分隔,分别是:标的代码,过期日(YYYYMMDD),行权价,期权类型(看涨CALL/看跌PUT)

回调数据

需通过push_client->quote_changed_callback绑定回调方法,回调方法同股票

示例push_client->subscribe_option_quote(symbols)push_client.subscribe_quote(symbols)

订阅期货行情

参数

参数名类型描述
symbolsstd::vector<std::string>期货标的列表,如 'CLmain', 'ES2209'

回调数据

需通过push_client->quote_changed_callback绑定回调方法,回调方法同股票

示例

push_client->subscribe_future_quote(symbols)push_client->subscribe_quote(symbols)


订阅股票榜单数据

订阅方法virtual bool subscribe_stock_top(const std::string& market) = 0;取消方法virtual bool unsubscribe_stock_top(const std::string& market) = 0;

说明

订阅股票的行情榜单数据,非交易时间不推送,推送间隔为30s,每次推送订阅指标Top30的标的数据。 推送接口是异步回调,通过实现ApiComposeCallback接口可以获得异步请求结果。 回调接口返回结果类型为StockTopData对象。各指标数据按指标值倒排序。

支持美国和香港市场股票指标的订阅,盘中数据榜单有StockRankingIndicator所有指标,美股盘前盘后只有涨幅(changeRate)和5分钟涨幅(changeRate5Min)两个指标的榜单数据

参数

参数名类型是否必填描述
marketstd::string&Yes市场,支持 HK, US

回调数据

需通过push_client->set_stock_top_changed_callback绑定回调方法

StockTopData数据结构如下:

参数名类型描述
marketstd::string&市场:US/HK
timestampint64_t时间戳
topDatatopData各指标榜单数据列表

TopData的数据结构如下:

参数名类型描述
targetNamestd::string&指标名(changeRate, changeRate5Min, turnoverRate, amount, volume, amplitude)
itemStockItem该指标维度下的榜单数据列表

StockItem的数据结构如下:

参数名类型描述
symbolstd::string&标的
latestPricedouble最新价
targetValuedouble对应指标值

回调数据示例

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;
        push_client->subscribe_stock_top("US");
    }

    void stock_top_changed_callback(const tigeropen::push::pb::StockTopData& data) {
        ucout << "StockTopData: " << std::endl;
        ucout << "- market: " << data.market() << std::endl;
        ucout << "- timestamp: " << data.timestamp() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_stock_top_changed_callback(std::bind(&TestPushClient::stock_top_changed_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->unsubscribe_stock_top("US");
        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 bool subscribe_option_top(const std::string& market) = 0;取消方法virtual bool unsubscribe_option_top(const std::string& market) = 0

说明

订阅期权的行情榜单数据,非交易时间不推送,推送间隔为30s,每次推送订阅指标Top50的标的数据。 推送接口是异步回调,通过实现ApiComposeCallback接口可以获得异步请求结果。 回调接口返回结果类型为OptionTopData对象。其中异动大单为单笔成交量大于1000,按成交时间倒排序的数据,其他指标数据为交易日累计指标值的倒序数据。

支持美国市场期权指标的订阅,盘中数据榜单有OptionRankingIndicator所有指标。

参数

参数名类型是否必填描述
marketstd::string&Yes市场:US/HK

回调数据

需通过push_client->set_option_top_changed_callback绑定回调方法

OptionTopData数据结构如下:

参数名类型描述
marketstd::string&市场:US
timestampint64_t时间戳
topDatatopData各指标榜单数据列表

TopData的数据结构如下:

参数名类型描述
targetNamestd::string&指标名(bigOrder, volume, amount, openInt)
bigOrderstd:vector<bigOrder>异动大单指标(bigOrder)数据列表
itemstd:vector<optionItem>该指标维度下的榜单数据列表

BigOrder的数据结构如下:

参数名类型描述
symbolstd::string&股票ETF标的
expirystd::string&过期日,格式:yyyyMMdd
strikestd::string&行权价
rightstd::string&CALL/PUT
dirstd::string&买卖方向:BUY/SELL/NONE
volumedouble成交量
pricedouble成交价
amountdouble成交额
tradeTimeint64_t成交时间戳

OptionItem的数据结构如下:

参数名类型描述
symbolstd::string&股票ETF标的
expirystd::string&过期日,格式:yyyyMMdd
strikestd::string&行权价
rightstd::string&CALL/PUT
totalAmountdouble成交额
totalVolumedouble成交量
totalOpenIntdouble未平仓量
volumeToOpenIntdouble成交量/未平仓量
latestPricedouble最新价
updateTimeint64_t指标数据更新时间戳

示例

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;
        push_client->subscribe_option_top("US");
    }

    void option_top_changed_callback(const tigeropen::push::pb::StockTopData& data) {
        ucout << "OptionTopData: " << std::endl;
        ucout << "- market: " << data.market() << std::endl;
        ucout << "- timestamp: " << data.timestamp() << std::endl;
    }
    
    void start_test(ClientConfig config) {
        push_client->set_option_top_changed_callback(std::bind(&TestPushClient::option_top_changed_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->unsubscribe_option_top("US");
        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);
上次编辑于: