@spfunctions/cli 1.7.1 → 1.7.4

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/dist/client.d.ts CHANGED
@@ -35,3 +35,4 @@ export declare function kalshiFetchMarketsBySeries(seriesTicker: string): Promis
35
35
  export declare function kalshiFetchMarketsByEvent(eventTicker: string): Promise<any[]>;
36
36
  export declare function fetchGlobalContext(): Promise<any>;
37
37
  export declare function fetchQuery(q: string): Promise<any>;
38
+ export declare function fetchTraditionalMarkets(): Promise<any>;
package/dist/client.js CHANGED
@@ -14,6 +14,7 @@ exports.kalshiFetchMarketsBySeries = kalshiFetchMarketsBySeries;
14
14
  exports.kalshiFetchMarketsByEvent = kalshiFetchMarketsByEvent;
15
15
  exports.fetchGlobalContext = fetchGlobalContext;
16
16
  exports.fetchQuery = fetchQuery;
17
+ exports.fetchTraditionalMarkets = fetchTraditionalMarkets;
17
18
  const DEFAULT_API_URL = 'https://simplefunctions.dev';
18
19
  const KALSHI_BASE = 'https://api.elections.kalshi.com/trade-api/v2';
19
20
  // ===== SF API Client =====
@@ -170,3 +171,7 @@ async function fetchQuery(q) {
170
171
  throw new Error(`Query API error: ${res.status}`);
171
172
  return res.json();
172
173
  }
174
+ async function fetchTraditionalMarkets() {
175
+ const ctx = await fetchGlobalContext();
176
+ return ctx.traditionalMarkets || [];
177
+ }
@@ -18,9 +18,18 @@ async function contextCommand(id, opts) {
18
18
  return;
19
19
  }
20
20
  console.log(`\n${utils_js_1.c.bold}Market Snapshot${utils_js_1.c.reset} ${(0, utils_js_1.shortDate)(data.snapshotAt)}\n`);
