kalshi-trading-bot-cli 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +360 -0
- package/assets/kalshi-flow-light.png +0 -0
- package/assets/screenshot.png +0 -0
- package/env.example +43 -0
- package/kalshi-flow-light.png +0 -0
- package/package.json +66 -0
- package/src/agent/agent.ts +249 -0
- package/src/agent/channels.ts +53 -0
- package/src/agent/index.ts +29 -0
- package/src/agent/prompts.ts +171 -0
- package/src/agent/run-context.ts +23 -0
- package/src/agent/scratchpad.ts +465 -0
- package/src/agent/token-counter.ts +33 -0
- package/src/agent/tool-executor.ts +166 -0
- package/src/agent/types.ts +221 -0
- package/src/audit/index.ts +25 -0
- package/src/audit/reader.ts +43 -0
- package/src/audit/trail.ts +29 -0
- package/src/audit/types.ts +133 -0
- package/src/backtest/discovery.ts +170 -0
- package/src/backtest/fetcher.ts +247 -0
- package/src/backtest/metrics.ts +165 -0
- package/src/backtest/renderer.ts +196 -0
- package/src/backtest/types.ts +45 -0
- package/src/cli.ts +943 -0
- package/src/commands/alerts.ts +48 -0
- package/src/commands/analyze.ts +662 -0
- package/src/commands/backtest.ts +276 -0
- package/src/commands/clear-cache.ts +24 -0
- package/src/commands/config.ts +107 -0
- package/src/commands/dispatch.ts +473 -0
- package/src/commands/edge.ts +62 -0
- package/src/commands/formatters.ts +339 -0
- package/src/commands/help.ts +263 -0
- package/src/commands/helpers.ts +48 -0
- package/src/commands/index.ts +287 -0
- package/src/commands/json.ts +43 -0
- package/src/commands/parse-args.ts +229 -0
- package/src/commands/portfolio.ts +236 -0
- package/src/commands/review.ts +176 -0
- package/src/commands/scan-formatters.ts +98 -0
- package/src/commands/scan.ts +38 -0
- package/src/commands/search-edge.ts +139 -0
- package/src/commands/status.ts +70 -0
- package/src/commands/themes.ts +117 -0
- package/src/commands/watch.ts +295 -0
- package/src/components/answer-box.ts +57 -0
- package/src/components/approval-prompt.ts +34 -0
- package/src/components/browse-list.ts +134 -0
- package/src/components/chat-log.ts +291 -0
- package/src/components/custom-editor.ts +18 -0
- package/src/components/debug-panel.ts +52 -0
- package/src/components/index.ts +17 -0
- package/src/components/intro.ts +92 -0
- package/src/components/select-list.ts +155 -0
- package/src/components/tool-event.ts +127 -0
- package/src/components/user-query.ts +18 -0
- package/src/components/working-indicator.ts +87 -0
- package/src/controllers/agent-runner.ts +283 -0
- package/src/controllers/browse.ts +1013 -0
- package/src/controllers/index.ts +7 -0
- package/src/controllers/input-history.ts +76 -0
- package/src/controllers/model-selection.ts +244 -0
- package/src/db/alerts.ts +77 -0
- package/src/db/edge.ts +105 -0
- package/src/db/event-index.ts +323 -0
- package/src/db/events.ts +41 -0
- package/src/db/index.ts +60 -0
- package/src/db/octagon-cache.ts +118 -0
- package/src/db/positions.ts +71 -0
- package/src/db/risk.ts +51 -0
- package/src/db/schema.ts +227 -0
- package/src/db/themes.ts +34 -0
- package/src/db/trades.ts +50 -0
- package/src/eval/brier.ts +90 -0
- package/src/eval/index.ts +4 -0
- package/src/eval/performance.ts +87 -0
- package/src/gateway/access-control.ts +253 -0
- package/src/gateway/agent-runner.ts +75 -0
- package/src/gateway/alerts/formatter.ts +90 -0
- package/src/gateway/alerts/index.ts +4 -0
- package/src/gateway/alerts/router.ts +32 -0
- package/src/gateway/alerts/terminal.ts +16 -0
- package/src/gateway/alerts/types.ts +13 -0
- package/src/gateway/channels/index.ts +9 -0
- package/src/gateway/channels/manager.ts +153 -0
- package/src/gateway/channels/types.ts +48 -0
- package/src/gateway/channels/whatsapp/README.md +234 -0
- package/src/gateway/channels/whatsapp/auth-store.ts +140 -0
- package/src/gateway/channels/whatsapp/dedupe.ts +60 -0
- package/src/gateway/channels/whatsapp/error.ts +122 -0
- package/src/gateway/channels/whatsapp/inbound.ts +326 -0
- package/src/gateway/channels/whatsapp/index.ts +5 -0
- package/src/gateway/channels/whatsapp/lid.ts +56 -0
- package/src/gateway/channels/whatsapp/logger.ts +25 -0
- package/src/gateway/channels/whatsapp/login.ts +94 -0
- package/src/gateway/channels/whatsapp/outbound.ts +119 -0
- package/src/gateway/channels/whatsapp/plugin.ts +54 -0
- package/src/gateway/channels/whatsapp/reconnect.ts +40 -0
- package/src/gateway/channels/whatsapp/runtime.ts +122 -0
- package/src/gateway/channels/whatsapp/session.ts +89 -0
- package/src/gateway/channels/whatsapp/types.ts +32 -0
- package/src/gateway/commands/handler.ts +64 -0
- package/src/gateway/commands/index.ts +7 -0
- package/src/gateway/commands/parser.ts +29 -0
- package/src/gateway/commands/wa-formatters.ts +92 -0
- package/src/gateway/config.ts +244 -0
- package/src/gateway/extension-points.ts +17 -0
- package/src/gateway/gateway.ts +301 -0
- package/src/gateway/group/history-buffer.ts +75 -0
- package/src/gateway/group/index.ts +8 -0
- package/src/gateway/group/member-tracker.ts +60 -0
- package/src/gateway/group/mention-detection.ts +42 -0
- package/src/gateway/heartbeat/index.ts +8 -0
- package/src/gateway/heartbeat/prompt.ts +73 -0
- package/src/gateway/heartbeat/runner.ts +200 -0
- package/src/gateway/heartbeat/suppression.ts +74 -0
- package/src/gateway/index.ts +138 -0
- package/src/gateway/routing/resolve-route.ts +119 -0
- package/src/gateway/sessions/store.ts +65 -0
- package/src/gateway/types.ts +11 -0
- package/src/gateway/utils.ts +82 -0
- package/src/index.tsx +30 -0
- package/src/model/llm.ts +247 -0
- package/src/providers.ts +94 -0
- package/src/risk/circuit-breaker.ts +113 -0
- package/src/risk/correlation.ts +40 -0
- package/src/risk/gate.ts +125 -0
- package/src/risk/index.ts +10 -0
- package/src/risk/kelly.ts +230 -0
- package/src/scan/alerter.ts +64 -0
- package/src/scan/edge-computer.ts +164 -0
- package/src/scan/invoker.ts +199 -0
- package/src/scan/loop.ts +184 -0
- package/src/scan/octagon-client.ts +627 -0
- package/src/scan/octagon-events-api.ts +105 -0
- package/src/scan/octagon-prefetch.ts +172 -0
- package/src/scan/theme-resolver.ts +179 -0
- package/src/scan/types.ts +62 -0
- package/src/scan/watchdog.ts +126 -0
- package/src/setup/wizard.ts +659 -0
- package/src/theme.ts +67 -0
- package/src/tools/fetch/cache.ts +95 -0
- package/src/tools/fetch/external-content.ts +200 -0
- package/src/tools/fetch/index.ts +1 -0
- package/src/tools/fetch/web-fetch-utils.ts +122 -0
- package/src/tools/fetch/web-fetch.ts +419 -0
- package/src/tools/index.ts +10 -0
- package/src/tools/kalshi/api.ts +251 -0
- package/src/tools/kalshi/dlq.ts +35 -0
- package/src/tools/kalshi/events.ts +84 -0
- package/src/tools/kalshi/exchange.ts +24 -0
- package/src/tools/kalshi/historical.ts +89 -0
- package/src/tools/kalshi/index.ts +11 -0
- package/src/tools/kalshi/kalshi-search.ts +437 -0
- package/src/tools/kalshi/kalshi-trade.ts +102 -0
- package/src/tools/kalshi/markets.ts +76 -0
- package/src/tools/kalshi/portfolio.ts +100 -0
- package/src/tools/kalshi/search-index.ts +198 -0
- package/src/tools/kalshi/series.ts +16 -0
- package/src/tools/kalshi/trading.ts +115 -0
- package/src/tools/kalshi/types.ts +199 -0
- package/src/tools/registry.ts +160 -0
- package/src/tools/search/index.ts +25 -0
- package/src/tools/search/tavily.ts +35 -0
- package/src/tools/types.ts +53 -0
- package/src/tools/v2/edge-query.ts +135 -0
- package/src/tools/v2/octagon-report.ts +112 -0
- package/src/tools/v2/portfolio-query.ts +79 -0
- package/src/tools/v2/portfolio-review.ts +59 -0
- package/src/tools/v2/risk-status.ts +94 -0
- package/src/tools/v2/scan.ts +78 -0
- package/src/types/qrcode-terminal.d.ts +7 -0
- package/src/types/whiskeysockets-baileys.d.ts +41 -0
- package/src/types.ts +22 -0
- package/src/utils/ai-message.ts +26 -0
- package/src/utils/bot-config.ts +219 -0
- package/src/utils/cache.ts +195 -0
- package/src/utils/config.ts +113 -0
- package/src/utils/env.ts +111 -0
- package/src/utils/errors.ts +313 -0
- package/src/utils/history-context.ts +32 -0
- package/src/utils/in-memory-chat-history.ts +268 -0
- package/src/utils/index.ts +28 -0
- package/src/utils/input-key-handlers.ts +64 -0
- package/src/utils/logger.ts +67 -0
- package/src/utils/long-term-chat-history.ts +138 -0
- package/src/utils/markdown-table.ts +227 -0
- package/src/utils/model.ts +70 -0
- package/src/utils/ollama.ts +37 -0
- package/src/utils/paths.ts +12 -0
- package/src/utils/progress-channel.ts +84 -0
- package/src/utils/telemetry.ts +103 -0
- package/src/utils/text-navigation.ts +81 -0
- package/src/utils/thinking-verbs.ts +18 -0
- package/src/utils/tokens.ts +36 -0
- package/src/utils/tool-description.ts +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Octagon AI, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
# Kalshi Trading Bot CLI
|
|
2
|
+
|
|
3
|
+
AI-powered Kalshi trading CLI that finds edge and executes trades.
|
|
4
|
+
|
|
5
|
+
Runs deep fundamental research on every market — independent probability estimates, ranked price drivers, catalyst calendars — then computes edge as the spread between model price and the live order book. Signals are sized using half-Kelly and filtered through a 5-gate risk engine before a dollar is risked.
|
|
6
|
+
|
|
7
|
+
Integrates with the [Octagon Research API](https://app.octagonai.co) for AI-generated probability estimates that power the edge detection engine.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Install [Bun](https://bun.com/), then run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bunx kalshi-trading-bot-cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
That's it — no clone, no install. The setup wizard runs automatically on first launch and walks you through API keys.
|
|
20
|
+
|
|
21
|
+
Prefer a global install? `bun add -g kalshi-trading-bot-cli` then run `kalshi`.
|
|
22
|
+
|
|
23
|
+
Or work from a clone:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
git clone https://github.com/OctagonAI/kalshi-trading-bot-cli.git
|
|
27
|
+
cd kalshi-trading-bot-cli
|
|
28
|
+
bun install
|
|
29
|
+
bun start
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> Don't have Bun? Install it with `curl -fsSL https://bun.com/install | bash`
|
|
33
|
+
|
|
34
|
+
### Where things live
|
|
35
|
+
|
|
36
|
+
- **Config, cache, SQLite DB:** `~/.kalshi-bot/`
|
|
37
|
+
- **API keys (`.env`):** `~/.kalshi-bot/.env` — written by the setup wizard. A `.env` in the current directory takes precedence (handy for dev).
|
|
38
|
+
- **First run** with no keys configured triggers the setup wizard automatically.
|
|
39
|
+
|
|
40
|
+
## Example Session
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
$ bunx kalshi-trading-bot-cli
|
|
44
|
+
|
|
45
|
+
Welcome to Kalshi Trading Bot CLI
|
|
46
|
+
Type help for commands, or just ask a question.
|
|
47
|
+
|
|
48
|
+
> search crypto
|
|
49
|
+
|
|
50
|
+
Ticker Title Last Volume
|
|
51
|
+
KXBTC-26APR-B95000 Bitcoin above $95k by Apr 30 $0.58 12,841
|
|
52
|
+
KXBTC-26APR-B100000 Bitcoin above $100k by Apr 30 $0.31 8,203
|
|
53
|
+
KXETH-26APR-B2000 Ethereum above $2k by Apr 30 $0.72 5,419
|
|
54
|
+
|
|
55
|
+
3 markets found
|
|
56
|
+
|
|
57
|
+
> analyze KXBTC-26APR-B95000
|
|
58
|
+
|
|
59
|
+
Octagon Research Report — KXBTC-26APR-B95000
|
|
60
|
+
─────────────────────────────────────────────
|
|
61
|
+
Model Probability 72%
|
|
62
|
+
Market Price 58%
|
|
63
|
+
Edge +14.0% (very_high confidence)
|
|
64
|
+
|
|
65
|
+
Top Drivers
|
|
66
|
+
1. Bitcoin ETF inflows accelerating impact: high
|
|
67
|
+
2. Halving cycle momentum impact: high
|
|
68
|
+
3. Macro risk-on sentiment impact: moderate
|
|
69
|
+
|
|
70
|
+
Kelly Sizing
|
|
71
|
+
Recommended: 3 contracts YES at $0.58
|
|
72
|
+
Risk gates: ✓ Kelly ✓ Liquidity ✓ Correlation ✓ Concentration ✓ Drawdown
|
|
73
|
+
|
|
74
|
+
> buy KXBTC-26APR-B95000 3 58
|
|
75
|
+
|
|
76
|
+
✓ Order placed: BUY 3 YES @ $0.58
|
|
77
|
+
Order ID: abc-123-def
|
|
78
|
+
|
|
79
|
+
> portfolio
|
|
80
|
+
|
|
81
|
+
Ticker Side Qty Entry Now Edge P&L
|
|
82
|
+
KXBTC-26APR-B95000 YES 3 $0.58 $0.61 +11.0% +$0.09
|
|
83
|
+
|
|
84
|
+
Cash: $487.26 · Exposure: $1.74 · Positions: 1
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Commands
|
|
88
|
+
|
|
89
|
+
| Command | Description |
|
|
90
|
+
|---------|-------------|
|
|
91
|
+
| `search [theme\|ticker\|query]` | Find markets by keyword or theme |
|
|
92
|
+
| `search edge [--min-edge N]` | Scan all markets by model edge |
|
|
93
|
+
| `analyze <ticker>` | Deep analysis: edge, drivers, Kelly sizing |
|
|
94
|
+
| `watch <ticker>` | Live price and orderbook feed |
|
|
95
|
+
| `watch --theme <theme>` | Continuous theme scan |
|
|
96
|
+
| `buy <ticker> <count> [price] [yes\|no]` | Buy contracts |
|
|
97
|
+
| `sell <ticker> <count> [price] [yes\|no]` | Sell contracts |
|
|
98
|
+
| `cancel <order_id>` | Cancel a resting order |
|
|
99
|
+
| `backtest` | Model accuracy scorecard + live edge scanner |
|
|
100
|
+
| `portfolio` | Positions, P&L, risk snapshot |
|
|
101
|
+
| `setup` | Re-run setup wizard (inside TUI) |
|
|
102
|
+
| `init` | Launch setup wizard from CLI (`kalshi init`) |
|
|
103
|
+
| `clear-cache` | Delete local cache and rebuild (`kalshi clear-cache`) |
|
|
104
|
+
| `help [command]` | Detailed help for a command |
|
|
105
|
+
|
|
106
|
+
### Flags
|
|
107
|
+
|
|
108
|
+
| Flag | Description |
|
|
109
|
+
|------|-------------|
|
|
110
|
+
| `--json` | JSON output for scripts and agents |
|
|
111
|
+
| `--refresh` | Force fresh Octagon report (analyze) |
|
|
112
|
+
| `--performance` | Include win rate, Sharpe, Brier scores (portfolio) |
|
|
113
|
+
| `--dry-run` | Scan without persisting edges (watch) |
|
|
114
|
+
| `--verbose` | Verbose output |
|
|
115
|
+
| `--min-edge <n>` | Minimum edge threshold in pp (backtest default 0.5) |
|
|
116
|
+
| `--interval <min>` | Scan interval in minutes (watch) |
|
|
117
|
+
| `--live` | Force 15m scan interval (watch) |
|
|
118
|
+
| `--days <n>` | Lookback period in days (backtest, default 15) |
|
|
119
|
+
| `--max-age <n>` | Reject predictions older than N days (backtest, default = `--days`) |
|
|
120
|
+
| `--resolved` | Resolved markets only (backtest) |
|
|
121
|
+
| `--unresolved` | Open markets only (backtest) |
|
|
122
|
+
| `--category <cat>` | Filter by category (backtest, search edge) |
|
|
123
|
+
| `--limit <n>` | Max results to show (search edge, default 20) |
|
|
124
|
+
| `--min-volume <n>` | Min per-contract volume (from Octagon snapshot; falls back to Kalshi lifetime if missing). Backtest default 1. |
|
|
125
|
+
| `--min-price <n>` | Min contract price, 0-100 scale (backtest, default 5) |
|
|
126
|
+
| `--max-price <n>` | Max contract price, 0-100 scale (backtest, default 95) |
|
|
127
|
+
| `--export <path>` | Export per-market CSV (backtest) |
|
|
128
|
+
|
|
129
|
+
### Backtesting
|
|
130
|
+
|
|
131
|
+
Does the model find real edge? Look back N days, compare what the model said then to where the market is now.
|
|
132
|
+
|
|
133
|
+
- **Resolved** — scored against Kalshi settlement (YES=100%, NO=0%)
|
|
134
|
+
- **Unresolved** — mark-to-market vs current Kalshi trading price
|
|
135
|
+
|
|
136
|
+
**Methodology (matches Supabase reference):**
|
|
137
|
+
- Per-contract `mp`/`kp` come from `outcome_probabilities` on each Octagon snapshot — no event-level fallback.
|
|
138
|
+
- Tradeability gate uses per-contract `volume`/`volume_24h` from the snapshot when present; falls back to Kalshi lifetime volume for pre-API-change cached snapshots.
|
|
139
|
+
- `--min-edge` defaults to 0.5pp so the 0-5% edge bucket stays visible; each signal is tagged with an `edge_bucket` label (`0-5%`, `5-10%`, ..., `90%+`).
|
|
140
|
+
- `flat_bet_roi` is capital-weighted: `sum(pnl) / sum(capital)`, where `capital = kp/100` for YES edges and `(100 - kp)/100` for NO edges.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
kalshi backtest # 15-day lookback (default)
|
|
144
|
+
kalshi backtest --days 30 # 30-day lookback
|
|
145
|
+
kalshi backtest --max-age 14 # only score predictions <=14d old
|
|
146
|
+
kalshi backtest --resolved # resolved only
|
|
147
|
+
kalshi backtest --unresolved --min-edge 10 # unresolved, 10pp threshold
|
|
148
|
+
kalshi backtest --category crypto # filter by category
|
|
149
|
+
kalshi backtest --min-volume 10 --min-price 5 --max-price 95 # tradeable contracts only
|
|
150
|
+
kalshi backtest --export results.csv # per-market detail
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
Octagon Backtest — 15-day lookback (04/02 – 04/17)
|
|
155
|
+
══════════════════════════════════════════════════════════
|
|
156
|
+
|
|
157
|
+
VERDICT: Model has edge (Skill +12.5% [CI: +4.1%, +20.8%]; ROI +7.8%)
|
|
158
|
+
|
|
159
|
+
Events 83
|
|
160
|
+
Markets 247 (142 resolved, 105 unresolved)
|
|
161
|
+
Brier (Octagon) 0.168
|
|
162
|
+
Brier (Market) 0.192
|
|
163
|
+
Skill Score +12.5% [95% CI: +4.1% to +20.8%]
|
|
164
|
+
Hit rate 61.4% [95% CI: 54.2% to 68.1%]
|
|
165
|
+
Flat-bet P&L +$14.38 (ROI: +7.8%)
|
|
166
|
+
|
|
167
|
+
RESOLVED (142 markets)
|
|
168
|
+
Ticker Model Mkt Then Outcome Edge P&L
|
|
169
|
+
KXBTC-26APR-B95000 72% 58% YES 100% +14pp +$0.42
|
|
170
|
+
...
|
|
171
|
+
|
|
172
|
+
UNRESOLVED (105 markets)
|
|
173
|
+
Ticker Model Mkt Then Now Edge M2M
|
|
174
|
+
KXBTC-26MAY-B110000 71% 58% 68% +13pp +$0.10
|
|
175
|
+
...
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Demo Mode
|
|
179
|
+
|
|
180
|
+
Set `KALSHI_USE_DEMO=true` in your `.env` to use Kalshi's demo environment. All trades are simulated — no real money at risk.
|
|
181
|
+
|
|
182
|
+
## Agent Usage
|
|
183
|
+
|
|
184
|
+
Every command supports `--json` for structured output, making the bot easy to orchestrate from scripts or AI agents.
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
kalshi search crypto --json
|
|
188
|
+
kalshi analyze KXBTC-26APR-B95000 --json
|
|
189
|
+
kalshi buy KXBTC-26APR-B95000 3 58 --json
|
|
190
|
+
kalshi portfolio --json
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### JSON Response Format
|
|
194
|
+
|
|
195
|
+
All responses follow the same envelope:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"ok": true,
|
|
200
|
+
"command": "analyze",
|
|
201
|
+
"data": {
|
|
202
|
+
"ticker": "KXBTC-26APR-B95000",
|
|
203
|
+
"modelProb": 0.72,
|
|
204
|
+
"marketProb": 0.58,
|
|
205
|
+
"edge": 0.14,
|
|
206
|
+
"confidence": "very_high",
|
|
207
|
+
"drivers": [
|
|
208
|
+
{ "claim": "Bitcoin ETF inflows accelerating", "impact": "high" }
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
"meta": {
|
|
212
|
+
"octagon_credits_used": 3,
|
|
213
|
+
"octagon_cache_hits": 0
|
|
214
|
+
},
|
|
215
|
+
"timestamp": "2026-03-30T10:00:00.000Z"
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Errors return `"ok": false` with an `error` object containing `code` and `message`. Exit code is 0 for success, 1 for failure.
|
|
220
|
+
|
|
221
|
+
### Example Orchestration Flow
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# 1. Find markets
|
|
225
|
+
MARKETS=$(kalshi search crypto --json | jq '.data')
|
|
226
|
+
|
|
227
|
+
# 2. Analyze top pick
|
|
228
|
+
ANALYSIS=$(kalshi analyze KXBTC-26APR-B95000 --json)
|
|
229
|
+
EDGE=$(echo "$ANALYSIS" | jq '.data.edge')
|
|
230
|
+
|
|
231
|
+
# 3. Trade if edge is high enough
|
|
232
|
+
if (( $(echo "$EDGE > 0.05" | bc -l) )); then
|
|
233
|
+
kalshi buy KXBTC-26APR-B95000 3 58 --json
|
|
234
|
+
fi
|
|
235
|
+
|
|
236
|
+
# 4. Check portfolio
|
|
237
|
+
kalshi portfolio --json
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The `watch --theme` command outputs NDJSON (one JSON object per scan cycle), suitable for streaming pipelines.
|
|
241
|
+
|
|
242
|
+
## Configuration
|
|
243
|
+
|
|
244
|
+
### Environment Variables
|
|
245
|
+
|
|
246
|
+
The setup wizard (run automatically on first launch, or invoke with `kalshi init`) handles this interactively. To edit by hand:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
cp env.example ~/.kalshi-bot/.env
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Required:**
|
|
253
|
+
|
|
254
|
+
| Variable | Description |
|
|
255
|
+
|----------|-------------|
|
|
256
|
+
| `KALSHI_API_KEY` | Kalshi API key ID |
|
|
257
|
+
| `KALSHI_PRIVATE_KEY_FILE` | Path to your Kalshi RSA private key PEM file |
|
|
258
|
+
| `OPENAI_API_KEY` | OpenAI API key (default model is GPT-5.4) |
|
|
259
|
+
| `OCTAGON_API_KEY` | Octagon API key for deep research. Get one at [app.octagonai.co](https://app.octagonai.co) |
|
|
260
|
+
|
|
261
|
+
**Optional:**
|
|
262
|
+
|
|
263
|
+
| Variable | Description |
|
|
264
|
+
|----------|-------------|
|
|
265
|
+
| `KALSHI_USE_DEMO` | `true` for demo environment (simulated trades) |
|
|
266
|
+
| `KALSHI_PRIVATE_KEY` | Inline PEM key as alternative to file path |
|
|
267
|
+
| `ANTHROPIC_API_KEY` | Anthropic (Claude) |
|
|
268
|
+
| `GOOGLE_API_KEY` | Google (Gemini) |
|
|
269
|
+
| `XAI_API_KEY` | xAI (Grok) |
|
|
270
|
+
| `OPENROUTER_API_KEY` | OpenRouter (multi-model) |
|
|
271
|
+
| `TAVILY_API_KEY` | Tavily web search for event research |
|
|
272
|
+
|
|
273
|
+
> **Note:** The bot defaults to GPT-5.4. If using a different provider, switch the model via the `config` command — otherwise queries will fail without `OPENAI_API_KEY`.
|
|
274
|
+
|
|
275
|
+
### Octagon Credits
|
|
276
|
+
|
|
277
|
+
Each Octagon report costs 3 credits. Reports are cached with tiered TTLs based on market close proximity — markets closing soon get shorter cache windows. Use `--refresh` to force a fresh report. Set a daily credit ceiling with `config octagon.daily_credit_ceiling <n>`.
|
|
278
|
+
|
|
279
|
+
### Runtime Settings
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
kalshi config # List all settings
|
|
283
|
+
kalshi config risk.kelly_multiplier # Get a value
|
|
284
|
+
kalshi config risk.kelly_multiplier 0.3 # Set a value
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
| Setting | Default | Description |
|
|
288
|
+
|---------|---------|-------------|
|
|
289
|
+
| `scan.interval` | `60` | Scan interval in minutes |
|
|
290
|
+
| `scan.theme` | `top50` | Default market theme |
|
|
291
|
+
| `risk.kelly_multiplier` | `0.5` | Kelly fraction (0.5 = half-Kelly) |
|
|
292
|
+
| `risk.max_drawdown` | `0.20` | Max drawdown before circuit breaker |
|
|
293
|
+
| `risk.max_positions` | `10` | Max concurrent open positions |
|
|
294
|
+
| `risk.max_per_category` | `3` | Max positions per event category |
|
|
295
|
+
| `risk.daily_loss_limit` | `200` | Daily loss limit in dollars |
|
|
296
|
+
| `octagon.daily_credit_ceiling` | `100` | Max Octagon credits per day |
|
|
297
|
+
| `alerts.min_edge` | `0.05` | Minimum edge to trigger an alert |
|
|
298
|
+
|
|
299
|
+
## Architecture
|
|
300
|
+
|
|
301
|
+

|
|
302
|
+
|
|
303
|
+
The CLI talks to two external services: the Kalshi exchange API (market data, order placement, portfolio) and the Octagon research API (AI probability estimates, price drivers). Results are cached in a local SQLite database to minimize API calls and credit usage.
|
|
304
|
+
|
|
305
|
+
### LLM Providers
|
|
306
|
+
|
|
307
|
+
Default model is GPT-5.4. Switch with the `config` command.
|
|
308
|
+
|
|
309
|
+
| Prefix | Provider |
|
|
310
|
+
|--------|----------|
|
|
311
|
+
| `gpt-` | OpenAI |
|
|
312
|
+
| `claude-` | Anthropic |
|
|
313
|
+
| `gemini-` | Google |
|
|
314
|
+
| `grok-` | xAI |
|
|
315
|
+
| `openrouter/` | OpenRouter |
|
|
316
|
+
| `ollama:` | Ollama (local) |
|
|
317
|
+
|
|
318
|
+
### Development
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
bun dev # Dev mode with hot reload
|
|
322
|
+
bun run typecheck # Type checking
|
|
323
|
+
bun test # Run tests
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Telemetry
|
|
327
|
+
|
|
328
|
+
This app collects anonymous usage telemetry to help improve the product.
|
|
329
|
+
**No personal data, API keys, trade details, or natural language inputs are ever collected.**
|
|
330
|
+
Only command names, tool usage, timing, and success/failure metrics are tracked.
|
|
331
|
+
|
|
332
|
+
Telemetry is enabled by default. To disable it, add to your `.env`:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
TELEMETRY_ENABLED=false
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Or set the environment variable before running:
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
TELEMETRY_ENABLED=false bunx kalshi-trading-bot-cli
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Documentation
|
|
345
|
+
|
|
346
|
+
See the [User Guide](GUIDE.md) for detailed usage instructions, examples, and tips.
|
|
347
|
+
|
|
348
|
+
## Star History
|
|
349
|
+
|
|
350
|
+
<a href="https://www.star-history.com/?repos=OctagonAI%2Fkalshi-trading-bot-cli&type=date&legend=top-left">
|
|
351
|
+
<picture>
|
|
352
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=OctagonAI/kalshi-trading-bot-cli&type=date&theme=dark&legend=top-left" />
|
|
353
|
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=OctagonAI/kalshi-trading-bot-cli&type=date&legend=top-left" />
|
|
354
|
+
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=OctagonAI/kalshi-trading-bot-cli&type=date&legend=top-left" />
|
|
355
|
+
</picture>
|
|
356
|
+
</a>
|
|
357
|
+
|
|
358
|
+
## License
|
|
359
|
+
|
|
360
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
|
Binary file
|
|
Binary file
|
package/env.example
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# ── Required ──────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
# Kalshi API
|
|
4
|
+
KALSHI_API_KEY=your-kalshi-api-key
|
|
5
|
+
# Private key — provide one of:
|
|
6
|
+
# Option 1 (recommended): path to your PEM file
|
|
7
|
+
KALSHI_PRIVATE_KEY_FILE=/path/to/kalshi-private-key.pem
|
|
8
|
+
# Option 2: paste the full PEM key directly with real newlines inside double quotes
|
|
9
|
+
# KALSHI_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
|
|
10
|
+
# MIIEpAIBAAKCAQEA...
|
|
11
|
+
# -----END RSA PRIVATE KEY-----"
|
|
12
|
+
|
|
13
|
+
# LLM provider (at least one required)
|
|
14
|
+
# ⚠️ The bot defaults to GPT-5.4 (OpenAI). If you use a different provider,
|
|
15
|
+
# change the default model here or via /model in the TUI.
|
|
16
|
+
DEFAULT_MODEL=gpt-5.4
|
|
17
|
+
# Examples for other providers:
|
|
18
|
+
# DEFAULT_MODEL=claude-sonnet-4-20250514
|
|
19
|
+
# DEFAULT_MODEL=gemini-2.5-pro
|
|
20
|
+
# DEFAULT_MODEL=grok-3
|
|
21
|
+
OPENAI_API_KEY=your-openai-api-key
|
|
22
|
+
ANTHROPIC_API_KEY=your-anthropic-api-key
|
|
23
|
+
GOOGLE_API_KEY=your-google-api-key
|
|
24
|
+
XAI_API_KEY=your-xai-api-key
|
|
25
|
+
OPENROUTER_API_KEY=your-openrouter-api-key
|
|
26
|
+
|
|
27
|
+
# Octagon AI — required for /scan, /watch, and deep research
|
|
28
|
+
# Get a key at https://app.octagonai.co
|
|
29
|
+
OCTAGON_API_KEY=your-octagon-api-key
|
|
30
|
+
|
|
31
|
+
# ── Optional ─────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
# Use Kalshi demo environment (simulated trades, no real money)
|
|
34
|
+
# KALSHI_USE_DEMO=false
|
|
35
|
+
|
|
36
|
+
# Web search for researching real-world events behind markets
|
|
37
|
+
# TAVILY_API_KEY=your-tavily-api-key
|
|
38
|
+
|
|
39
|
+
# Local LLM via Ollama (use /model in the TUI to switch)
|
|
40
|
+
# OLLAMA_BASE_URL=http://127.0.0.1:11434
|
|
41
|
+
|
|
42
|
+
# Anonymous usage telemetry (default: enabled). Set to false to disable.
|
|
43
|
+
# TELEMETRY_ENABLED=true
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kalshi-trading-bot-cli",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Kalshi Trading Bot CLI - AI-powered prediction market terminal.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Octagon AI, Inc.",
|
|
7
|
+
"homepage": "https://github.com/OctagonAI/kalshi-trading-bot-cli#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/OctagonAI/kalshi-trading-bot-cli.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/OctagonAI/kalshi-trading-bot-cli/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"kalshi",
|
|
17
|
+
"prediction-markets",
|
|
18
|
+
"trading-bot",
|
|
19
|
+
"cli",
|
|
20
|
+
"tui",
|
|
21
|
+
"ai",
|
|
22
|
+
"octagon",
|
|
23
|
+
"bun"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "src/index.tsx",
|
|
27
|
+
"bin": {
|
|
28
|
+
"kalshi": "./src/index.tsx",
|
|
29
|
+
"kalshi-trading-bot-cli": "./src/index.tsx"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"bun": ">=1.1.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"start": "bun run src/index.tsx",
|
|
40
|
+
"dev": "bun --watch run src/index.tsx",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"test:integration": "bun test **/*.itest.ts",
|
|
44
|
+
"test:watch": "bun test --watch",
|
|
45
|
+
"gateway:login": "bun run src/gateway/index.ts login",
|
|
46
|
+
"gateway": "bun run src/gateway/index.ts run"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@langchain/anthropic": "^1.1.3",
|
|
50
|
+
"@langchain/core": "^1.1.0",
|
|
51
|
+
"@langchain/google-genai": "^2.0.0",
|
|
52
|
+
"@langchain/ollama": "^1.0.3",
|
|
53
|
+
"@langchain/openai": "^1.1.3",
|
|
54
|
+
"@langchain/tavily": "^1.0.1",
|
|
55
|
+
"@mariozechner/pi-tui": "^0.52.9",
|
|
56
|
+
"@mozilla/readability": "^0.6.0",
|
|
57
|
+
"dotenv": "^17.2.3",
|
|
58
|
+
"langsmith": "^0.4.10",
|
|
59
|
+
"linkedom": "^0.18.12",
|
|
60
|
+
"zod": "^4.1.13"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/bun": "latest",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
65
|
+
}
|
|
66
|
+
}
|