数字货币

HTTP 行情适用性

数字货币 HTTP 行情支持 K 线和当日分时。它们复用 get_kline() 和 get_timeline(),并通过 SecType::CC 指定数字货币;代码格式如 BTC.USD。当前不支持数字货币历史分时。

数字货币行情订阅请参阅行情推送中的 subscribe_cc()。

数字货币实时行情

vector<RealtimeQuote> QuoteClient::get_quote_real_time(const value &symbols, SecType sec_type)

传入 SecType::CC 查询数字货币实时行情。每个 RealtimeQuote.amount 为成交额。

value symbols = value::array();
symbols[0] = value::string(U("BTC.USD"));
auto quotes = quote_client.get_quote_real_time(symbols, SecType::CC);
ucout << U("amount: ") << quotes[0].amount << std::endl;

数字货币 K 线

value QuoteClient::get_kline(
    const value &symbols, BarPeriod period, time_t begin_time, time_t end_time,
    QuoteRight right, int limit, utility::string_t page_token, SecType sec_type)

vector<Kline> QuoteClient::get_kline(
    const value &symbols, utility::string_t period, time_t begin_time, time_t end_time,
    int limit, utility::string_t right, utility::string_t page_token, SecType sec_type)

传入 SecType::CC 查询数字货币 K 线。返回原始 JSON 和 vector<Kline> 的重载均支持该参数;接受 TradingSession 的重载也可在最后传入 SecType。不传 SecType 的原有重载保持不变。

page_token 会和 SecType::CC 一起发送,因此后续分页请求仍会查询数字货币。读取响应中的 nextPageToken,并在下一次调用中传回 page_token。

KlineItem.volume_decimal 的类型为 boost::optional<double>,对应 JSON 字段 volumeDecimal,用于保留数字货币的非整数成交量;字段缺失或为 null 时没有值,此时读取整数 volume。

示例

value symbols = value::array();
symbols[0] = value::string(U("BTC.USD"));

vector<Kline> klines = quote_client.get_kline(
    symbols, U("day"), -1, -1, 251, U("br"), U(""), SecType::CC);

for (const auto &kline : klines) {
    for (const auto &item : kline.items) {
        if (item.volume_decimal) {
            std::cout << *item.volume_decimal << std::endl;
        }
    }
}

数字货币分时

value QuoteClient::get_timeline(const value &symbols, bool include_hour_trading, time_t begin_time, SecType sec_type)

传入 SecType::CC 查询数字货币当日分时。该方法返回原始 web::json::value;分时点中的非整数成交量位于 JSON 字段 volumeDecimal。此能力不适用于 get_history_timeline()。

示例

value symbols = value::array();
symbols[0] = value::string(U("BTC.USD"));

value result = quote_client.get_timeline(symbols, false, -1, SecType::CC);
ucout << result.serialize() << std::endl;

分时点示例:

{"time": 1785441000000, "price": 118432.25, "avgPrice": 118401.72, "volume": 12, "volumeDecimal": 12.3456}

Did this page help you?