21
+ if (data.edges?.length > 0) {
22
+ console.log(`${utils_js_1.c.bold}Thesis Edges${utils_js_1.c.reset}`);
23
+ for (const m of data.edges.slice(0, 10)) {
24
+ const venue = m.venue === 'kalshi' ? `${utils_js_1.c.cyan}K${utils_js_1.c.reset}` : `${utils_js_1.c.magenta}P${utils_js_1.c.reset}`;
25
+ const edgeStr = m.edge > 0 ? `${utils_js_1.c.green}+${m.edge}¢${utils_js_1.c.reset}` : `${utils_js_1.c.red}${m.edge}¢${utils_js_1.c.reset}`;
26
+ console.log(` ${venue} ${String(m.price).padStart(3)}¢ edge ${edgeStr.padStart(14)} ${m.title.slice(0, 50)}`);
27
+ }
28
+ console.log();
29
+ }
21
30
  if (data.movers?.length > 0) {
22
31
  console.log(`${utils_js_1.c.bold}Movers (24h)${utils_js_1.c.reset}`);
23
- for (const m of data.movers.slice(0, 10)) {
32
+ for (const m of data.movers.slice(0, 8)) {
24
33
  const venue = m.venue === 'kalshi' ? `${utils_js_1.c.cyan}K${utils_js_1.c.reset}` : `${utils_js_1.c.magenta}P${utils_js_1.c.reset}`;
25
34
  const ch = m.change24h > 0 ? `${utils_js_1.c.green}+${m.change24h}¢${utils_js_1.c.reset}` : `${utils_js_1.c.red}${m.change24h}¢${utils_js_1.c.reset}`;
26
35
  console.log(` ${venue} ${String(m.price).padStart(3)}¢ ${ch.padStart(16)} ${m.title.slice(0, 55)}`);
@@ -34,14 +43,6 @@ async function contextCommand(id, opts) {
34
43
  }
35
44
  console.log();
36
45
  }
37
- if (data.expiring?.length > 0) {
38
- console.log(`${utils_js_1.c.bold}Expiring (7d)${utils_js_1.c.reset}`);
39
- for (const m of data.expiring.slice(0, 8)) {
40
- const venue = m.venue === 'kalshi' ? `${utils_js_1.c.cyan}K${utils_js_1.c.reset}` : `${utils_js_1.c.magenta}P${utils_js_1.c.reset}`;
41
- console.log(` ${venue} ${String(m.price).padStart(3)}¢ ${utils_js_1.c.dim}${String(m.hoursUntil).padStart(3)}h${utils_js_1.c.reset} ${m.title.slice(0, 55)}`);
42
- }
43
- console.log();
44
- }
45
46
  if (data.liquid?.length > 0) {
46
47
  console.log(`${utils_js_1.c.bold}Liquid${utils_js_1.c.reset}`);
47
48
  for (const m of data.liquid.slice(0, 8)) {
@@ -0,0 +1,9 @@
1
+ /**
2
+ * sf markets
3
+ *
4
+ * Traditional market snapshot via Databento (SPY, VIX, TLT, Gold, Oil).
5
+ * No auth required — calls public endpoint.
6
+ */
7
+ export declare function marketsCommand(opts?: {
8
+ json?: boolean;
9
+ }): Promise<void>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /**
3
+ * sf markets
4
+ *
5
+ * Traditional market snapshot via Databento (SPY, VIX, TLT, Gold, Oil).
6
+ * No auth required — calls public endpoint.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.marketsCommand = marketsCommand;
10
+ const BASE_URL = 'https://simplefunctions.dev';
11
+ async function marketsCommand(opts) {
12
+ const res = await fetch(`${BASE_URL}/api/public/markets`);
13
+ if (!res.ok) {
14
+ console.error(` Error: ${res.status} ${await res.text()}`);
15
+ return;
16
+ }
17
+ const data = await res.json();
18
+ if (opts?.json) {
19
+ console.log(JSON.stringify(data, null, 2));
20
+ return;
21
+ }
22
+ console.log(`\n \x1b[1mTraditional Markets\x1b[22m \x1b[2m${data.snapshotAt?.slice(0, 10) || ''}\x1b[22m\n`);
23
+ if (!data.markets?.length) {
24
+ console.log(' No data available.\n');
25
+ return;
26
+ }
27
+ for (const m of data.markets) {
28
+ const arrow = m.changePct >= 0 ? '\x1b[32m▲\x1b[39m' : '\x1b[31m▼\x1b[39m';
29
+ const chg = m.changePct >= 0 ? `\x1b[32m+${m.changePct}%\x1b[39m` : `\x1b[31m${m.changePct}%\x1b[39m`;
30
+ const price = `$${m.price.toFixed(2)}`;
31
+ console.log(` ${arrow} ${m.symbol.padEnd(5)} ${price.padStart(10)} ${chg.padStart(16)} ${m.name}`);
32
+ }
33
+ console.log();
34
+ }
@@ -62,11 +62,18 @@ async function queryCommand(q, opts) {
62
62
  }
63
63
  console.log();
64
64
  }
65
- // Thesis
66
- if (data.thesis) {
65
+ // Theses
66
+ if (data.theses?.length > 0) {
67
+ console.log(` \x1b[1mTheses\x1b[22m`);
68
+ for (const t of data.theses.slice(0, 3)) {
69
+ console.log(` ${t.confidence || '?'}% ${String(t.edges || 0).padStart(2)} edges ${t.title.slice(0, 50)}`);
70
+ }
71
+ console.log();
72
+ }
73
+ else if (data.thesis) {
74
+ // Backward compat
67
75
  const t = data.thesis;
68
76
  console.log(` \x1b[1mThesis\x1b[22m`);
69
- console.log(` ${t.title.slice(0, 60)}`);
70
77
  console.log(` ${t.confidence}% confidence ${t.edges} edges /thesis/${t.slug}`);
71
78
  console.log();
72
79
  }
@@ -5,6 +5,9 @@ exports.sellCommand = sellCommand;
5
5
  const kalshi_js_1 = require("../kalshi.js");
6
6
  const config_js_1 = require("../config.js");
7
7
  const utils_js_1 = require("../utils.js");
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const os_1 = require("os");
8
11
  async function buyCommand(ticker, qty, opts) {
9
12
  (0, config_js_1.requireTrading)();
10
13
  await executeOrder(ticker, qty, 'buy', opts);
@@ -62,6 +65,27 @@ async function executeOrder(ticker, qty, action, opts) {
62
65
  if (order.fill_count_fp)
63
66
  console.log(` Filled: ${order.fill_count_fp}/${order.initial_count_fp || quantity}`);
64
67
  console.log();
68
+ // Auto-log trade to journal
69
+ try {
70
+ const journalDir = (0, path_1.join)((0, os_1.homedir)(), '.sf');
71
+ if (!(0, fs_1.existsSync)(journalDir))
72
+ (0, fs_1.mkdirSync)(journalDir, { recursive: true });
73
+ const entry = JSON.stringify({
74
+ ts: new Date().toISOString(),
75
+ action,
76
+ ticker,
77
+ side,
78
+ quantity,
79
+ price: priceCents || null,
80
+ type: orderType,
81
+ orderId: order.order_id || null,
82
+ status: order.status || null,
83
+ filled: order.fill_count_fp || null,
84
+ }) + '\n';
85
+ (0, fs_1.appendFileSync)((0, path_1.join)(journalDir, 'trade-journal.jsonl'), entry);
86
+ console.log(` ${utils_js_1.c.dim}Trade logged to ~/.sf/trade-journal.jsonl${utils_js_1.c.reset}`);
87
+ }
88
+ catch { /* journal logging is best-effort */ }
65
89
  }
66
90
  catch (err) {
67
91
  const msg = err.message || String(err);
package/dist/index.js CHANGED
@@ -58,6 +58,7 @@ const prompt_js_1 = require("./commands/prompt.js");
58
58
  const augment_js_1 = require("./commands/augment.js");
59
59
  const telegram_js_1 = require("./commands/telegram.js");
60
60
  const query_js_1 = require("./commands/query.js");
61
+ const markets_js_1 = require("./commands/markets.js");
61
62
  const utils_js_1 = require("./utils.js");
62
63
  // ── Apply ~/.sf/config.json to process.env BEFORE any command ────────────────
63
64
  // This means client.ts, kalshi.ts, agent.ts keep reading process.env and just work.
@@ -86,6 +87,7 @@ const GROUPED_HELP = `
86
87
 
87
88
  \x1b[1mSearch\x1b[22m
88
89
  \x1b[36mquery\x1b[39m "question" LLM-enhanced market knowledge search \x1b[2m(no auth)\x1b[22m
90
+ \x1b[36mmarkets\x1b[39m Traditional markets: SPY, VIX, bonds, gold, oil \x1b[2m(no auth)\x1b[22m
89
91
 
90
92
  \x1b[1mMarkets\x1b[22m
91
93
  \x1b[36mscan\x1b[39m "keywords" Search Kalshi + Polymarket
@@ -221,7 +223,7 @@ async function interactiveEntry() {
221
223
  console.log();
222
224
  }
223
225
  // ── Pre-action guard: check configuration ────────────────────────────────────
224
- const NO_CONFIG_COMMANDS = new Set(['setup', 'help', 'scan', 'explore', 'query', 'context', 'milestones', 'forecast', 'settlements', 'balance', 'orders', 'fills', 'schedule', 'announcements', 'history', 'liquidity', 'book', 'prompt', 'sf']);
226
+ const NO_CONFIG_COMMANDS = new Set(['setup', 'help', 'scan', 'explore', 'query', 'context', 'markets', 'milestones', 'forecast', 'settlements', 'balance', 'orders', 'fills', 'schedule', 'announcements', 'history', 'liquidity', 'book', 'prompt', 'sf']);
225
227
  program.hook('preAction', (thisCommand, actionCommand) => {
226
228
  const cmdName = actionCommand.name();
227
229
  if (NO_CONFIG_COMMANDS.has(cmdName))
@@ -625,6 +627,14 @@ program
625
627
  const g = cmd.optsWithGlobals();
626
628
  await run(() => (0, augment_js_1.augmentCommand)(thesisId, { dryRun: opts.dryRun, json: opts.json, apiKey: g.apiKey, apiUrl: g.apiUrl }));
627
629
  });
630
+ // ── sf markets ───────────────────────────────────────────────────────────────
631
+ program
632
+ .command('markets')
633
+ .description('Traditional market snapshot — SPY, VIX, Treasury, Gold, Oil (no auth)')
634
+ .option('--json', 'JSON output')
635
+ .action(async (opts) => {
636
+ await run(() => (0, markets_js_1.marketsCommand)({ json: opts.json }));
637
+ });
628
638
  // ── sf query "question" ──────────────────────────────────────────────────────
629
639
  program
630
640
  .command('query <question>')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfunctions/cli",
3
- "version": "1.7.1",
3
+ "version": "1.7.4",
4
4
  "description": "Prediction market intelligence CLI. Causal thesis model, 24/7 Kalshi/Polymarket scan, live orderbook, edge detection. Interactive agent mode with tool calling.",
5
5
  "bin": {
6
6
  "sf": "./dist/index.js"