百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

kalshi-cpp

> 开发工具
开源

适用于 Kalshi 预测市场 API 的现代 C++23 SDK — 完整的带类型的 REST 覆盖 + 实时 WebSocket 流式传输、RSA-PSS 身份验证和无异常的 std::expec

99 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

适用于 Kalshi 预测市场 API 的现代 C++23 SDK — 完整的带类型的 REST 覆盖 + 实时 WebSocket 流式传输、RSA-PSS 身份验证和无异常的 std::expec

kalshi-cpp

A C++23 client for Kalshi's Predictions REST API and WebSocket feeds. It uses RSA-PSS request signing, lossless fixed-point strings, and std::expected for failures.

This package targets the Predictions API. Kalshi's Margin and Perpetuals API has a separate host, authentication surface, and OpenAPI document; it is not part of this client.

Install and test

Install OpenSSL, libcurl, libwebsockets, CMake 3.20+, and a C++23 compiler.

bash
brew install cmake openssl curl libwebsockets pkg-config
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel && ctest --test-dir build --output-on-failure

Linux package names are libssl-dev, libcurl4-openssl-dev, libwebsockets-dev, and pkg-config.

Add to a CMake project

cmake
include(FetchContent)
FetchContent_Declare(
  kalshi
  GIT_REPOSITORY https://github.com/Reddimus/kalshi-cpp.git
  GIT_TAG v0.5.2
)
set(KALSHI_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(KALSHI_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(kalshi)
target_link_libraries(myapp PRIVATE kalshi::kalshi)

The same target is exported by cmake --install and find_package(kalshi). Run tools/test_consumers.sh to verify both paths.

Read market data

cpp
#include 
#include 

int main() {
    auto signer = kalshi::Signer::from_pem_file("key-id", "private-key.pem");
    if (!signer) return 1;
    kalshi::KalshiClient client{kalshi::HttpClient{std::move(*signer)}};
    auto markets = client.get_markets();
    if (!markets) return 2;
    for (const auto& market : markets->items) {
        std::cout << market.ticker << ' ' << market.yes_bid_dollars << '\n';
    }
}

Place a V2 order

The current order API uses one bid/ask book and fixed-point strings. The SDK rejects ambiguous legacy integer bodies before sending a request.

cpp
kalshi::CreateOrderParams order;
order.ticker = "MARKET-TICKER";
order.book_side = kalshi::BookSide::Bid;
order.count_fp = "10.00";
order.price_dollars = "0.500000";
order.time_in_force = "good_till_canceled";
order.self_trade_prevention_type = "taker_at_cross";
order.exchange_index = -1;

// For an ask that intentionally replaces the default legacy Yes/Buy direction:
// order.book_side = kalshi::BookSide::Ask;
// order.discard_legacy_direction = true;

auto result = client.create_order(order);
if (!result) std::cerr << result.error().message << '\n';

Precision and exchange shards

  • Dollar and fractional-count values retain their exact wire strings.
  • FixedPoint::scaled_integer(scale) rejects lossy or overflowing conversion.
  • Legacy integer fields are 0 when exact conversion is impossible.
  • Portfolio filters and returned models expose exchange_index. Pass -1 where the API supports ticker-based auto-routing.

Predictions API coverage

The typed surface covers the common market-data, portfolio, order, subaccount, RFQ, quote, and discovery workflows. See the exact REST and WebSocket coverage table before depending on a less common operation.

Unsupported legacy methods fail before transport instead of calling a stale route. Margin endpoints belong in a separate client and remain out of scope.

Where things live

Path Purpose
include/kalshi/ Public API and models
src/api/ REST contracts, parsing, and serialization
src/http/ Signed libcurl transport
src/ws/ WebSocket client and frame parsing
tests/ Unit, parser, and operation-contract tests
docs/api-coverage.md Exact supported and deferred API surface
docs/research.md Upstream contract provenance

Development gates

bash
make format && make lint
cmake -S . -B build-sanitized -DKALSHI_ENABLE_SANITIZERS=ON -DKALSHI_ENABLE_LTO=OFF
cmake --build build-sanitized --parallel
ctest --test-dir build-sanitized --output-on-failure
./tools/test_consumers.sh

See CONTRIBUTING.md for contribution steps and CHANGELOG.md for migration notes.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++api-clientcmakecppcpp23

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具