@spfunctions/cli 1.7.17 → 1.7.20

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.
Files changed (180) hide show
  1. package/dist/101.index.js +1 -0
  2. package/dist/12.index.js +1 -0
  3. package/dist/160.index.js +1 -0
  4. package/dist/174.index.js +1 -0
  5. package/dist/278.index.js +6 -0
  6. package/dist/582.index.js +1 -0
  7. package/dist/641.index.js +324 -0
  8. package/dist/669.index.js +1 -0
  9. package/dist/722.index.js +1 -0
  10. package/dist/788.index.js +1 -0
  11. package/dist/816.index.js +12 -0
  12. package/dist/830.index.js +1 -0
  13. package/dist/921.index.js +1 -0
  14. package/dist/index.js +1 -813
  15. package/package.json +6 -2
  16. package/dist/cache.d.ts +0 -6
  17. package/dist/cache.js +0 -31
  18. package/dist/cache.test.d.ts +0 -1
  19. package/dist/cache.test.js +0 -73
  20. package/dist/client.d.ts +0 -56
  21. package/dist/client.js +0 -205
  22. package/dist/client.test.d.ts +0 -1
  23. package/dist/client.test.js +0 -89
  24. package/dist/commands/agent.d.ts +0 -20
  25. package/dist/commands/agent.js +0 -4119
  26. package/dist/commands/announcements.d.ts +0 -3
  27. package/dist/commands/announcements.js +0 -28
  28. package/dist/commands/augment.d.ts +0 -12
  29. package/dist/commands/augment.js +0 -56
  30. package/dist/commands/balance.d.ts +0 -3
  31. package/dist/commands/balance.js +0 -17
  32. package/dist/commands/book.d.ts +0 -17
  33. package/dist/commands/book.js +0 -220
  34. package/dist/commands/cancel.d.ts +0 -5
  35. package/dist/commands/cancel.js +0 -41
  36. package/dist/commands/context.d.ts +0 -6
  37. package/dist/commands/context.js +0 -208
  38. package/dist/commands/create.d.ts +0 -7
  39. package/dist/commands/create.js +0 -42
  40. package/dist/commands/dashboard.d.ts +0 -14
  41. package/dist/commands/dashboard.js +0 -215
  42. package/dist/commands/delta.d.ts +0 -16
  43. package/dist/commands/delta.js +0 -115
  44. package/dist/commands/edges.d.ts +0 -26
  45. package/dist/commands/edges.js +0 -237
  46. package/dist/commands/evaluate.d.ts +0 -4
  47. package/dist/commands/evaluate.js +0 -30
  48. package/dist/commands/explore.d.ts +0 -14
  49. package/dist/commands/explore.js +0 -115
  50. package/dist/commands/feed.d.ts +0 -13
  51. package/dist/commands/feed.js +0 -73
  52. package/dist/commands/fills.d.ts +0 -4
  53. package/dist/commands/fills.js +0 -29
  54. package/dist/commands/forecast.d.ts +0 -4
  55. package/dist/commands/forecast.js +0 -53
  56. package/dist/commands/get.d.ts +0 -5
  57. package/dist/commands/get.js +0 -98
  58. package/dist/commands/heartbeat.d.ts +0 -20
  59. package/dist/commands/heartbeat.js +0 -73
  60. package/dist/commands/history.d.ts +0 -3
  61. package/dist/commands/history.js +0 -38
  62. package/dist/commands/liquidity.d.ts +0 -14
  63. package/dist/commands/liquidity.js +0 -378
  64. package/dist/commands/list.d.ts +0 -5
  65. package/dist/commands/list.js +0 -38
  66. package/dist/commands/login.d.ts +0 -9
  67. package/dist/commands/login.js +0 -98
  68. package/dist/commands/markets.d.ts +0 -10
  69. package/dist/commands/markets.js +0 -39
  70. package/dist/commands/milestones.d.ts +0 -8
  71. package/dist/commands/milestones.js +0 -56
  72. package/dist/commands/orders.d.ts +0 -4
  73. package/dist/commands/orders.js +0 -28
  74. package/dist/commands/performance.d.ts +0 -11
  75. package/dist/commands/performance.js +0 -250
  76. package/dist/commands/positions.d.ts +0 -19
  77. package/dist/commands/positions.js +0 -294
  78. package/dist/commands/prompt.d.ts +0 -13
  79. package/dist/commands/prompt.js +0 -35
  80. package/dist/commands/publish.d.ts +0 -15
  81. package/dist/commands/publish.js +0 -39
  82. package/dist/commands/query.d.ts +0 -15
  83. package/dist/commands/query.js +0 -132
  84. package/dist/commands/rfq.d.ts +0 -5
  85. package/dist/commands/rfq.js +0 -35
  86. package/dist/commands/scan.d.ts +0 -11
  87. package/dist/commands/scan.js +0 -230
  88. package/dist/commands/schedule.d.ts +0 -3
  89. package/dist/commands/schedule.js +0 -38
  90. package/dist/commands/settlements.d.ts +0 -6
  91. package/dist/commands/settlements.js +0 -50
  92. package/dist/commands/setup.d.ts +0 -24
  93. package/dist/commands/setup.js +0 -700
  94. package/dist/commands/signal.d.ts +0 -6
  95. package/dist/commands/signal.js +0 -32
  96. package/dist/commands/strategies.d.ts +0 -11
  97. package/dist/commands/strategies.js +0 -130
  98. package/dist/commands/telegram.d.ts +0 -15
  99. package/dist/commands/telegram.js +0 -125
  100. package/dist/commands/trade.d.ts +0 -12
  101. package/dist/commands/trade.js +0 -112
  102. package/dist/commands/watch.d.ts +0 -19
  103. package/dist/commands/watch.js +0 -157
  104. package/dist/commands/whatif.d.ts +0 -17
  105. package/dist/commands/whatif.js +0 -209
  106. package/dist/commands/x.d.ts +0 -28
  107. package/dist/commands/x.js +0 -167
  108. package/dist/config.d.ts +0 -55
  109. package/dist/config.js +0 -139
  110. package/dist/config.test.d.ts +0 -1
  111. package/dist/config.test.js +0 -138
  112. package/dist/index.d.ts +0 -20
  113. package/dist/kalshi.d.ts +0 -144
  114. package/dist/kalshi.js +0 -498
  115. package/dist/polymarket.d.ts +0 -237
  116. package/dist/polymarket.js +0 -353
  117. package/dist/polymarket.test.d.ts +0 -1
  118. package/dist/polymarket.test.js +0 -424
  119. package/dist/share.d.ts +0 -4
  120. package/dist/share.js +0 -27
  121. package/dist/skills/loader.d.ts +0 -19
  122. package/dist/skills/loader.js +0 -86
  123. package/dist/telegram/agent-bridge.d.ts +0 -15
  124. package/dist/telegram/agent-bridge.js +0 -573
  125. package/dist/telegram/bot.d.ts +0 -10
  126. package/dist/telegram/bot.js +0 -297
  127. package/dist/telegram/commands.d.ts +0 -11
  128. package/dist/telegram/commands.js +0 -120
  129. package/dist/telegram/format.d.ts +0 -11
  130. package/dist/telegram/format.js +0 -51
  131. package/dist/telegram/format.test.d.ts +0 -1
  132. package/dist/telegram/format.test.js +0 -73
  133. package/dist/telegram/poller.d.ts +0 -6
  134. package/dist/telegram/poller.js +0 -32
  135. package/dist/topics.d.ts +0 -17
  136. package/dist/topics.js +0 -102
  137. package/dist/topics.test.d.ts +0 -1
  138. package/dist/topics.test.js +0 -131
  139. package/dist/tui/border.d.ts +0 -33
  140. package/dist/tui/border.js +0 -87
  141. package/dist/tui/chart.d.ts +0 -19
  142. package/dist/tui/chart.js +0 -117
  143. package/dist/tui/dashboard.d.ts +0 -9
  144. package/dist/tui/dashboard.js +0 -814
  145. package/dist/tui/layout.d.ts +0 -16
  146. package/dist/tui/layout.js +0 -41
  147. package/dist/tui/screen.d.ts +0 -33
  148. package/dist/tui/screen.js +0 -102
  149. package/dist/tui/state.d.ts +0 -40
  150. package/dist/tui/state.js +0 -36
  151. package/dist/tui/widgets/commandbar.d.ts +0 -8
  152. package/dist/tui/widgets/commandbar.js +0 -82
  153. package/dist/tui/widgets/detail.d.ts +0 -9
  154. package/dist/tui/widgets/detail.js +0 -151
  155. package/dist/tui/widgets/edges.d.ts +0 -4
  156. package/dist/tui/widgets/edges.js +0 -34
  157. package/dist/tui/widgets/liquidity.d.ts +0 -9
  158. package/dist/tui/widgets/liquidity.js +0 -142
  159. package/dist/tui/widgets/orders.d.ts +0 -4
  160. package/dist/tui/widgets/orders.js +0 -37
  161. package/dist/tui/widgets/portfolio.d.ts +0 -4
  162. package/dist/tui/widgets/portfolio.js +0 -59
  163. package/dist/tui/widgets/signals.d.ts +0 -4
  164. package/dist/tui/widgets/signals.js +0 -31
  165. package/dist/tui/widgets/statusbar.d.ts +0 -8
  166. package/dist/tui/widgets/statusbar.js +0 -72
  167. package/dist/tui/widgets/thesis.d.ts +0 -4
  168. package/dist/tui/widgets/thesis.js +0 -66
  169. package/dist/tui/widgets/trade.d.ts +0 -9
  170. package/dist/tui/widgets/trade.js +0 -117
  171. package/dist/tui/widgets/upcoming.d.ts +0 -4
  172. package/dist/tui/widgets/upcoming.js +0 -41
  173. package/dist/tui/widgets/whatif.d.ts +0 -7
  174. package/dist/tui/widgets/whatif.js +0 -113
  175. package/dist/types/output.d.ts +0 -412
  176. package/dist/types/output.js +0 -9
  177. package/dist/utils.d.ts +0 -42
  178. package/dist/utils.js +0 -124
  179. package/dist/utils.test.d.ts +0 -1
  180. package/dist/utils.test.js +0 -111
