Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type Client
- type ClientOption
- func WithAPIKey(apiKeyID string, privateKeyPEM []byte) ClientOption
- func WithAPIKeyFile(apiKeyID string, privateKeyPath string) ClientOption
- func WithBaseURL(url string) ClientOption
- func WithEnvironment(env Environment) ClientOption
- func WithHTTPClient(hc *http.Client) ClientOption
- func WithMaxRetries(n int) ClientOption
- func WithRateLimit(ratePerSecond, burstCapacity float64) ClientOption
- func WithRequestHook(fn func(RequestInfo)) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithUserAgent(ua string) ClientOption
- func WithWSURL(url string) ClientOption
- type ConfigError
- type Environment
- type RequestInfo
- type TimeoutError
Constants ¶
const ( // EnvironmentProduction is the live trading environment. EnvironmentProduction = transport.EnvironmentProduction // EnvironmentDemo is Kalshi's sandbox environment, backed by play money. EnvironmentDemo = transport.EnvironmentDemo )
const SDKVersion = transport.SDKVersion
SDKVersion is the current release of this module.
Variables ¶
var ParsePrivateKeyPEM = transport.ParsePrivateKeyPEM
ParsePrivateKeyPEM parses a PEM-encoded RSA private key (PKCS#1 or PKCS#8) into the form Client and streaming.WSClient use for signing.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Services. Each is the entry point for one bounded context.
Exchange *exchange.Service
Markets *markets.Service
Events *events.Service
Orders *orders.Service
OrderGroups *ordergroups.Service
Portfolio *portfolio.Service
Communications *communications.Service
APIKeys *apikeys.Service
Search *search.Service
// contains filtered or unexported fields
}
Client is the top-level Kalshi SDK client. Construct one with NewClient and reuse it — it holds a connection-pooled *http.Client and (optionally) a parsed private key for request signing.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient constructs a Client from the given options. With no options it is an unauthenticated production client suitable for public market data.
func NewClientFromEnv ¶
func NewClientFromEnv(opts ...ClientOption) (*Client, error)
NewClientFromEnv builds a Client from standard environment variables: KALSHI_ENV ("production" | "demo"), KALSHI_API_KEY_ID, and either KALSHI_PRIVATE_KEY (PEM contents) or KALSHI_PRIVATE_KEY_PATH. Additional options are applied after the environment-derived ones and can override them.
func (*Client) CreateWebSocket ¶
func (c *Client) CreateWebSocket(opts streaming.WSClientOptions) *streaming.WSClient
CreateWebSocket builds a new streaming.WSClient wired with the same credentials and environment as this Client. Call Connect on the result.
func (*Client) Environment ¶
func (c *Client) Environment() Environment
Environment returns the environment this Client is configured for.
func (*Client) IsAuthenticated ¶
IsAuthenticated reports whether this Client was constructed with API credentials.
type ClientOption ¶
type ClientOption func(*clientConfig) error
ClientOption configures a Client. Options are applied in order, so later options can override earlier ones.
func WithAPIKey ¶
func WithAPIKey(apiKeyID string, privateKeyPEM []byte) ClientOption
WithAPIKey configures authenticated requests using an API Key ID and a PEM-encoded RSA private key (the .key file downloaded from Account & security -> API Keys).
func WithAPIKeyFile ¶
func WithAPIKeyFile(apiKeyID string, privateKeyPath string) ClientOption
WithAPIKeyFile is like WithAPIKey but reads the PEM from a file path.
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL overrides the REST base URL (advanced / testing).
func WithEnvironment ¶
func WithEnvironment(env Environment) ClientOption
WithEnvironment selects production or demo. Defaults to production.
func WithHTTPClient ¶
func WithHTTPClient(hc *http.Client) ClientOption
WithHTTPClient injects a custom *http.Client (custom transport, proxy, mocking, etc).
func WithMaxRetries ¶
func WithMaxRetries(n int) ClientOption
WithMaxRetries sets the max attempts (including the first) for retryable errors (429/5xx). Default 3. Set to 1 to disable retries.
func WithRateLimit ¶
func WithRateLimit(ratePerSecond, burstCapacity float64) ClientOption
WithRateLimit enables a proactive client-side token-bucket rate limiter at ratePerSecond requests/sec, with the given burst capacity (tokens). Disabled by default; the SDK still retries 429s it receives regardless.
func WithRequestHook ¶
func WithRequestHook(fn func(RequestInfo)) ClientOption
WithRequestHook registers an observability callback invoked after every REST request.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the per-request timeout. Default 10s.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent overrides the default User-Agent header.
func WithWSURL ¶
func WithWSURL(url string) ClientOption
WithWSURL overrides the WebSocket base URL (advanced / testing).
type ConfigError ¶
type ConfigError = transport.ConfigError
ConfigError indicates invalid or incomplete SDK configuration.
type Environment ¶
type Environment = transport.Environment
Environment selects which Kalshi deployment a Client talks to.
type RequestInfo ¶
type RequestInfo = transport.RequestInfo
RequestInfo is passed to an observability hook after every REST request completes.
type TimeoutError ¶
type TimeoutError = transport.TimeoutError
TimeoutError indicates a request exceeded its configured timeout.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apikeys covers /api_keys/* — manage the RSA API keys used for request signing.
|
Package apikeys covers /api_keys/* — manage the RSA API keys used for request signing. |
|
Package communications covers /communications/* — request-for-quote (RFQ) negotiated trading.
|
Package communications covers /communications/* — request-for-quote (RFQ) negotiated trading. |
|
Package events covers /events/* — events (groups of related markets).
|
Package events covers /events/* — events (groups of related markets). |
|
examples
|
|
|
place_and_cancel_order
command
Command place_and_cancel_order demonstrates an authenticated trading flow: check balance, place a resting limit order, then cancel it.
|
Command place_and_cancel_order demonstrates an authenticated trading flow: check balance, place a resting limit order, then cancel it. |
|
public_market_data
command
Command public_market_data fetches public market data — no API key required.
|
Command public_market_data fetches public market data — no API key required. |
|
websocket_orderbook
command
Command websocket_orderbook streams live order book updates for a market over WebSocket, demonstrating reconnect and sequence-gap handling.
|
Command websocket_orderbook streams live order book updates for a market over WebSocket, demonstrating reconnect and sequence-gap handling. |
|
Package exchange covers /exchange/* — exchange-wide status, trading schedule, announcements, and fee-change history.
|
Package exchange covers /exchange/* — exchange-wide status, trading schedule, announcements, and fee-change history. |
|
internal
|
|
|
Package markets covers /markets/* and /series/* — market discovery, order books, trades, and candlesticks.
|
Package markets covers /markets/* and /series/* — market discovery, order books, trades, and candlesticks. |
|
Package ordergroups covers /portfolio/order_groups/* — coordinated risk limits across a set of orders.
|
Package ordergroups covers /portfolio/order_groups/* — coordinated risk limits across a set of orders. |
|
Package orders covers /portfolio/events/orders/* (V2, recommended) and the order-read/cancel/amend surface under /portfolio/orders/*.
|
Package orders covers /portfolio/events/orders/* (V2, recommended) and the order-read/cancel/amend surface under /portfolio/orders/*. |
|
Package pagination provides a lazy, generic cursor-pagination iterator shared by every bounded context that exposes a ListAll-style method (markets, events, orders, portfolio, ...).
|
Package pagination provides a lazy, generic cursor-pagination iterator shared by every bounded context that exposes a ListAll-style method (markets, events, orders, portfolio, ...). |
|
Package portfolio covers /portfolio/* — account balance, positions, fills, settlements, deposits/withdrawals, and subaccounts.
|
Package portfolio covers /portfolio/* — account balance, positions, fills, settlements, deposits/withdrawals, and subaccounts. |
|
Package search covers GET /search — full-text search across markets, events, and series.
|
Package search covers GET /search — full-text search across markets, events, and series. |
|
Package shared holds the handful of value objects that genuinely cross bounded-context boundaries in this SDK (currently just MarketSide, which appears on markets.Trade, orders.CreateOrderLegacyRequest, portfolio.Fill, communications.Rfq/CreateRfqRequest, and streaming.OrderbookDeltaMsg).
|
Package shared holds the handful of value objects that genuinely cross bounded-context boundaries in this SDK (currently just MarketSide, which appears on markets.Trade, orders.CreateOrderLegacyRequest, portfolio.Fill, communications.Rfq/CreateRfqRequest, and streaming.OrderbookDeltaMsg). |
|
Package streaming implements Kalshi's single-endpoint, multi-channel WebSocket API: a resilient, read-only client with automatic reconnect, re-subscription, and sequence-gap recovery.
|
Package streaming implements Kalshi's single-endpoint, multi-channel WebSocket API: a resilient, read-only client with automatic reconnect, re-subscription, and sequence-gap recovery. |