kalshi
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKalshi API
Kalshi API
Kalshi is a CFTC-regulated prediction market exchange where users trade on the outcomes of real-world events.
Check this skill and the official documentation FREQUENTLY. The canonical machine-readable index of all docs lives at:
Always consult to discover every available page before building. It is the single source of truth for endpoint references, SDK docs, WebSocket channels, FIX protocol details, and getting-started guides.
llms.txtKey Concepts (Glossary)
核心概念(术语表)
| Term | Definition |
|---|---|
| Market | A single binary outcome contract (Yes / No) with prices in cents (1–99¢). |
| Event | A collection of related markets representing a real-world occurrence (e.g., an election, a weather reading). |
| Series | A template for recurring events that share the same structure and rules (e.g., "Daily Highest Temp in NYC"). |
| Orderbook | Bids only — in binary markets a YES bid at X¢ is equivalent to a NO ask at (100−X)¢. |
| Fill | A matched trade on one of your orders. |
| Settlement | The final resolution of a market (Yes or No) after determination. |
| Multivariate Event | A combo event created dynamically from a multivariate event collection. |
Full glossary: https://docs.kalshi.com/getting_started/terms.md
| 术语 | 定义 |
|---|---|
| Market(市场) | 单个二元结果合约(是/否),价格以美分计价(1-99美分)。 |
| Event(事件) | 一组相关市场的集合,代表某一现实世界事件(例如选举、天气读数)。 |
| Series(系列) | 具有相同结构和规则的重复事件模板(例如“纽约每日最高气温”)。 |
| Orderbook(订单簿) | 仅包含买单——在二元市场中,X美分的YES买单等价于(100−X)美分的NO卖单。 |
| Fill(成交) | 您的某笔订单达成的匹配交易。 |
| Settlement(结算) | 市场在结果确定后的最终决议(是或否)。 |
| Multivariate Event(多元事件) | 从多元事件集合中动态创建的组合事件。 |
Base URLs
基础URL
| Environment | REST API | WebSocket |
|---|---|---|
| Production | | |
| Demo | | |
Note: Despite thesubdomain, the production URL serves ALL Kalshi markets — economics, weather, tech, entertainment, etc.elections
Demo environment info: https://docs.kalshi.com/getting_started/demo_env.md
| 环境 | REST API | WebSocket |
|---|---|---|
| 生产环境 | | |
| 演示环境 | | |
注意: 尽管域名包含,生产环境URL仍适用于所有Kalshi市场——包括经济、天气、科技、娱乐等领域。elections
Documentation & References
文档与参考
All detailed examples, request/response schemas, and walkthroughs live in the official docs. Always consult these before building:
所有详细示例、请求/响应模式以及操作指南均位于官方文档中。开发前请务必查阅:
Authentication
认证
Kalshi uses RSA-PSS signed requests (not Bearer tokens). Every authenticated request requires three headers:
| Header | Value |
|---|---|
| Your API Key ID |
| Current Unix timestamp in milliseconds |
| Base64-encoded RSA-PSS signature of |
Important: When signing, use the path without query parameters. For example, sign even if the request URL is .
/trade-api/v2/portfolio/orders/trade-api/v2/portfolio/orders?limit=5Kalshi使用RSA-PSS签名请求(而非Bearer令牌)。每笔认证请求都需要三个请求头:
| 请求头 | 值 |
|---|---|
| 您的API密钥ID |
| 当前Unix时间戳(毫秒) |
| |
重要提示: 签名时,请使用不含查询参数的路径。例如,即使请求URL是,也要对进行签名。
/trade-api/v2/portfolio/orders?limit=5/trade-api/v2/portfolio/ordersGenerating API Keys
生成API密钥
- Log in → Account Settings → API Keys section.
- Click "Create New API Key" to generate an RSA key pair.
- Store the private key immediately — it cannot be retrieved again.
- 登录 → 账户设置 → API密钥部分。
- 点击“Create New API Key”生成RSA密钥对。
- 立即存储私钥——私钥无法再次找回。
Python Signing Example
Python签名示例
python
import base64, datetime, requests
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding
def load_private_key(file_path):
with open(file_path, "rb") as f:
return serialization.load_pem_private_key(f.read(), password=None)
def sign_pss(private_key, text: str) -> str:
sig = private_key.sign(
text.encode("utf-8"),
padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.DIGEST_LENGTH),
hashes.SHA256(),
)
return base64.b64encode(sig).decode("utf-8")
def kalshi_headers(key_id, private_key, method, path):
ts = str(int(datetime.datetime.now().timestamp() * 1000))
path_no_qs = path.split("?")[0]
sig = sign_pss(private_key, ts + method + path_no_qs)
return {
"KALSHI-ACCESS-KEY": key_id,
"KALSHI-ACCESS-SIGNATURE": sig,
"KALSHI-ACCESS-TIMESTAMP": ts,
}python
import base64, datetime, requests
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding
def load_private_key(file_path):
with open(file_path, "rb") as f:
return serialization.load_pem_private_key(f.read(), password=None)
def sign_pss(private_key, text: str) -> str:
sig = private_key.sign(
text.encode("utf-8"),
padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.DIGEST_LENGTH),
hashes.SHA256(),
)
return base64.b64encode(sig).decode("utf-8")
def kalshi_headers(key_id, private_key, method, path):
ts = str(int(datetime.datetime.now().timestamp() * 1000))
path_no_qs = path.split("?")[0]
sig = sign_pss(private_key, ts + method + path_no_qs)
return {
"KALSHI-ACCESS-KEY": key_id,
"KALSHI-ACCESS-SIGNATURE": sig,
"KALSHI-ACCESS-TIMESTAMP": ts,
}JavaScript Signing Example
JavaScript签名示例
javascript
const crypto = require("crypto");
const fs = require("fs");
function signPss(privateKeyPem, text) {
const sign = crypto.createSign("RSA-SHA256");
sign.update(text);
sign.end();
return sign.sign({
key: privateKeyPem,
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
}).toString("base64");
}
function kalshiHeaders(keyId, privateKeyPem, method, path) {
const ts = Date.now().toString();
const pathNoQs = path.split("?")[0];
const sig = signPss(privateKeyPem, ts + method + pathNoQs);
return {
"KALSHI-ACCESS-KEY": keyId,
"KALSHI-ACCESS-SIGNATURE": sig,
"KALSHI-ACCESS-TIMESTAMP": ts,
};
}javascript
const crypto = require("crypto");
const fs = require("fs");
function signPss(privateKeyPem, text) {
const sign = crypto.createSign("RSA-SHA256");
sign.update(text);
sign.end();
return sign.sign({
key: privateKeyPem,
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
}).toString("base64");
}
function kalshiHeaders(keyId, privateKeyPem, method, path) {
const ts = Date.now().toString();
const pathNoQs = path.split("?")[0];
const sig = signPss(privateKeyPem, ts + method + pathNoQs);
return {
"KALSHI-ACCESS-KEY": keyId,
"KALSHI-ACCESS-SIGNATURE": sig,
"KALSHI-ACCESS-TIMESTAMP": ts,
};
}SDKs
SDK
Kalshi provides official SDKs. Prefer these for production integrations:
| SDK | Install | Docs |
|---|---|---|
| Python (sync) | | https://docs.kalshi.com/sdks/python/quickstart.md |
| Python (async) | | https://docs.kalshi.com/sdks/python/quickstart.md |
| TypeScript | | https://docs.kalshi.com/sdks/typescript/quickstart.md |
The oldpackage is deprecated. Migrate tokalshi-pythonorkalshi_python_sync.kalshi_python_async
SDK overview: https://docs.kalshi.com/sdks/overview.md
For production applications, consider generating your own client from the OpenAPI spec.
Kalshi提供官方SDK。生产环境集成建议优先使用SDK:
| SDK | 安装方式 | 文档 |
|---|---|---|
| Python(同步) | | https://docs.kalshi.com/sdks/python/quickstart.md |
| Python(异步) | | https://docs.kalshi.com/sdks/python/quickstart.md |
| TypeScript | | https://docs.kalshi.com/sdks/typescript/quickstart.md |
旧版包已弃用。请迁移至kalshi-python或kalshi_python_sync。kalshi_python_async
对于生产应用,可考虑从OpenAPI规范生成自定义客户端。
Rate Limits
速率限制
| Tier | Read | Write |
|---|---|---|
| Basic | 20/s | 10/s |
| Advanced | 30/s | 30/s |
| Premier | 100/s | 100/s |
| Prime | 400/s | 400/s |
Write-limited endpoints: , , , , , . In batch APIs each item counts as 1 transaction (except where each cancel = 0.2 transactions).
CreateOrderCancelOrderAmendOrderDecreaseOrderBatchCreateOrdersBatchCancelOrdersBatchCancelOrdersFull details: https://docs.kalshi.com/getting_started/rate_limits.md
| 等级 | 读取 | 写入 |
|---|---|---|
| 基础版 | 20次/秒 | 10次/秒 |
| 进阶版 | 30次/秒 | 30次/秒 |
| 高级版 | 100次/秒 | 100次/秒 |
| 旗舰版 | 400次/秒 | 400次/秒 |
受写入限制的端点:, , , , , 。在批量API中,每个条目计为1次交易(除外,每笔取消计为0.2次交易)。
CreateOrderCancelOrderAmendOrderDecreaseOrderBatchCreateOrdersBatchCancelOrdersBatchCancelOrdersPagination
分页
The API uses cursor-based pagination. Responses include a field; pass it as on the next request. An empty/null cursor means no more pages. Default page size is 100 (max typically 1000).
cursor?cursor={value}API使用基于游标(cursor)的分页。响应中包含字段;在下一次请求中,将其作为参数传递。空值或null游标表示没有更多页面。默认页面大小为100(最大值通常为1000)。
cursor?cursor={value}REST API Endpoints Overview
REST API端点概览
Below is a summary organized by domain. For full request/response schemas, see the linked docs or browse https://docs.kalshi.com/llms.txt.
以下是按领域分类的摘要。如需完整的请求/响应模式,请查阅链接文档或浏览https://docs.kalshi.com/llms.txt。
Markets
市场
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | List markets with filters (status, series, timestamps). Docs: Get Markets |
| GET | No | Get a single market by ticker. Docs: Get Market |
| GET | No | Get current orderbook (yes bids + no bids). Docs: Get Market Orderbook |
| GET | No | Candlestick data (1m, 1h, 1d). Docs: Get Market Candlesticks |
| POST | No | Batch candlesticks for up to 100 tickers. Docs: Batch Get Market Candlesticks |
| GET | No | All public trades. Docs: Get Trades |
| GET | No | Get a series. Docs: Get Series |
| GET | No | List series. Docs: Get Series List |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 带筛选条件列出市场(状态、系列、时间戳)。文档:Get Markets |
| GET | 否 | 通过交易代码获取单个市场。文档:Get Market |
| GET | 否 | 获取当前订单簿(YES买单 + NO买单)。文档:Get Market Orderbook |
| GET | 否 | K线数据(1分钟、1小时、1天)。文档:Get Market Candlesticks |
| POST | 否 | 批量获取最多100个交易代码的K线数据。文档:Batch Get Market Candlesticks |
| GET | 否 | 所有公开交易。文档:Get Trades |
| GET | 否 | 获取系列。文档:Get Series |
| GET | 否 | 列出系列。文档:Get Series List |
Events
事件
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | List events (excludes multivariate). Docs: Get Events |
| GET | No | Get a single event. Docs: Get Event |
| GET | No | Event metadata only. Docs: Get Event Metadata |
| GET | No | Aggregated event candlesticks. Docs: Get Event Candlesticks |
| GET | No | Forecast percentile history. Docs: Get Event Forecast Percentile History |
| GET | No | List multivariate events. Docs: Get Multivariate Events |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 列出事件(不含多元事件)。文档:Get Events |
| GET | 否 | 获取单个事件。文档:Get Event |
| GET | 否 | 仅获取事件元数据。文档:Get Event Metadata |
| GET | 否 | 聚合事件K线数据。文档:Get Event Candlesticks |
| GET | 否 | 预测百分位数历史数据。文档:Get Event Forecast Percentile History |
| GET | 否 | 列出多元事件。文档:Get Multivariate Events |
Orders (Authenticated)
订单(需认证)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| POST | Yes | Create an order. Docs: Create Order |
| GET | Yes | List your orders (resting/canceled/executed). Docs: Get Orders |
| GET | Yes | Get a single order. Docs: Get Order |
| DELETE | Yes | Cancel an order. Docs: Cancel Order |
| POST | Yes | Amend price/count. Docs: Amend Order |
| POST | Yes | Decrease contract count. Docs: Decrease Order |
| GET | Yes | Queue position. Docs: Get Order Queue Position |
| GET | Yes | Queue positions for all resting orders. Docs: Get Queue Positions for Orders |
| POST | Yes | Batch create (up to 20). Docs: Batch Create Orders |
| DELETE | Yes | Batch cancel (up to 20). Docs: Batch Cancel Orders |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| POST | 是 | 创建订单。文档:Create Order |
| GET | 是 | 列出您的订单(待处理/已取消/已执行)。文档:Get Orders |
| GET | 是 | 获取单个订单。文档:Get Order |
| DELETE | 是 | 取消订单。文档:Cancel Order |
| POST | 是 | 修改价格/数量。文档:Amend Order |
| POST | 是 | 减少合约数量。文档:Decrease Order |
| GET | 是 | 队列位置。文档:Get Order Queue Position |
| GET | 是 | 所有待处理订单的队列位置。文档:Get Queue Positions for Orders |
| POST | 是 | 批量创建(最多20笔)。文档:Batch Create Orders |
| DELETE | 是 | 批量取消(最多20笔)。文档:Batch Cancel Orders |
Portfolio (Authenticated)
投资组合(需认证)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | Yes | Account balance (cents). Docs: Get Balance |
| GET | Yes | Market positions. Docs: Get Positions |
| GET | Yes | Your fills. Docs: Get Fills |
| GET | Yes | Settlement history. Docs: Get Settlements |
| GET | Yes | Total resting order value (FCM). Docs: Get Total Resting Order Value |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 是 | 账户余额(美分)。文档:Get Balance |
| GET | 是 | 市场持仓。文档:Get Positions |
| GET | 是 | 您的成交记录。文档:Get Fills |
| GET | 是 | 结算历史。文档:Get Settlements |
| GET | 是 | 待处理订单总价值(FCM)。文档:Get Total Resting Order Value |
Subaccounts (Authenticated)
子账户(需认证)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| POST | Yes | Create subaccount (max 32). Docs: Create Subaccount |
| GET | Yes | All subaccount balances. Docs: Get All Subaccount Balances |
| GET | Yes | Subaccount transfer history. Docs: Get Subaccount Transfers |
| POST | Yes | Transfer between subaccounts. Docs: Transfer Between Subaccounts |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| POST | 是 | 创建子账户(最多32个)。文档:Create Subaccount |
| GET | 是 | 所有子账户余额。文档:Get All Subaccount Balances |
| GET | 是 | 子账户转账历史。文档:Get Subaccount Transfers |
| POST | 是 | 子账户间转账。文档:Transfer Between Subaccounts |
Order Groups (Authenticated)
订单组(需认证)
Order groups apply a rolling 15-second contracts limit; when hit, all orders in the group are auto-cancelled.
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| POST | Yes | Create group. Docs: Create Order Group |
| GET | Yes | List groups. Docs: Get Order Groups |
| GET | Yes | Get group. Docs: Get Order Group |
| DELETE | Yes | Delete group. Docs: Delete Order Group |
| POST | Yes | Reset counter. Docs: Reset Order Group |
| POST | Yes | Manually trigger. Docs: Trigger Order Group |
| PUT | Yes | Update limit. Docs: Update Order Group Limit |
订单组应用滚动15秒合约限制;达到限制时,组内所有订单将自动取消。
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| POST | 是 | 创建组。文档:Create Order Group |
| GET | 是 | 列出组。文档:Get Order Groups |
| GET | 是 | 获取组。文档:Get Order Group |
| DELETE | 是 | 删除组。文档:Delete Order Group |
| POST | 是 | 重置计数器。文档:Reset Order Group |
| POST | 是 | 手动触发。文档:Trigger Order Group |
| PUT | 是 | 更新限制。文档:Update Order Group Limit |
Communications / RFQ (Authenticated)
通信 / RFQ(需认证)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | Yes | Get your comms ID. Docs: Get Communications ID |
| POST | Yes | Create RFQ (max 100 open). Docs: Create RFQ |
| GET | Yes | List RFQs. Docs: Get RFQs |
| GET | Yes | Get RFQ. Docs: Get RFQ |
| DELETE | Yes | Delete RFQ. Docs: Delete RFQ |
| POST | Yes | Create quote. Docs: Create Quote |
| GET | Yes | List quotes. Docs: Get Quotes |
| GET | Yes | Get quote. Docs: Get Quote |
| DELETE | Yes | Delete quote. Docs: Delete Quote |
| POST | Yes | Accept quote. Docs: Accept Quote |
| POST | Yes | Confirm quote. Docs: Confirm Quote |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 是 | 获取您的通信ID。文档:Get Communications ID |
| POST | 是 | 创建RFQ(最多100个未处理)。文档:Create RFQ |
| GET | 是 | 列出RFQ。文档:Get RFQs |
| GET | 是 | 获取单个RFQ。文档:Get RFQ |
| DELETE | 是 | 删除RFQ。文档:Delete RFQ |
| POST | 是 | 创建报价。文档:Create Quote |
| GET | 是 | 列出报价。文档:Get Quotes |
| GET | 是 | 获取单个报价。文档:Get Quote |
| DELETE | 是 | 删除报价。文档:Delete Quote |
| POST | 是 | 接受报价。文档:Accept Quote |
| POST | 是 | 确认报价。文档:Confirm Quote |
Historical Data (Authenticated)
历史数据(需认证)
Historical data is for archived markets, orders, and fills that have moved past cutoff timestamps.
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | Yes | Cutoff boundaries. Docs: Get Historical Cutoff Timestamps |
| GET | Yes | Archived markets. Docs: Get Historical Markets |
| GET | Yes | Single archived market. Docs: Get Historical Market |
| GET | Yes | Archived candlesticks. Docs: Get Historical Market Candlesticks |
| GET | Yes | Archived fills. Docs: Get Historical Fills |
| GET | Yes | Archived orders. Docs: Get Historical Orders |
Historical data guide: https://docs.kalshi.com/getting_started/historical_data.md
历史数据适用于已超过截止时间的归档市场、订单和成交记录。
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 是 | 截止时间边界。文档:Get Historical Cutoff Timestamps |
| GET | 是 | 归档市场。文档:Get Historical Markets |
| GET | 是 | 单个归档市场。文档:Get Historical Market |
| GET | 是 | 归档K线数据。文档:Get Historical Market Candlesticks |
| GET | 是 | 归档成交记录。文档:Get Historical Fills |
| GET | 是 | 归档订单。文档:Get Historical Orders |
Multivariate Collections
多元事件集合
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | List collections. Docs: Get Multivariate Event Collections |
| GET | No | Get collection. Docs: Get Multivariate Event Collection |
| POST | Yes | Create market in collection. Docs: Create Market In Multivariate Event Collection |
| GET | No | Lookup tickers. Docs: Lookup Tickers For Market In Multivariate Event Collection |
| GET | No | Recent lookups. Docs: Get Multivariate Event Collection Lookup History |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 列出集合。文档:Get Multivariate Event Collections |
| GET | 否 | 获取集合。文档:Get Multivariate Event Collection |
| POST | 是 | 在集合中创建市场。文档:Create Market In Multivariate Event Collection |
| GET | 否 | 查询交易代码。文档:Lookup Tickers For Market In Multivariate Event Collection |
| GET | 否 | 近期查询记录。文档:Get Multivariate Event Collection Lookup History |
Milestones & Structured Targets
里程碑与结构化目标
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | List milestones. Docs: Get Milestones |
| GET | No | Get milestone. Docs: Get Milestone |
| GET | No | List structured targets. Docs: Get Structured Targets |
| GET | No | Get structured target. Docs: Get Structured Target |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 列出里程碑。文档:Get Milestones |
| GET | 否 | 获取单个里程碑。文档:Get Milestone |
| GET | 否 | 列出结构化目标。文档:Get Structured Targets |
| GET | 否 | 获取单个结构化目标。文档:Get Structured Target |
Live Data
实时数据
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | Live data for milestone. Docs: Get Live Data |
| GET | No | Multiple milestones. Docs: Get Multiple Live Data |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 里程碑的实时数据。文档:Get Live Data |
| GET | 否 | 多个里程碑的实时数据。文档:Get Multiple Live Data |
Search & Discovery
搜索与发现
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | Sport filters. Docs: Get Filters for Sports |
| GET | No | Tags by category. Docs: Get Tags for Series Categories |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 体育类筛选条件。文档:Get Filters for Sports |
| GET | 否 | 按分类列出标签。文档:Get Tags for Series Categories |
Exchange & Account
交易所与账户
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | Exchange status. Docs: Get Exchange Status |
| GET | No | Exchange schedule. Docs: Get Exchange Schedule |
| GET | No | Announcements. Docs: Get Exchange Announcements |
| GET | Yes | Data freshness timestamp. Docs: Get User Data Timestamp |
| GET | No | Fee changes. Docs: Get Series Fee Changes |
| GET | Yes | Your rate limit tier. Docs: Get Account API Limits |
| GET | Yes | List API keys. Docs: Get API Keys |
| POST | Yes | Create API key. Docs: Create API Key |
| POST | Yes | Generate key pair. Docs: Get API Keys |
| DELETE | Yes | Delete API key. Docs: Delete API Key |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 交易所状态。文档:Get Exchange Status |
| GET | 否 | 交易所日程。文档:Get Exchange Schedule |
| GET | 否 | 公告。文档:Get Exchange Announcements |
| GET | 是 | 数据新鲜度时间戳。文档:Get User Data Timestamp |
| GET | 否 | 系列费用变更。文档:Get Series Fee Changes |
| GET | 是 | 您的速率限制等级。文档:Get Account API Limits |
| GET | 是 | 列出API密钥。文档:Get API Keys |
| POST | 是 | 创建API密钥。文档:Create API Key |
| POST | 是 | 生成密钥对。文档:Generate API Key |
| DELETE | 是 | 删除API密钥。文档:Delete API Key |
Incentive Programs
激励计划
| Endpoint | Method | Auth | Description |
|---|---|---|---|
| GET | No | List incentives. Docs: Get Incentives |
| 端点 | 方法 | 是否需要认证 | 描述 |
|---|---|---|---|
| GET | 否 | 列出激励计划。文档:Get Incentives |
WebSocket API
WebSocket API
A single authenticated WebSocket connection provides real-time streaming. Subscribe to channels by sending JSON commands.
单个已认证的WebSocket连接可提供实时流传输。通过发送JSON命令订阅通道。
Connection
连接
wss://api.elections.kalshi.com/trade-api/ws/v2 (production)
wss://demo-api.kalshi.co/trade-api/ws/v2 (demo)Authentication headers (, , ) must be included during the handshake. Sign the string .
KALSHI-ACCESS-KEYKALSHI-ACCESS-SIGNATUREKALSHI-ACCESS-TIMESTAMP{timestamp}GET/trade-api/ws/v2wss://api.elections.kalshi.com/trade-api/ws/v2 (生产环境)
wss://demo-api.kalshi.co/trade-api/ws/v2 (演示环境)握手时必须包含认证请求头(、、)。对字符串进行签名。
KALSHI-ACCESS-KEYKALSHI-ACCESS-SIGNATUREKALSHI-ACCESS-TIMESTAMP{timestamp}GET/trade-api/ws/v2Available Channels
可用通道
| Channel | Auth Required | Description | Docs |
|---|---|---|---|
| No* | Market price/volume/OI updates | Market Ticker |
| No* | Public trade notifications | Public Trades |
| No* | Market/event state changes | Market & Event Lifecycle |
| No* | Multivariate lookup notifications | Multivariate Lookups |
| Yes | Real-time orderbook updates | Orderbook Updates |
| Yes | Your fill notifications | User Fills |
| Yes | Your order updates | User Orders |
| Yes | Your position updates | Market Positions |
| Yes | RFQ/quote notifications | Communications |
| Yes | Order group lifecycle | Order Group Updates |
*The connection itself always requires authentication, even for public channels.
| 通道 | 是否需要认证 | 描述 | 文档 |
|---|---|---|---|
| 否* | 市场价格/成交量/持仓量更新 | Market Ticker |
| 否* | 公开交易通知 | Public Trades |
| 否* | 市场/事件状态变更 | Market & Event Lifecycle |
| 否* | 多元事件查询通知 | Multivariate Lookups |
| 是 | 实时订单簿更新 | Orderbook Updates |
| 是 | 您的成交通知 | User Fills |
| 是 | 您的订单更新 | User Orders |
| 是 | 您的持仓更新 | Market Positions |
| 是 | RFQ/报价通知 | Communications |
| 是 | 订单组生命周期更新 | Order Group Updates |
*即使是公开通道,连接本身也始终需要认证。
Subscribe Command
订阅命令
json
{
"id": 1,
"cmd": "subscribe",
"params": {
"channels": ["ticker", "orderbook_delta"],
"market_tickers": ["KXHIGHNY-24JAN01-T60"]
}
}json
{
"id": 1,
"cmd": "subscribe",
"params": {
"channels": ["ticker", "orderbook_delta"],
"market_tickers": ["KXHIGHNY-24JAN01-T60"]
}
}Keep-Alive
保活机制
Kalshi sends Ping frames every 10 seconds with body . Clients must respond with Pong frames. Docs: Connection Keep-Alive
heartbeatFull WebSocket guide: https://docs.kalshi.com/getting_started/quick_start_websockets.md
Kalshi每10秒发送一次Ping帧,内容为。客户端必须回复Pong帧。文档:Connection Keep-Alive
heartbeatOrderbook Structure
订单簿结构
Kalshi orderbooks return bids only (no asks). In binary markets:
- A YES bid at X¢ = a NO ask at (100−X)¢
- A NO bid at Y¢ = a YES ask at (100−Y)¢
Each entry is sorted ascending. The best bid is the last element.
[price, quantity]Spread calculation:
- Best YES ask =
100 - best_no_bid - Spread = Best YES ask − Best YES bid
Kalshi订单簿仅返回买单(无卖单)。在二元市场中:
- X美分的YES买单等价于(100−X)美分的NO卖单
- Y美分的NO买单等价于(100−Y)美分的YES卖单
每个条目为,按升序排列。最优买单是最后一个元素。
[price, quantity]点差计算:
- 最优YES卖单价格 =
100 - 最优NO买单价格 - 点差 = 最优YES卖单价格 − 最优YES买单价格
FIX Protocol
FIX协议
Kalshi also supports the Financial Information eXchange (FIX) protocol for low-latency trading:
| Topic | Docs |
|---|---|
| Overview | https://docs.kalshi.com/fix/index.md |
| Connectivity | https://docs.kalshi.com/fix/connectivity.md |
| Session Management | https://docs.kalshi.com/fix/session-management.md |
| Order Entry | https://docs.kalshi.com/fix/order-entry.md |
| Order Groups | https://docs.kalshi.com/fix/order-groups.md |
| Drop Copy | https://docs.kalshi.com/fix/drop-copy.md |
| Market Settlement | https://docs.kalshi.com/fix/market-settlement.md |
| RFQ Messages | https://docs.kalshi.com/fix/rfq-messages.md |
| Error Handling | https://docs.kalshi.com/fix/error-handling.md |
| Subpenny Pricing | https://docs.kalshi.com/fix/subpenny-pricing.md |
Kalshi还支持金融信息交换(FIX)协议,用于低延迟交易:
Common Patterns
常见模式
Fetch All Open Markets for a Series
获取某系列的所有开放市场
bash
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets?series_ticker=KXHIGHNY&status=open" | jq '.markets[] | {ticker, title, yes_price, volume}'bash
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets?series_ticker=KXHIGHNY&status=open" | jq '.markets[] | {ticker, title, yes_price, volume}'Get Orderbook for a Market
获取某市场的订单簿
bash
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets/KXHIGHNY-24JAN01-T60/orderbook" | jq '.orderbook'bash
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets/KXHIGHNY-24JAN01-T60/orderbook" | jq '.orderbook'Paginate Through All Results
遍历所有结果(分页)
bash
undefinedbash
undefinedFirst page
第一页
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets?limit=100" > page1.json
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets?limit=100" > page1.json
Extract cursor for next page
提取下一页的游标
CURSOR=$(jq -r '.cursor' page1.json)
CURSOR=$(jq -r '.cursor' page1.json)
Next page
下一页
curl -s "https://api.elections.kalshi.com/trade-api/v2/markets?limit=100&cursor=$CURSOR" > page2.json
---curl -s "https://api.elections.kalshi.com/trade-api/v2/markets?limit=100&cursor=$CURSOR" > page2.json
---Usage Tips
使用技巧
- Always check first: https://docs.kalshi.com/llms.txt has every endpoint and guide.
llms.txt - Use the demo environment for testing — credentials are separate from production.
- Never hardcode API keys — use environment variables or secure key storage.
- Prices are in cents (1–99). Monetary values in WebSocket position channels are in centi-cents (divide by 10,000 for dollars).
- Sign paths without query parameters. Strip everything after before signing.
? - Handle pagination — always check for a non-null and loop until exhausted.
cursor - Respect rate limits — implement exponential backoff on 429 responses.
- Combine REST + WebSocket for the most accurate state: use REST for initial snapshots and WebSocket for real-time deltas.
- Orderbook is bids-only — derive asks via the 100−price complement.
- Historical vs. Live data: Check cutoff timestamps to know whether to query live or historical endpoints.
- For market status values, use: ,
unopened,open,closed.settled - Batch operations count against per-second write limits per item.
- 首先查阅: https://docs.kalshi.com/llms.txt包含所有端点和指南。
llms.txt - 使用演示环境进行测试——演示环境的凭证与生产环境分离。
- 切勿硬编码API密钥——使用环境变量或安全密钥存储。
- 价格以美分计价(1-99)。WebSocket持仓通道中的货币价值以厘分计价(除以10000转换为美元)。
- 对不含查询参数的路径进行签名。签名前,删除后的所有内容。
? - 处理分页——始终检查非空,并循环直到没有更多页面。
cursor - 遵守速率限制——在收到429响应时实现指数退避。
- 结合REST + WebSocket以获取最准确的状态:使用REST获取初始快照,使用WebSocket获取实时增量更新。
- 订单簿仅含买单——通过100−价格的补数推导卖单。
- 历史数据与实时数据: 检查截止时间戳以确定应查询实时端点还是历史端点。
- 市场状态值包括:、
unopened、open、closed。settled - 批量操作按每个条目计入每秒写入限制。
Error Handling
错误处理
Standard HTTP error codes apply. The API returns JSON error bodies with descriptive messages. Implement retry with backoff for 429 (rate limited) and 5xx (server errors).
适用标准HTTP错误码。API返回带描述性消息的JSON错误体。对429(速率限制)和5xx(服务器错误)响应实现重试与退避机制。
WebSocket Error Codes
WebSocket错误码
| Code | Meaning |
|---|---|
| 1 | Unable to process message |
| 2 | Params required |
| 3 | Channels required |
| 5 | Unknown command |
| 8 | Unknown channel name |
| 9 | Authentication required |
| 14 | Market ticker required |
| 16 | Market not found |
| 17 | Internal error |
| 18 | Command timeout |
Full error code table: https://docs.kalshi.com/getting_started/quick_start_websockets.md
| 代码 | 含义 |
|---|---|
| 1 | 无法处理消息 |
| 2 | 需要参数 |
| 3 | 需要通道 |
| 5 | 未知命令 |
| 8 | 未知通道名称 |
| 9 | 需要认证 |
| 14 | 需要市场交易代码 |
| 16 | 市场未找到 |
| 17 | 内部错误 |
| 18 | 命令超时 |
Example Project: Alph Bot
示例项目:Alph Bot
How Alph Bot Uses Kalshi
Alph Bot如何使用Kalshi
- Market discovery — Searches for Kalshi event contracts related to a live sports game (e.g., NBA point spreads, totals).
- Orderbook reading — Fetches orderbook data to determine current market-implied probabilities (prices in cents map directly to implied %).
- Edge detection — Compares Kalshi market prices against AI-estimated probabilities powered by Claude + Shipp real-time game data.
- Order execution — Places limit orders when sufficient edge is found, using Kelly Criterion for position sizing.
- Risk management — Enforces circuit breakers (max daily loss), position size limits, single-market exposure caps, and minimum account balance thresholds.
- 市场发现——搜索与实时体育赛事相关的Kalshi事件合约(例如NBA让分盘、总分盘)。
- 订单簿读取——获取订单簿数据以确定当前市场隐含概率(美分价格直接对应隐含百分比)。
- 机会识别——将Kalshi市场价格与Claude + Shipp实时赛事数据驱动的AI估算概率进行比较。
- 订单执行——当发现足够的套利空间时,使用凯利准则(Kelly Criterion)确定持仓规模并下达限价订单。
- 风险管理——实施熔断机制(每日最大亏损)、持仓规模限制、单一市场暴露上限以及最低账户余额阈值。
Alph Bot's Kalshi Configuration
Alph Bot的Kalshi配置
From its :
.env.exampleALPH_BOT_KALSHI_API_KEY_ID=abc123
ALPH_BOT_KALSHI_PRIVATE_KEY_PATH=./keys/kalshi-private.pem来自其:
.env.exampleALPH_BOT_KALSHI_API_KEY_ID=abc123
ALPH_BOT_KALSHI_PRIVATE_KEY_PATH=./keys/kalshi-private.pemStrategy
策略
ALPH_BOT_MIN_EDGE_PCT=5
ALPH_BOT_MIN_CONFIDENCE=medium
ALPH_BOT_KELLY_FRACTION=0.25
ALPH_BOT_MIN_EDGE_PCT=5
ALPH_BOT_MIN_CONFIDENCE=medium
ALPH_BOT_KELLY_FRACTION=0.25
Risk controls
风险控制
ALPH_BOT_MAX_TOTAL_EXPOSURE_USD=10000
ALPH_BOT_MAX_POSITION_SIZE_USD=1000
ALPH_BOT_MAX_SINGLE_MARKET_PERCENT=20
ALPH_BOT_MAX_DAILY_LOSS_USD=500
ALPH_BOT_MAX_DAILY_TRADES=50
ALPH_BOT_MIN_ACCOUNT_BALANCE_USD=100
undefinedALPH_BOT_MAX_TOTAL_EXPOSURE_USD=10000
ALPH_BOT_MAX_POSITION_SIZE_USD=1000
ALPH_BOT_MAX_SINGLE_MARKET_PERCENT=20
ALPH_BOT_MAX_DAILY_LOSS_USD=500
ALPH_BOT_MAX_DAILY_TRADES=50
ALPH_BOT_MIN_ACCOUNT_BALANCE_USD=100
undefinedTry It
尝试使用
bash
git clone https://gitlab.com/outsharp/shipp/alph-bot.git
cd alph-bot
cp .env.example .envbash
git clone https://gitlab.com/outsharp/shipp/alph-bot.git
cd alph-bot
cp .env.example .envAdd your Kalshi, Shipp, and Anthropic API keys
添加您的Kalshi、Shipp和Anthropic API密钥
yarn migrate
yarn migrate
Find a game to trade on
查找可交易的赛事
./index.ts available-games --sport NBA
./index.ts available-games --sport NBA
Run value betting in demo mode (uses Kalshi demo environment)
以演示模式运行价值投注(使用Kalshi演示环境)
./index.ts value-bet -d --game <GAME_ID>
./index.ts value-bet -d --game <GAME_ID>
Run in paper mode (no real orders executed)
以模拟模式运行(不执行真实订单)
./index.ts value-bet --paper --game <GAME_ID>
> **Warning:** Trading on Kalshi involves real money when not in demo/paper mode. Always start with a [demo account](https://help.kalshi.com/account/demo-account).
See the [Alph Bot README](https://gitlab.com/outsharp/shipp/alph-bot) for full setup instructions.
---./index.ts value-bet --paper --game <GAME_ID>
> **警告:** 非演示/模拟模式下,在Kalshi进行交易涉及真实资金。请始终从[演示账户](https://help.kalshi.com/account/demo-account)开始。
查看[Alph Bot README](https://gitlab.com/outsharp/shipp/alph-bot)获取完整设置说明。
---Versioning
版本控制
The current API version is v2 under . Monitor the API Changelog for updates. SDK versions align with the OpenAPI spec and are generally published weekly.
/trade-api/v2