适用于 Kalshi 预测市场 API 的现代 C++23 SDK — 完整的带类型的 REST 覆盖 + 实时 WebSocket 流式传输、RSA-PSS 身份验证和无异常的 std::expec
适用于 Kalshi 预测市场 API 的现代 C++23 SDK — 完整的带类型的 REST 覆盖 + 实时 WebSocket 流式传输、RSA-PSS 身份验证和无异常的 std::expec
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 OpenSSL, libcurl, libwebsockets, CMake 3.20+, and a C++23 compiler.
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-failureLinux package names are libssl-dev, libcurl4-openssl-dev,
libwebsockets-dev, and pkg-config.
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.
#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';
}
}The current order API uses one bid/ask book and fixed-point strings. The SDK
rejects ambiguous legacy integer bodies before sending a request.
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';FixedPoint::scaled_integer(scale) rejects lossy or overflowing conversion.0 when exact conversion is impossible.exchange_index. Pass -1
where the API supports ticker-based auto-routing.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.
| 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 |
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.shSee CONTRIBUTING.md for contribution steps and CHANGELOG.md for migration notes.
暂无开放 Issues,或尚未同步最近议题。