@@ -1,39 +0,0 @@
1
- "use strict";
2
- /**
3
- * sf publish / sf unpublish
4
- *
5
- * Publish a thesis for public viewing or remove it from public.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.publishCommand = publishCommand;
9
- exports.unpublishCommand = unpublishCommand;
10
- const client_js_1 = require("../client.js");
11
- /** Convert any string to a URL-safe slug: lowercase, hyphens, strip invalid chars */
12
- function slugify(input) {
13
- return input
14
- .toLowerCase()
15
- .trim()
16
- .replace(/[^a-z0-9\s-]/g, '') // remove non-alphanumeric except spaces/hyphens
17
- .replace(/[\s_]+/g, '-') // spaces/underscores → hyphens
18
- .replace(/-+/g, '-') // collapse multiple hyphens
19
- .replace(/^-|-$/g, '') // trim leading/trailing hyphens
20
- .slice(0, 60); // max 60 chars
21
- }
22
- async function publishCommand(thesisId, opts) {
23
- const slug = slugify(opts.slug);
24
- if (slug.length < 3) {
25
- console.error(`\n Error: slug too short after normalization: "${slug}" (need 3+ chars)\n`);
26
- process.exit(1);
27
- }
28
- if (slug !== opts.slug) {
29
- console.log(` Slug normalized: "${opts.slug}" → "${slug}"`);
30
- }
31
- const client = new client_js_1.SFClient(opts.apiKey, opts.apiUrl);
32
- await client.publish(thesisId, slug, opts.description);
33
- console.log(`\n ✓ Published: https://simplefunctions.dev/thesis/${slug}\n`);
34
- }
35
- async function unpublishCommand(thesisId, opts) {
36
- const client = new client_js_1.SFClient(opts.apiKey, opts.apiUrl);
37
- await client.unpublish(thesisId);
38
- console.log(`\n ✓ Unpublished thesis ${thesisId}\n`);
39
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * sf query "iran oil"
3
- *
4
- * LLM-enhanced prediction market knowledge search. No auth required.
5
- * Searches Kalshi, Polymarket, X, traditional markets, and SimpleFunctions content.
6
- *
7
- * Usage:
8
- * sf query "iran oil" — Formatted output
9
- * sf query "fed rate cut" --json — JSON for agents
10
- */
11
- export declare function queryCommand(q: string, opts?: {
12
- json?: boolean;
13
- share?: boolean;
14
- limit?: string;
15
- }): Promise<void>;
@@ -1,132 +0,0 @@
1
- "use strict";
2
- /**
3
- * sf query "iran oil"
4
- *
5
- * LLM-enhanced prediction market knowledge search. No auth required.
6
- * Searches Kalshi, Polymarket, X, traditional markets, and SimpleFunctions content.
7
- *
8
- * Usage:
9
- * sf query "iran oil" — Formatted output
10
- * sf query "fed rate cut" --json — JSON for agents
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.queryCommand = queryCommand;
14
- const share_js_1 = require("../share.js");
15
- const BASE_URL = process.env.SF_API_URL || 'https://simplefunctions.dev';
16
- async function queryCommand(q, opts) {
17
- const limit = opts?.limit || '10';
18
- const url = `${BASE_URL}/api/public/query?q=${encodeURIComponent(q)}&limit=${limit}`;
19
- const res = await fetch(url);
20
- if (!res.ok) {
21
- const text = await res.text();
22
- if (res.status === 429) {
23
- console.error(' Rate limited. Wait a minute and try again.');
24
- }
25
- else {
26
- console.error(` Error: ${res.status} ${text}`);
27
- }
28
- return;
29
- }
30
- const data = await res.json();
31
- if (opts?.share) {
32
- await (0, share_js_1.shareOutput)('query', q, data);
33
- return;
34
- }
35
- if (opts?.json) {
36
- console.log(JSON.stringify(data, null, 2));
37
- return;
38
- }
39
- // Formatted output
40
- console.log();
41
- console.log(` \x1b[1m${data.query}\x1b[22m`);
42
- console.log();
43
- // Answer
44
- if (data.answer) {
45
- console.log(` ${data.answer}`);
46
- console.log();
47
- }
48
- // Key factors
49
- if (data.keyFactors?.length > 0) {
50
- console.log(' \x1b[2mKey factors:\x1b[22m');
51
- for (const f of data.keyFactors) {
52
- console.log(` • ${f}`);
53
- }
54
- console.log();
55
- }
56
- // Markets — each venue separately
57
- const kalshiList = data.kalshi || [];
58
- const polyList = data.polymarket || [];
59
- if (kalshiList.length > 0 || polyList.length > 0) {
60
- console.log(' \x1b[1mMarkets\x1b[22m');
61
- for (const m of kalshiList.slice(0, 8)) {
62
- const vol = fmtVol(m.volume);
63
- const id = m.ticker ? ` \x1b[2m${m.ticker}\x1b[22m` : '';
64
- console.log(` \x1b[36mK\x1b[39m ${String(m.price).padStart(3)}¢ vol ${vol.padStart(6)} ${m.title.slice(0, 55)}${id}`);
65
- }
66
- if (kalshiList.length > 0 && polyList.length > 0)
67
- console.log();
68
- for (const m of polyList.slice(0, 8)) {
69
- const vol = fmtVol(m.volume);
70
- const id = m.slug ? ` \x1b[2m${m.slug}\x1b[22m` : '';
71
- console.log(` \x1b[35mP\x1b[39m ${String(m.price).padStart(3)}¢ vol ${vol.padStart(6)} ${m.title.slice(0, 55)}${id}`);
72
- }
73
- console.log();
74
- }
75
- // X posts
76
- const xList = data.x || [];
77
- if (xList.length > 0) {
78
- console.log(' \x1b[1mX signals\x1b[22m');
79
- for (const p of xList.slice(0, 5)) {
80
- const engagement = `${fmtNum(p.likes)}♥ ${fmtNum(p.retweets)}⟲`;
81
- console.log(` @${p.author} ${engagement} ${p.text.slice(0, 80)}`);
82
- }
83
- console.log();
84
- }
85
- // Traditional markets
86
- const tradList = data.traditional || [];
87
- if (tradList.length > 0) {
88
- console.log(' \x1b[1mTraditional\x1b[22m');
89
- for (const m of tradList) {
90
- const sign = m.change1d >= 0 ? '+' : '';
91
- console.log(` ${m.symbol.padEnd(5)} $${m.price} ${sign}${m.change1d} (${sign}${m.changePct}%) ${m.name}`);
92
- }
93
- console.log();
94
- }
95
- // Theses
96
- if (data.theses?.length > 0) {
97
- console.log(' \x1b[1mTheses\x1b[22m');
98
- for (const t of data.theses.slice(0, 3)) {
99
- console.log(` ${t.confidence || '?'}% ${String(t.edges || 0).padStart(2)} edges ${t.title.slice(0, 50)}`);
100
- }
101
- console.log();
102
- }
103
- // Content
104
- if (data.content?.length > 0) {
105
- console.log(' \x1b[1mContent\x1b[22m');
106
- for (const c of data.content.slice(0, 5)) {
107
- const type = c.type.padEnd(9);
108
- console.log(` \x1b[2m${type}\x1b[22m ${c.title.slice(0, 50)} \x1b[2m${c.url}\x1b[22m`);
109
- }
110
- console.log();
111
- }
112
- // Meta
113
- const meta = data.meta || {};
114
- const sources = meta.sources || data.sources || [];
115
- const latency = meta.latencyMs ? `${(meta.latencyMs / 1000).toFixed(1)}s` : '';
116
- console.log(` \x1b[2mSources: ${sources.join(', ')}${latency ? ` (${latency})` : ''}\x1b[22m`);
117
- console.log();
118
- }
119
- function fmtVol(v) {
120
- if (v > 1_000_000)
121
- return `${(v / 1_000_000).toFixed(1)}M`;
122
- if (v > 1_000)
123
- return `${(v / 1_000).toFixed(0)}K`;
124
- return String(Math.round(v));
125
- }
126
- function fmtNum(n) {
127
- if (n > 1_000_000)
128
- return `${(n / 1_000_000).toFixed(1)}M`;
129
- if (n > 1_000)
130
- return `${(n / 1_000).toFixed(1)}K`;
131
- return String(n);
132
- }
@@ -1,5 +0,0 @@
1
- export declare function rfqCommand(ticker: string, qty: string, opts: {
2
- targetCost?: string;
3
- restRemainder?: boolean;
4
- json?: boolean;
5
- }): Promise<void>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rfqCommand = rfqCommand;
4
- const kalshi_js_1 = require("../kalshi.js");
5
- const config_js_1 = require("../config.js");
6
- const utils_js_1 = require("../utils.js");
7
- async function rfqCommand(ticker, qty, opts) {
8
- (0, config_js_1.requireTrading)();
9
- const quantity = parseInt(qty);
10
- if (isNaN(quantity) || quantity <= 0)
11
- throw new Error('Quantity must be a positive integer');
12
- console.log();
13
- console.log(` ${utils_js_1.c.bold}${utils_js_1.c.cyan}Request for Quote${utils_js_1.c.reset}`);
14
- console.log(` ${utils_js_1.c.dim}${'─'.repeat(30)}${utils_js_1.c.reset}`);
15
- console.log(` Market: ${ticker}`);
16
- console.log(` Contracts: ${quantity}`);
17
- if (opts.targetCost)
18
- console.log(` Target cost: ${opts.targetCost}¢/contract`);
19
- console.log(` Rest remainder: ${opts.restRemainder ? 'yes' : 'no'}`);
20
- console.log();
21
- try {
22
- const result = await (0, kalshi_js_1.createRFQ)({
23
- market_ticker: ticker,
24
- contracts: quantity,
25
- rest_remainder: opts.restRemainder || false,
26
- ...(opts.targetCost ? { target_cost_centi_cents: parseInt(opts.targetCost) * 100 } : {}),
27
- });
28
- console.log(` ${utils_js_1.c.green}✓${utils_js_1.c.reset} RFQ created: ${result.id || result.rfq_id || 'OK'}`);
29
- console.log();
30
- }
31
- catch (err) {
32
- console.error(`\n ${utils_js_1.c.red}✗${utils_js_1.c.reset} ${err.message}\n`);
33
- process.exit(1);
34
- }
35
- }
@@ -1,11 +0,0 @@
1
- interface ScanOpts {
2
- series?: string;
3
- market?: string;
4
- venue?: string;
5
- json?: boolean;
6
- share?: boolean;
7
- apiKey?: string;
8
- apiUrl?: string;
9
- }
10
- export declare function scanCommand(query: string, opts: ScanOpts): Promise<void>;
11
- export {};
@@ -1,230 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.scanCommand = scanCommand;
4
- const client_js_1 = require("../client.js");
5
- const polymarket_js_1 = require("../polymarket.js");
6
- const utils_js_1 = require("../utils.js");
7
- const share_js_1 = require("../share.js");
8
- // SF API base — scan goes through the server which holds the proxy key
9
- const SF_API_URL = process.env.SF_API_URL || 'https://simplefunctions.dev';
10
- async function scanCommand(query, opts) {
11
- // Mode 1: --market TICKER — single market detail
12
- if (opts.market) {
13
- await showMarket(opts.market.toUpperCase(), opts.json);
14
- return;
15
- }
16
- // Mode 2: --series TICKER — list events + markets for a series
17
- if (opts.series) {
18
- await showSeries(opts.series.toUpperCase(), opts.json);
19
- return;
20
- }
21
- // Mode 3: keyword scan across all series + Polymarket
22
- await keywordScan(query, opts.json, opts.venue || 'all', opts.share);
23
- }
24
- async function showMarket(ticker, json) {
25
- console.log(`${utils_js_1.c.dim}Fetching market ${ticker}...${utils_js_1.c.reset}`);
26
- const m = await (0, client_js_1.kalshiFetchMarket)(ticker);
27
- if (json) {
28
- console.log(JSON.stringify(m, null, 2));
29
- return;
30
- }
31
- (0, utils_js_1.header)(`${m.title || m.ticker}`);
32
- if (m.subtitle)
33
- console.log(`${utils_js_1.c.dim}${m.subtitle}${utils_js_1.c.reset}`);
34
- console.log(`Event: ${m.event_ticker} Status: ${m.status}`);
35
- console.log('');
36
- console.log(`Yes Ask: ${(0, utils_js_1.cents)(m.yes_ask_dollars)} (size: ${m.yes_ask_size_fp || '-'})`);
37
- console.log(`Yes Bid: ${(0, utils_js_1.cents)(m.yes_bid_dollars)} (size: ${m.yes_bid_size_fp || '-'})`);
38
- console.log(`No Ask: ${(0, utils_js_1.cents)(m.no_ask_dollars)}`);
39
- console.log(`No Bid: ${(0, utils_js_1.cents)(m.no_bid_dollars)}`);
40
- console.log(`Last: ${(0, utils_js_1.cents)(m.last_price_dollars)}`);
41
- console.log('');
42
- console.log(`Volume: ${(0, utils_js_1.vol)(m.volume_fp)}`);
43
- console.log(`Vol 24h: ${(0, utils_js_1.vol)(m.volume_24h_fp)}`);
44
- console.log(`Open Int: ${(0, utils_js_1.vol)(m.open_interest_fp)}`);
45
- console.log(`Liquidity: ${(0, utils_js_1.vol)(m.liquidity_dollars)}`);
46
- console.log('');
47
- console.log(`Open: ${m.open_time}`);
48
- console.log(`Close: ${m.close_time}`);
49
- if (m.rules_primary) {
50
- console.log(`\nRules: ${m.rules_primary.slice(0, 300)}`);
51
- }
52
- }
53
- async function showSeries(seriesTicker, json) {
54
- console.log(`${utils_js_1.c.dim}Fetching events for series ${seriesTicker}...${utils_js_1.c.reset}`);
55
- let events = await (0, client_js_1.kalshiFetchEvents)(seriesTicker);
56
- if (events.length === 0) {
57
- // Fallback: direct market lookup by series
58
- const markets = await (0, client_js_1.kalshiFetchMarketsBySeries)(seriesTicker);
59
- if (json) {
60
- console.log(JSON.stringify(markets, null, 2));
61
- return;
62
- }
63
- if (markets.length === 0) {
64
- console.log(`${utils_js_1.c.dim}No open markets found for series ${seriesTicker}.${utils_js_1.c.reset}`);
65
- return;
66
- }
67
- (0, utils_js_1.header)(`${seriesTicker} — ${markets.length} markets`);
68
- printMarketsTable(markets);
69
- return;
70
- }
71
- if (json) {
72
- console.log(JSON.stringify(events, null, 2));
73
- return;
74
- }
75
- for (const event of events) {
76
- (0, utils_js_1.header)(`${event.title || event.event_ticker}`);
77
- console.log(`${utils_js_1.c.dim}${event.event_ticker} | ${event.category || '-'} | strike: ${event.strike_date || '-'}${utils_js_1.c.reset}`);
78
- const markets = event.markets && event.markets.length > 0
79
- ? event.markets
80
- : await (0, client_js_1.kalshiFetchMarketsByEvent)(event.event_ticker);
81
- printMarketsTable(markets);
82
- }
83
- }
84
- async function keywordScan(query, json, venue = 'all', share) {
85
- // ── Polymarket search (runs in parallel with Kalshi) ───────────────────────
86
- const polyPromise = (venue === 'kalshi')
87
- ? Promise.resolve([])
88
- : (0, polymarket_js_1.polymarketSearch)(query, 10).catch(() => []);
89
- if (venue !== 'polymarket') {
90
- console.log(`${utils_js_1.c.dim}Scanning Kalshi for: "${query}"...${utils_js_1.c.reset}`);
91
- }
92
- if (venue !== 'kalshi') {
93
- console.log(`${utils_js_1.c.dim}Scanning Polymarket for: "${query}"...${utils_js_1.c.reset}`);
94
- }
95
- // ── Kalshi via SF API /scan (proxies to CF worker, key stays server-side)
96
- const allMarkets = [];
97
- if (venue !== 'polymarket') {
98
- try {
99
- const scanUrl = `${SF_API_URL}/api/public/scan?q=${encodeURIComponent(query)}&limit=30`;
100
- const res = await fetch(scanUrl);
101
- if (!res.ok)
102
- throw new Error(`Proxy ${res.status}`);
103
- const data = await res.json();
104
- const matchedSeries = data.matchedSeries || [];
105
- const markets = data.markets || [];
106
- console.log(`\n${utils_js_1.c.bold}Matched ${matchedSeries.length} series via proxy:${utils_js_1.c.reset}\n`);
107
- for (const s of matchedSeries.slice(0, 15)) {
108
- console.log(` ${(0, utils_js_1.pad)(s.ticker, 25)} score=${s.score} ${s.title || ''}`);
109
- }
110
- for (const m of markets) {
111
- allMarkets.push({
112
- venue: 'kalshi',
113
- seriesTicker: m.series_ticker,
114
- ticker: m.ticker,
115
- title: m.title || m.exchange_title || '',
116
- yesAsk: parseFloat(m.yes_ask_dollars || '0'),
117
- lastPrice: parseFloat(m.last_price_dollars || '0'),
118
- volume24h: parseFloat(m.volume_24h_fp || '0'),
119
- liquidity: parseFloat(m.open_interest_fp || m.liquidity_dollars || '0'),
120
- });
121
- }
122
- }
123
- catch (err) {
124
- console.warn(`${utils_js_1.c.dim}Kalshi scan failed: ${err}${utils_js_1.c.reset}`);
125
- }
126
- }
127
- allMarkets.sort((a, b) => b.liquidity - a.liquidity);
128
- // ── Polymarket results ──────────────────────────────────────────────────────
129
- const polyEvents = await polyPromise;
130
- const polyMarkets = [];
131
- for (const event of polyEvents) {
132
- for (const m of (event.markets || [])) {
133
- if (!m.active || m.closed)
134
- continue;
135
- const prices = (0, polymarket_js_1.parseOutcomePrices)(m.outcomePrices);
136
- const yesPrice = prices[0] || 0;
137
- polyMarkets.push({
138
- venue: 'polymarket',
139
- ticker: m.conditionId?.slice(0, 16) || m.id,
140
- title: m.groupItemTitle
141
- ? `${event.title}: ${m.groupItemTitle}`
142
- : m.question || event.title,
143
- yesAsk: yesPrice,
144
- lastPrice: m.lastTradePrice || yesPrice,
145
- volume24h: m.volume24hr || 0,
146
- liquidity: m.liquidityNum || 0,
147
- });
148
- }
149
- }
150
- // ── Merge & output ─────────────────────────────────────────────────────────
151
- // Tag Kalshi markets with venue
152
- for (const m of allMarkets) {
153
- if (!m.venue)
154
- m.venue = 'kalshi';
155
- }
156
- const combined = [...allMarkets, ...polyMarkets];
157
- combined.sort((a, b) => b.liquidity - a.liquidity);
158
- if (share) {
159
- await (0, share_js_1.shareOutput)('scan', query, combined);
160
- return;
161
- }
162
- if (json) {
163
- console.log(JSON.stringify(combined, null, 2));
164
- return;
165
- }
166
- (0, utils_js_1.header)(`${combined.length} Live Markets (${allMarkets.length} Kalshi + ${polyMarkets.length} Polymarket)`);
167
- console.log(utils_js_1.c.bold +
168
- (0, utils_js_1.pad)('', 5) +
169
- (0, utils_js_1.pad)('Ticker', 30) +
170
- (0, utils_js_1.rpad)('Yes', 6) +
171
- (0, utils_js_1.rpad)('Last', 6) +
172
- (0, utils_js_1.rpad)('Vol24h', 10) +
173
- (0, utils_js_1.rpad)('Liq', 10) +
174
- ' Title' +
175
- utils_js_1.c.reset);
176
- (0, utils_js_1.hr)(120);
177
- for (const m of combined.slice(0, 60)) {
178
- // Venue tag: fixed 5-char column, color applied AFTER padding
179
- const venuePad = m.venue === 'polymarket' ? 'POLY ' : 'KLSH ';
180
- const venueColored = m.venue === 'polymarket'
181
- ? utils_js_1.c.blue + venuePad + utils_js_1.c.reset
182
- : utils_js_1.c.cyan + venuePad + utils_js_1.c.reset;
183
- const tickerStr = m.venue === 'polymarket'
184
- ? (m.ticker || '').slice(0, 28)
185
- : (m.ticker || '').slice(0, 28);
186
- console.log(venueColored +
187
- (0, utils_js_1.pad)(tickerStr, 30) +
188
- (0, utils_js_1.rpad)(`${Math.round(m.yesAsk * 100)}¢`, 6) +
189
- (0, utils_js_1.rpad)(`${Math.round(m.lastPrice * 100)}¢`, 6) +
190
- (0, utils_js_1.rpad)((0, utils_js_1.vol)(Math.round(m.volume24h)), 10) +
191
- (0, utils_js_1.rpad)((0, utils_js_1.vol)(Math.round(m.liquidity)), 10) +
192
- ` ${(m.title || '').slice(0, 55)}`);
193
- }
194
- console.log('');
195
- // Conversion hook
196
- if (!json) {
197
- console.log(`${utils_js_1.c.dim}Want 24/7 monitoring + edge detection? ${utils_js_1.c.reset}${utils_js_1.c.cyan}sf create${utils_js_1.c.reset}${utils_js_1.c.dim} "your thesis"${utils_js_1.c.reset}`);
198
- console.log('');
199
- }
200
- }
201
- function printMarketsTable(markets) {
202
- if (markets.length === 0) {
203
- console.log(` ${utils_js_1.c.dim}(no markets)${utils_js_1.c.reset}`);
204
- return;
205
- }
206
- markets.sort((a, b) => {
207
- const pa = parseFloat(a.yes_ask_dollars || a.last_price_dollars || '0');
208
- const pb = parseFloat(b.yes_ask_dollars || b.last_price_dollars || '0');
209
- return pb - pa;
210
- });
211
- console.log(' ' + utils_js_1.c.bold +
212
- (0, utils_js_1.pad)('Ticker', 35) +
213
- (0, utils_js_1.rpad)('YesAsk', 8) +
214
- (0, utils_js_1.rpad)('Last', 8) +
215
- (0, utils_js_1.rpad)('Vol24h', 10) +
216
- (0, utils_js_1.rpad)('Liq', 12) +
217
- ' Title' +
218
- utils_js_1.c.reset);
219
- console.log(' ' + utils_js_1.c.dim + '─'.repeat(100) + utils_js_1.c.reset);
220
- for (const m of markets) {
221
- console.log(' ' +
222
- (0, utils_js_1.pad)(m.ticker || '', 35) +
223
- (0, utils_js_1.rpad)((0, utils_js_1.cents)(m.yes_ask_dollars), 8) +
224
- (0, utils_js_1.rpad)((0, utils_js_1.cents)(m.last_price_dollars), 8) +
225
- (0, utils_js_1.rpad)((0, utils_js_1.vol)(m.volume_24h_fp), 10) +
226
- (0, utils_js_1.rpad)((0, utils_js_1.vol)(m.liquidity_dollars), 12) +
227
- ` ${(m.title || m.subtitle || '').slice(0, 55)}`);
228
- }
229
- console.log('');
230
- }
@@ -1,3 +0,0 @@
1
- export declare function scheduleCommand(opts: {
2
- json?: boolean;
3
- }): Promise<void>;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.scheduleCommand = scheduleCommand;
4
- const utils_js_1 = require("../utils.js");
5
- const KALSHI_API_BASE = 'https://api.elections.kalshi.com/trade-api/v2';
6
- async function scheduleCommand(opts) {
7
- const statusRes = await fetch(`${KALSHI_API_BASE}/exchange/status`, {
8
- headers: { 'Accept': 'application/json' },
9
- });
10
- if (!statusRes.ok)
11
- throw new Error(`Exchange API ${statusRes.status}`);
12
- const status = await statusRes.json();
13
- let schedule = null;
14
- try {
15
- const schedRes = await fetch(`${KALSHI_API_BASE}/exchange/schedule`, {
16
- headers: { 'Accept': 'application/json' },
17
- });
18
- if (schedRes.ok)
19
- schedule = await schedRes.json();
20
- }
21
- catch { /* schedule endpoint may not exist */ }
22
- if (opts.json) {
23
- console.log(JSON.stringify({ status, schedule }, null, 2));
24
- return;
25
- }
26
- const trading = status.exchange_active ? `${utils_js_1.c.green}OPEN${utils_js_1.c.reset}` : `${utils_js_1.c.red}CLOSED${utils_js_1.c.reset}`;
27
- console.log();
28
- console.log(` ${utils_js_1.c.bold}${utils_js_1.c.cyan}Exchange Status${utils_js_1.c.reset}`);
29
- console.log(` ${utils_js_1.c.dim}${'─'.repeat(30)}${utils_js_1.c.reset}`);
30
- console.log(` Trading: ${trading}`);
31
- if (status.trading_active !== undefined) {
32
- console.log(` Trading Active: ${status.trading_active ? 'yes' : 'no'}`);
33
- }
34
- if (schedule?.schedule) {
35
- console.log(` Schedule: ${JSON.stringify(schedule.schedule).slice(0, 100)}`);
36
- }
37
- console.log();
38
- }
@@ -1,6 +0,0 @@
1
- export declare function settlementsCommand(opts: {
2
- thesis?: string;
3
- json?: boolean;
4
- apiKey?: string;
5
- apiUrl?: string;
6
- }): Promise<void>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settlementsCommand = settlementsCommand;
4
- const kalshi_js_1 = require("../kalshi.js");
5
- const client_js_1 = require("../client.js");
6
- const utils_js_1 = require("../utils.js");
7
- async function settlementsCommand(opts) {
8
- // Paginate through all settlements
9
- const all = [];
10
- let cursor = '';
11
- do {
12
- const result = await (0, kalshi_js_1.getSettlements)({ limit: 200, cursor: cursor || undefined });
13
- if (!result)
14
- throw new Error('Kalshi not configured. Set KALSHI_API_KEY_ID + KALSHI_PRIVATE_KEY_PATH.');
15
- all.push(...result.settlements);
16
- cursor = result.cursor;
17
- } while (cursor);
18
- let filtered = all;
19
- if (opts.thesis) {
20
- const client = new client_js_1.SFClient(opts.apiKey, opts.apiUrl);
21
- const ctx = await client.getContext(opts.thesis);
22
- const edgeTickers = new Set((ctx.edges || []).map((e) => e.marketId));
23
- filtered = all.filter((s) => edgeTickers.has(s.ticker));
24
- }
25
- if (opts.json) {
26
- console.log(JSON.stringify(filtered, null, 2));
27
- return;
28
- }
29
- if (filtered.length === 0) {
30
- console.log(`${utils_js_1.c.dim}No settlements found.${utils_js_1.c.reset}`);
31
- return;
32
- }
33
- console.log(`${utils_js_1.c.bold}${utils_js_1.c.cyan}Settlements${utils_js_1.c.reset}`);
34
- console.log(`${utils_js_1.c.dim}${'─'.repeat(80)}${utils_js_1.c.reset}`);
35
- console.log(`${utils_js_1.c.bold}${'Ticker'.padEnd(35)} ${'Result'.padEnd(8)} ${'Revenue'.padEnd(10)} ${'Cost'.padEnd(10)} P&L${utils_js_1.c.reset}`);
36
- let totalPnl = 0;
37
- for (const s of filtered.slice(0, 50)) {
38
- const revenue = parseFloat(s.revenue || s.revenue_dollars || '0');
39
- const cost = parseFloat(s.yes_total_cost || s.yes_total_cost_dollars || '0') +
40
- parseFloat(s.no_total_cost || s.no_total_cost_dollars || '0');
41
- const pnl = revenue - cost;
42
- totalPnl += pnl;
43
- const pnlStr = pnl >= 0 ? `${utils_js_1.c.green}+$${pnl.toFixed(2)}${utils_js_1.c.reset}` : `${utils_js_1.c.red}-$${Math.abs(pnl).toFixed(2)}${utils_js_1.c.reset}`;
44
- const result = s.market_result || '-';
45
- console.log(` ${(s.ticker || '').slice(0, 33).padEnd(35)} ${result.padEnd(8)} $${revenue.toFixed(2).padEnd(9)} $${cost.toFixed(2).padEnd(9)} ${pnlStr}`);
46
- }
47
- console.log(`${utils_js_1.c.dim}${'─'.repeat(80)}${utils_js_1.c.reset}`);
48
- const totalStr = totalPnl >= 0 ? `${utils_js_1.c.green}+$${totalPnl.toFixed(2)}${utils_js_1.c.reset}` : `${utils_js_1.c.red}-$${Math.abs(totalPnl).toFixed(2)}${utils_js_1.c.reset}`;
49
- console.log(` Total: ${totalStr} (${filtered.length} settlements)`);
50
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * sf setup — Interactive configuration wizard
3
- *
4
- * Walks user through:
5
- * 1. SF API key (required)
6
- * 2. OpenRouter API key (optional, for agent)
7
- * 3. Kalshi exchange credentials (optional, for positions)
8
- * 4. Tavily API key (optional, for web search)
9
- * 5. First thesis creation (if none exist)
10
- *
11
- * Each key is validated in real-time.
12
- * Config is saved to ~/.sf/config.json.
13
- */
14
- interface SetupOpts {
15
- check?: boolean;
16
- reset?: boolean;
17
- key?: string;
18
- enableTrading?: boolean;
19
- disableTrading?: boolean;
20
- kalshi?: boolean;
21
- polymarket?: boolean;
22
- }
23
- export declare function setupCommand(opts: SetupOpts): Promise<void>;
24
- export {};