@spfunctions/cli 1.1.9 → 1.2.1

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.
@@ -1100,8 +1100,8 @@ async function agentCommand(thesisId, opts) {
1100
1100
  }),
1101
1101
  execute: async (_toolCallId, params) => {
1102
1102
  const { createOrder } = await import('../kalshi.js');
1103
- const priceDollars = params.price_cents ? (params.price_cents / 100).toFixed(2) : undefined;
1104
- const maxCost = ((params.price_cents || 99) * params.count / 100).toFixed(2);
1103
+ const priceCents = params.price_cents ? Math.round(Number(params.price_cents)) : undefined;
1104
+ const maxCost = ((priceCents || 99) * params.count / 100).toFixed(2);
1105
1105
  // Show preview
1106
1106
  const preview = [
1107
1107
  C.zinc200(bold('ORDER PREVIEW')),
@@ -1110,7 +1110,7 @@ async function agentCommand(thesisId, opts) {
1110
1110
  ` Action: ${params.action.toUpperCase()}`,
1111
1111
  ` Quantity: ${params.count}`,
1112
1112
  ` Type: ${params.type}`,
1113
- params.price_cents ? ` Price: ${params.price_cents}\u00A2` : '',
1113
+ priceCents ? ` Price: ${priceCents}\u00A2` : '',
1114
1114
  ` Max cost: $${maxCost}`,
1115
1115
  ].filter(Boolean).join('\n');
1116
1116
  addSystemText(preview);
@@ -1128,7 +1128,7 @@ async function agentCommand(thesisId, opts) {
1128
1128
  action: params.action,
1129
1129
  type: params.type,
1130
1130
  count: params.count,
1131
- ...(priceDollars ? { yes_price: priceDollars } : {}),
1131
+ ...(priceCents ? { yes_price: priceCents } : {}),
1132
1132
  });
1133
1133
  const order = result.order || result;
1134
1134
  return {
@@ -1217,6 +1217,10 @@ When the conversation produces a concrete trade idea (specific contract, directi
1217
1217
  - After creating, confirm the strategy details and mention that sf runtime --dangerous can execute it.
1218
1218
  - If the user says "change the stop loss on T150 to 30", use update_strategy.
1219
1219
 
1220
+ ## Trading status
1221
+
1222
+ ${config.tradingEnabled ? 'Trading is ENABLED. You have place_order and cancel_order tools.' : 'Trading is DISABLED. You cannot place or cancel orders. Tell the user to run `sf setup --enable-trading` to unlock trading.'}
1223
+
1220
1224
  ## Current thesis state
1221
1225
 
1222
1226
  Thesis: ${ctx.thesis || ctx.rawThesis || 'N/A'}
@@ -1762,7 +1766,7 @@ Output a structured summary. Be concise but preserve every important detail —
1762
1766
  const result = await createOrder({
1763
1767
  ticker, side: 'yes', action: 'buy', type: 'limit',
1764
1768
  count: parseInt(qtyStr),
1765
- yes_price: (parseInt(priceStr) / 100).toFixed(2),
1769
+ yes_price: parseInt(priceStr),
1766
1770
  });
1767
1771
  addSystemText(C.emerald('\u2713 Order placed: ' + ((result.order || result).order_id || 'OK')));
1768
1772
  }
@@ -1794,7 +1798,7 @@ Output a structured summary. Be concise but preserve every important detail —
1794
1798
  const result = await createOrder({
1795
1799
  ticker, side: 'yes', action: 'sell', type: 'limit',
1796
1800
  count: parseInt(qtyStr),
1797
- yes_price: (parseInt(priceStr) / 100).toFixed(2),
1801
+ yes_price: parseInt(priceStr),
1798
1802
  });
1799
1803
  addSystemText(C.emerald('\u2713 Order placed: ' + ((result.order || result).order_id || 'OK')));
1800
1804
  }
@@ -17,6 +17,7 @@ interface SetupOpts {
17
17
  key?: string;
18
18
  enableTrading?: boolean;
19
19
  disableTrading?: boolean;
20
+ kalshi?: boolean;
20
21
  }
21
22
  export declare function setupCommand(opts: SetupOpts): Promise<void>;
22
23
  export {};
@@ -147,6 +147,24 @@ async function setupCommand(opts) {
147
147
  ok(`保存到 ${(0, config_js_1.getConfigPath)()}`);
148
148
  return;
149
149
  }
150
+ // ── sf setup --kalshi (reconfigure Kalshi credentials) ──────────────────
151
+ if (opts.kalshi) {
152
+ const existing = (0, config_js_1.loadFileConfig)();
153
+ blank();
154
+ console.log(` ${bold('重新配置 Kalshi 凭证')}`);
155
+ blank();
156
+ info('去 https://kalshi.com/account/api-keys 生成新的 API key。');
157
+ info('如果需要交易功能,确保勾选 read+write 权限。');
158
+ blank();
159
+ await promptForKalshi(existing);
160
+ (0, config_js_1.saveConfig)(existing);
161
+ if (existing.kalshiKeyId) {
162
+ process.env.KALSHI_API_KEY_ID = existing.kalshiKeyId;
163
+ process.env.KALSHI_PRIVATE_KEY_PATH = existing.kalshiPrivateKeyPath;
164
+ }
165
+ blank();
166
+ return;
167
+ }
150
168
  // ── sf setup --enable-trading / --disable-trading ────────────────────────
151
169
  if (opts.enableTrading) {
152
170
  const existing = (0, config_js_1.loadFileConfig)();
@@ -26,7 +26,6 @@ async function executeOrder(ticker, qty, action, opts) {
26
26
  if (priceCents !== undefined && (priceCents < 1 || priceCents > 99)) {
27
27
  throw new Error('Price must be 1-99 cents.');
28
28
  }
29
- const priceDollars = priceCents ? (priceCents / 100).toFixed(2) : undefined;
30
29
  const maxCost = ((priceCents || 99) * quantity / 100).toFixed(2);
31
30
  console.log();
32
31
  console.log(` ${utils_js_1.c.bold}${utils_js_1.c.cyan}${action.toUpperCase()} Order${utils_js_1.c.reset}`);
@@ -35,7 +34,7 @@ async function executeOrder(ticker, qty, action, opts) {
35
34
  console.log(` Side: ${side === 'yes' ? utils_js_1.c.green + 'YES' + utils_js_1.c.reset : utils_js_1.c.red + 'NO' + utils_js_1.c.reset}`);
36
35
  console.log(` Quantity: ${quantity}`);
37
36
  console.log(` Type: ${orderType}`);
38
- if (priceDollars)
37
+ if (priceCents)
39
38
  console.log(` Price: ${priceCents}¢`);
40
39
  console.log(` Max cost: $${maxCost}`);
41
40
  console.log();
@@ -53,7 +52,7 @@ async function executeOrder(ticker, qty, action, opts) {
53
52
  action,
54
53
  type: orderType,
55
54
  count: quantity,
56
- ...(priceDollars ? { yes_price: priceDollars } : {}),
55
+ ...(priceCents ? { yes_price: priceCents } : {}),
57
56
  });
58
57
  const order = result.order || result;
59
58
  console.log();
package/dist/index.js CHANGED
@@ -87,8 +87,9 @@ program
87
87
  .option('--key <key>', 'Set SF API key (non-interactive, for CI)')
88
88
  .option('--enable-trading', 'Enable trading (sf buy/sell/cancel)')
89
89
  .option('--disable-trading', 'Disable trading')
90
+ .option('--kalshi', 'Reconfigure Kalshi API credentials')
90
91
  .action(async (opts) => {
91
- await run(() => (0, setup_js_1.setupCommand)({ check: opts.check, reset: opts.reset, key: opts.key, enableTrading: opts.enableTrading, disableTrading: opts.disableTrading }));
92
+ await run(() => (0, setup_js_1.setupCommand)({ check: opts.check, reset: opts.reset, key: opts.key, enableTrading: opts.enableTrading, disableTrading: opts.disableTrading, kalshi: opts.kalshi }));
92
93
  });
93
94
  // ── sf list ──────────────────────────────────────────────────────────────────
94
95
  program
package/dist/kalshi.d.ts CHANGED
@@ -103,7 +103,7 @@ export declare function createOrder(params: {
103
103
  action: 'buy' | 'sell';
104
104
  type: 'limit' | 'market';
105
105
  count: number;
106
- yes_price?: string;
106
+ yes_price?: number;
107
107
  client_order_id?: string;
108
108
  }): Promise<{
109
109
  order: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfunctions/cli",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
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"