Kalshi
Trade on Kalshi prediction markets via a self-contained CLI script. Supports market search, portfolio tracking, and full order lifecycle (place/cancel/monitor).
Quick Start
All commands route through a single script. Output is JSON.
CLI
Primary script:
CODEBLOCK0
Helper script:
CODEBLOCK1
Combines market details + orderbook in a single call for fast analysis.
Commands
| Command | Description |
|---|
| INLINECODE0 | Get account balance (cash + portfolio value) |
| INLINECODE1 |
Get balance + all open positions |
|
trending | Top markets by 24h volume |
|
search <query> | Search markets by keyword |
|
market <ticker> | Get details for a single market |
|
orderbook <ticker> | Get bid/ask levels for a market |
|
buy <ticker> <yes\|no> <count> <price> | Place a buy order (price in cents 1-99) |
|
sell <ticker> <yes\|no> <count> <price> | Place a sell order (price in cents 1-99) |
|
cancel <orderId> | Cancel a resting order |
|
orders [resting\|canceled\|executed] | List orders, optionally filtered by status |
|
fills [ticker] | List recent fills, optionally filtered by ticker |
Examples
CODEBLOCK2
Output
All commands output JSON to stdout. Parse the result to present it to the user.
Trading Rules
Critical: ALWAYS confirm with the user before placing any buy or sell order.
Before executing a trade, show the user:
- - Ticker
- Side (YES or NO)
- Count (number of contracts)
- Price (in cents)
- Total cost = count × price cents = $X.XX
Price format:
- - Prices are in cents (1-99)
- 65 cents = $0.65 per contract
- Minimum: 1 cent, Maximum: 99 cents
Payouts:
- - All contracts pay $1.00 (100 cents) if correct, $0 if wrong
- YES at 65¢: costs 65¢, pays $1.00 if YES wins → 35¢ profit per contract
- NO at 35¢: costs 35¢, pays $1.00 if NO wins → 65¢ profit per contract
- YES price + NO price ≈ 100¢ (spreads cause small deviations)
Before selling: Verify the user holds the position by checking portfolio first
Reference Documentation
Environment Variables
Required:
- -
KALSHI_API_KEY_ID — your Kalshi API key UUID - INLINECODE12 — absolute path to your RSA private key PEM file
See setup-guide.md for detailed configuration instructions.
Kalshi
通过独立的CLI脚本在Kalshi预测市场进行交易。支持市场搜索、投资组合跟踪以及完整的订单生命周期(下单/取消/监控)。
快速开始
所有命令均通过单个脚本路由。输出格式为JSON。
CLI
主脚本:
bash
{baseDir}/scripts/kalshi-cli.mjs <命令> [参数...]
辅助脚本:
bash
{baseDir}/scripts/quick-analysis.mjs <代码>
通过单次调用整合市场详情与订单簿,实现快速分析。
命令
| 命令 | 描述 |
|---|
| balance | 获取账户余额(现金 + 投资组合价值) |
| portfolio |
获取余额 + 所有未平仓头寸 |
| trending | 按24小时交易量排序的热门市场 |
| search <查询词> | 按关键词搜索市场 |
| market <代码> | 获取单个市场的详细信息 |
| orderbook <代码> | 获取市场的买卖盘口深度 |
| buy <代码> <是\|否> <数量> <价格> | 下达买入订单(价格单位为美分,范围1-99) |
| sell <代码> <是\|否> <数量> <价格> | 下达卖出订单(价格单位为美分,范围1-99) |
| cancel <订单ID> | 取消挂单 |
| orders [挂单\|已取消\|已成交] | 列出订单,可按状态筛选 |
| fills [代码] | 列出近期成交记录,可按代码筛选 |
示例
bash
查看余额
{baseDir}/scripts/kalshi-cli.mjs balance
查看热门市场
{baseDir}/scripts/kalshi-cli.mjs trending
搜索比特币相关市场
{baseDir}/scripts/kalshi-cli.mjs search bitcoin
获取特定市场详情
{baseDir}/scripts/kalshi-cli.mjs market KXBTCD-26FEB14-B55500
查看订单簿
{baseDir}/scripts/kalshi-cli.mjs orderbook KXBTCD-26FEB14-B55500
以65美分买入5份YES合约
{baseDir}/scripts/kalshi-cli.mjs buy KXBTCD-26FEB14-B55500 yes 5 65
以70美分卖出5份YES合约
{baseDir}/scripts/kalshi-cli.mjs sell KXBTCD-26FEB14-B55500 yes 5 70
查看未成交订单
{baseDir}/scripts/kalshi-cli.mjs orders resting
查看近期成交记录
{baseDir}/scripts/kalshi-cli.mjs fills
输出
所有命令均输出JSON格式到标准输出。解析结果后呈现给用户。
交易规则
关键提示: 在下达任何买入或卖出订单前,务必与用户确认。
执行交易前,向用户展示以下信息:
- - 代码
- 方向(YES或NO)
- 数量(合约份数)
- 价格(美分)
- 总成本 = 数量 × 价格(美分)= $X.XX
价格格式:
- - 价格单位为美分(1-99)
- 65美分 = 每份合约$0.65
- 最低:1美分,最高:99美分
收益结算:
- - 所有合约若预测正确支付$1.00(100美分),错误则支付$0
- YES合约65美分:成本65美分,若YES获胜支付$1.00 → 每份合约利润35美分
- NO合约35美分:成本35美分,若NO获胜支付$1.00 → 每份合约利润65美分
- YES价格 + NO价格 ≈ 100美分(价差导致微小偏差)
卖出前: 先检查投资组合,确认用户持有该头寸
参考文档
环境变量
必需变量:
- - KALSHIAPIKEYID — 您的Kalshi API密钥UUID
- KALSHIPRIVATEKEYPATH — RSA私钥PEM文件的绝对路径
详细配置说明请参见 setup-guide.md。