Prediction Market Watcher
Connects to Kalshi (and Polymarket) to track positions, scan markets, and place bets.
Setup
Kalshi (live trading, US):
- - API key + RSA private key required
- Config lives at
kalshi-agent/config.json in the workspace - Key file: INLINECODE1
- Scripts use
kalshi_client.py with RSA-PSS signed requests
Polymarket (coming soon — read-only via public API for now)
Common Tasks
Check portfolio / open positions
CODEBLOCK0
Check a specific market
from kalshi_client import KalshiClient
import json
c = KalshiClient('KEY_ID', 'kalshi.key')
market = c.get('/trade-api/v2/markets/TICKER_HERE')
print(json.dumps(market, indent=2))
Key fields:
yes_bid_dollars,
yes_ask_dollars,
floor_strike,
cap_strike,
close_time, INLINECODE8
Check BTC/crypto price vs bet range
- - Fetch live price via web search or Brave API
- Compare against
floor_strike / cap_strike from market data - Settlement uses CF Benchmarks RTI (60s avg before close) — not Coinbase/Google price
Scan for opportunities
CODEBLOCK2
Place a bet (manual)
order = c.create_order(ticker="TICKER", side="yes", action="buy", count=N, limit_price=CENTS)
- -
limit_price is in cents (e.g. 8 = $0.08) - INLINECODE12 = number of $1 contracts
- Always check
risk_state.json limits before placing
Settlement reminders
- - Use a cron job scheduled ~15 min before INLINECODE14
- Message Katie on Telegram with: current price, range, whether we're in/out, time remaining
Risk Rules (from risk.py)
- - Max $20/day budget
- Max 5 open positions
- Max single bet: $5 (high confidence), $3 (medium), $1 (low)
- Check
can_bet() before any auto-place
API Base URL
INLINECODE16
Key endpoints:
- -
GET /portfolio/positions → open positions (use /trade-api/v2/portfolio/positions) - INLINECODE19 → single market detail
- INLINECODE20 → scan markets
- INLINECODE21 → balance + portfolio value
- INLINECODE22 → place order
See references/kalshi-api.md for full endpoint reference.
Polymarket (read-only)
Public REST API — no auth needed for reads:
GET https://gamma-api.polymarket.com/markets?active=true&limit=20
See
references/polymarket-api.md for details.
预测市场观察器
连接至Kalshi(及Polymarket)以追踪持仓、扫描市场并下注。
设置
Kalshi(实盘交易,美国):
- - 需要API密钥 + RSA私钥
- 配置文件位于工作区中的kalshi-agent/config.json
- 密钥文件:kalshi-agent/kalshi.key
- 脚本使用带有RSA-PSS签名请求的kalshi_client.py
Polymarket(即将推出——目前仅通过公共API提供只读功能)
常见任务
查看投资组合/未平仓头寸
bash
cd ~/workspace/kalshi-agent && python3 kalshi_agent.py --status
cd ~/workspace/kalshi-agent && python3 kalshi_agent.py --positions
查看特定市场
python
from kalshi_client import KalshiClient
import json
c = KalshiClient(KEY_ID, kalshi.key)
market = c.get(/trade-api/v2/markets/TICKER_HERE)
print(json.dumps(market, indent=2))
关键字段:yesbiddollars、yesaskdollars、floorstrike、capstrike、closetime、rulesprimary
查看BTC/加密货币价格与投注范围对比
- - 通过网络搜索或Brave API获取实时价格
- 与市场数据中的floorstrike/capstrike进行比较
- 结算使用CF Benchmarks RTI(收盘前60秒平均值)——非Coinbase/Google价格
扫描机会
bash
cd ~/workspace/kalshi-agent && python3 kalshi_agent.py --scan
手动下注
python
order = c.create
order(ticker=TICKER, side=yes, action=buy, count=N, limitprice=CENTS)
- - limitprice以美分计(例如8 = $0.08)
- count = 1美元合约数量
- 下单前务必检查riskstate.json中的限制
结算提醒
- - 使用定时任务,在close_time前约15分钟触发
- 通过Telegram向Katie发送消息,内容包括:当前价格、范围、我们是否在范围内、剩余时间
风险规则(来自risk.py)
- - 每日最高预算$20
- 最多5个未平仓头寸
- 单笔最大投注:$5(高置信度)、$3(中等)、$1(低)
- 任何自动下单前需检查can_bet()
API基础URL
https://api.elections.kalshi.com/trade-api/v2/
关键端点:
- - GET /portfolio/positions → 未平仓头寸(使用/trade-api/v2/portfolio/positions)
- GET /markets/{ticker} → 单个市场详情
- GET /markets?status=open&limit=100 → 扫描市场
- GET /portfolio/balance → 余额及投资组合价值
- POST /portfolio/orders → 下单
完整端点参考见references/kalshi-api.md。
Polymarket(只读)
公共REST API——读取无需认证:
GET https://gamma-api.polymarket.com/markets?active=true&limit=20
详情见references/polymarket-api.md。