kalshi-ai-trading-bot
ryanfrigo/kalshi-ai-trading-bot
- Type
- MCP server
- Scanned
- Nov 17, 2026
- Version
- 5d7b70addcc6
- Files read
- 385
... Wait! NO extra text outside JSON! Let me be 100% careful in the actual output! Let's check my thought vs output. In the final output I must ONLY output the raw JSON string. Let me output just {...}.` -> Good catch in thought! Generating pure JSON now. End of thought. Let's emit pure JSON.{
Findings
-
MediumClaude skill triggers autonomous live trading on read-only account check prompt and mixes web search with live execution
.claude/skills/kalshi-trade/SKILL.md:3
The kalshi-trade skill frontmatter includes 'check the Kalshi account' as an activation trigger, yet the skill body instructs the agent to run a continuous autonomous loop that searches untrusted web pages (WebSearch), places real-money orders via 'cli.py trade --live' without asking for user confirmation, and edits its own SKILL.md and persistent memory. A user asking only to check their account can trigger live trades, and prompt injection in searched web pages can steer the agent's trading decisions.
Fix: Remove read-only phrases like 'check the Kalshi account' from the skill triggers, require explicit user confirmation before passing --live or --override-policy, and do not instruct the agent to modify SKILL.md automatically.
-
MediumPer-position 10% equity cap values existing holdings at the new order's price, allowing multi-order cap bypass
place_guarded_order (backing cli.py trade and the MCP trade tool) claims an unbypassable 10% per-position equity cap, but _committed_cents multiplies existing held and resting contract counts by the new order's price_cents rather than their actual cost. If an account holds contracts bought at a high price (for example 90 cents) and a prompt-injected or averaging-down agent places subsequent orders on the same ticker at lower prices (or on the opposite side), existing exposure is severely undercounted and KalshiClient.place_order only checks single-order cost, allowing total capital committed to one ticker to exceed 10% of equity.
Fix: Sum actual market_exposure_dollars from Kalshi position rows and each resting order's own limit price times remaining contracts instead of multiplying contract counts by the new order's price_cents.
-
MediumNon-halted sell orders skip holdings, reduce_only, and position-cap checks in KalshiClient.place_order
src/clients/kalshi_client.py:589
On Kalshi's v2 unified orderbook, a sell order without reduce_only=True is just an ask or bid that opens an opposite-side position if it exceeds net sellable holdings. Although the comment in place_order states that sells are gated because a sell can open a short, place_order only checks _within_held and sets reduce_only=True when the governor is halted; when not halted, the else branch only checks POSITION_CAP for action=='buy'. Callers that do not net out existing resting exit orders—such as cli.py close-all --live when track.py already placed resting stop-loss/profit-take orders or when close-all is run twice—can flip the account into an uncapped opposite-side position.
Fix: Enforce holdings netting or reduce_only on sell orders during normal non-halted trading (or apply POSITION_CAP to any excess above net sellable holdings), and subtract resting sell orders in cli.py close-all.
-
MediumUnsafe pickle deserialization of CWD-relative daily AI usage files
src/clients/openrouter_client.py:184
OpenRouterClient (as well as XAIClient and evaluate.py) stores simple numeric cost counters using Python's pickle module at a relative path (logs/daily_openrouter_usage.pkl and logs/daily_ai_usage.pkl) and calls pickle.load() during initialization. If a user or coding agent runs the installed kalshi-bot console script (such as kalshi-bot verify or kalshi-bot run) from an untrusted directory or cloned repository containing a crafted .pkl file under logs/, pickle.load() will execute arbitrary code on the machine.
Fix: Replace pickle.load and pickle.dump with JSON serialization (matching risk_governor_state.json) and store usage files in an anchored runtime directory rather than a CWD-relative path.
-
MediumAutonomy slash command mixes untrusted GitHub issue and PR triage with live trading and git push
.claude/commands/autonomy-loop.md:49
The repository ships the author's personal /autonomy-loop Claude Code command, which runs live Kalshi trading, writes real account equity and P&L into docs/TRACK_RECORD.md, triages open GitHub issues and pull requests from strangers, runs pytest, and pushes commits and release tags to GitHub in one autonomous session. If an installer runs /autonomy-loop, prompt injection inside an untrusted GitHub issue or pull request can trick the agent into leaking .env or kalshi_private_key.pem in an issue response, pushing malicious code, or executing unauthorized live trades.
Fix: Remove .claude/commands/autonomy-loop.md from the public repository (or keep it in untracked local config) and never process untrusted GitHub issues or pull requests in an agent session that has live exchange credentials or git push access.
-
LowCWD-relative Edge Policy and journal paths silently bypass trade blocks in MCP hosts
Unlike RiskGovernor, which anchors its files to the repository root and honors KALSHI_RUNTIME_DIR, policy.py (along with journal.py, settle.py, and learnings.py) resolves data/runtime/edge_policy.json relative to the current working directory. When kalshi-mcp is spawned by an MCP client such as Claude Desktop (where cwd is typically / or $HOME) or when KALSHI_RUNTIME_DIR is set, load_policy() fails to find the saved policy, returns None, and place_guarded_order silently skips all learned category blocks and overconfidence haircuts; if cwd is read-only, append_decision() also crashes after the live order has already been placed on Kalshi.
Fix: Resolve DEFAULT_POLICY_PATH, DEFAULT_JOURNAL_PATH, DEFAULT_SETTLEMENTS_PATH, and DEFAULT_LEARNINGS_PATH through the same KALSHI_RUNTIME_DIR and _REPO_ROOT helper used by src/risk/risk_governor.py.
-
LowUnescaped market fields and LLM reasoning in static paper-trading HTML dashboard
generate_html() interpolates market_id, truncated market_title, and truncated LLM reasoning directly into docs/paper_dashboard.html without calling _escape() (which is only applied to the reasoning title attribute). Because reasoning summarizes external RSS news articles and market metadata, crafted HTML or script tags in external content or model output can execute JavaScript if the user opens or hosts the generated HTML file.
Fix: Wrap market_id, _trunc(s['market_title'], 50), side, strategy, outcome_badge fallback, and _trunc(s['reasoning'], 40) with _escape() before interpolating into HTML.
-
LowPlaintext HTTP requests and unvalidated snapshot timestamps in Wayback backfill script
The offline backfill commands in scripts/aaa_data.py (and scripts/build_backtest_outcomes.py) fetch Wayback Machine CDX listings and archived pages over unencrypted http:// rather than https://, and write responses to RAW_DIR / f'{ts}.html' without checking that ts contains only digits. During a manual backfill run, a network attacker could tamper with historical pricing data or use path traversal sequences in ts to write .html files outside RAW_DIR.
Fix: Use https://web.archive.org URLs and validate that each snapshot timestamp matches re.fullmatch(r'\d{14}', ts) before constructing file paths.
