kalshi-cpp 0.6.2
C++23 client for Kalshi's Predictions API
Loading...
Searching...
No Matches
signer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "kalshi/error.hpp"
4
5#include <cstdint>
6#include <memory>
7#include <string>
8#include <string_view>
9
10namespace kalshi {
11
14 std::string access_key;
15 std::string signature;
16 std::string timestamp;
17};
18
20enum class KeyType : std::uint8_t {
21 Rsa,
22 Ed25519
23};
24
32class Signer {
33public:
36 [[nodiscard]] static Result<Signer> from_pem(std::string_view api_key_id,
37 std::string_view pem_key);
38
40 [[nodiscard]] static Result<Signer> from_pem_file(std::string_view api_key_id,
41 std::string_view file_path);
42
44 [[nodiscard]] Result<AuthHeaders> sign(std::string_view method, std::string_view path) const;
45
47 [[nodiscard]] Result<AuthHeaders> sign_with_timestamp(std::string_view method,
48 std::string_view path,
49 std::int64_t timestamp_ms) const;
50
51 [[nodiscard]] std::string_view api_key_id() const noexcept;
52 [[nodiscard]] KeyType key_type() const noexcept;
53
54private:
55 struct Impl;
56 std::shared_ptr<const Impl> impl_;
57
58 explicit Signer(std::shared_ptr<const Impl> impl) noexcept;
59};
60
61} // namespace kalshi
Signs Kalshi requests with an API key.
Definition signer.hpp:32
KeyType key_type() const noexcept
std::string_view api_key_id() const noexcept
Result< AuthHeaders > sign(std::string_view method, std::string_view path) const
Signs a request at the current time.
Result< AuthHeaders > sign_with_timestamp(std::string_view method, std::string_view path, std::int64_t timestamp_ms) const
Signs a request at a fixed time. Useful for tests.
static Result< Signer > from_pem(std::string_view api_key_id, std::string_view pem_key)
Loads an unencrypted PEM private key (PKCS#1 or PKCS#8).
static Result< Signer > from_pem_file(std::string_view api_key_id, std::string_view file_path)
Reads a PEM private key from a file. See from_pem().
Definition api.hpp:15
std::expected< T, Error > Result
Result type for SDK operations.
Definition error.hpp:50
KeyType
Algorithm of the loaded API key.
Definition signer.hpp:20
Headers that authenticate one request.
Definition signer.hpp:13
std::string signature
KALSHI-ACCESS-SIGNATURE (base64)
Definition signer.hpp:15
std::string access_key
KALSHI-ACCESS-KEY.
Definition signer.hpp:14
std::string timestamp
KALSHI-ACCESS-TIMESTAMP (Unix milliseconds)
Definition signer.hpp:16