@spfunctions/cli 1.7.19 → 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.
- package/dist/101.index.js +1 -0
- package/dist/12.index.js +1 -0
- package/dist/160.index.js +1 -0
- package/dist/174.index.js +1 -0
- package/dist/278.index.js +6 -0
- package/dist/582.index.js +1 -0
- package/dist/641.index.js +324 -0
- package/dist/669.index.js +1 -0
- package/dist/722.index.js +1 -0
- package/dist/788.index.js +1 -0
- package/dist/816.index.js +12 -0
- package/dist/830.index.js +1 -0
- package/dist/921.index.js +1 -0
- package/dist/index.js +1 -833
- package/package.json +5 -2
- package/dist/cache.d.ts +0 -6
- package/dist/cache.js +0 -31
- package/dist/cache.test.d.ts +0 -1
- package/dist/cache.test.js +0 -73
- package/dist/client.d.ts +0 -56
- package/dist/client.js +0 -205
- package/dist/client.test.d.ts +0 -1
- package/dist/client.test.js +0 -89
- package/dist/commands/agent.d.ts +0 -20
- package/dist/commands/agent.js +0 -4119
- package/dist/commands/announcements.d.ts +0 -3
- package/dist/commands/announcements.js +0 -28
- package/dist/commands/augment.d.ts +0 -12
- package/dist/commands/augment.js +0 -56
- package/dist/commands/balance.d.ts +0 -3
- package/dist/commands/balance.js +0 -17
- package/dist/commands/book.d.ts +0 -17
- package/dist/commands/book.js +0 -220
- package/dist/commands/cancel.d.ts +0 -5
- package/dist/commands/cancel.js +0 -41
- package/dist/commands/context.d.ts +0 -6
- package/dist/commands/context.js +0 -208
- package/dist/commands/create.d.ts +0 -7
- package/dist/commands/create.js +0 -42
- package/dist/commands/dashboard.d.ts +0 -14
- package/dist/commands/dashboard.js +0 -215
- package/dist/commands/delta.d.ts +0 -16
- package/dist/commands/delta.js +0 -115
- package/dist/commands/edges.d.ts +0 -26
- package/dist/commands/edges.js +0 -246
- package/dist/commands/evaluate.d.ts +0 -4
- package/dist/commands/evaluate.js +0 -30
- package/dist/commands/explore.d.ts +0 -14
- package/dist/commands/explore.js +0 -116
- package/dist/commands/feed.d.ts +0 -13
- package/dist/commands/feed.js +0 -73
- package/dist/commands/fills.d.ts +0 -4
- package/dist/commands/fills.js +0 -29
- package/dist/commands/forecast.d.ts +0 -4
- package/dist/commands/forecast.js +0 -53
- package/dist/commands/get.d.ts +0 -5
- package/dist/commands/get.js +0 -98
- package/dist/commands/heartbeat.d.ts +0 -20
- package/dist/commands/heartbeat.js +0 -73
- package/dist/commands/history.d.ts +0 -3
- package/dist/commands/history.js +0 -38
- package/dist/commands/liquidity.d.ts +0 -14
- package/dist/commands/liquidity.js +0 -378
- package/dist/commands/list.d.ts +0 -5
- package/dist/commands/list.js +0 -38
- package/dist/commands/login.d.ts +0 -10
- package/dist/commands/login.js +0 -98
- package/dist/commands/markets.d.ts +0 -10
- package/dist/commands/markets.js +0 -39
- package/dist/commands/milestones.d.ts +0 -8
- package/dist/commands/milestones.js +0 -56
- package/dist/commands/orders.d.ts +0 -4
- package/dist/commands/orders.js +0 -28
- package/dist/commands/performance.d.ts +0 -11
- package/dist/commands/performance.js +0 -250
- package/dist/commands/positions.d.ts +0 -19
- package/dist/commands/positions.js +0 -294
- package/dist/commands/prompt.d.ts +0 -13
- package/dist/commands/prompt.js +0 -35
- package/dist/commands/publish.d.ts +0 -15
- package/dist/commands/publish.js +0 -39
- package/dist/commands/query.d.ts +0 -15
- package/dist/commands/query.js +0 -132
- package/dist/commands/rfq.d.ts +0 -5
- package/dist/commands/rfq.js +0 -35
- package/dist/commands/scan.d.ts +0 -11
- package/dist/commands/scan.js +0 -230
- package/dist/commands/schedule.d.ts +0 -3
- package/dist/commands/schedule.js +0 -38
- package/dist/commands/settlements.d.ts +0 -6
- package/dist/commands/settlements.js +0 -50
- package/dist/commands/setup.d.ts +0 -24
- package/dist/commands/setup.js +0 -700
- package/dist/commands/signal.d.ts +0 -6
- package/dist/commands/signal.js +0 -32
- package/dist/commands/strategies.d.ts +0 -11
- package/dist/commands/strategies.js +0 -130
- package/dist/commands/telegram.d.ts +0 -15
- package/dist/commands/telegram.js +0 -125
- package/dist/commands/trade.d.ts +0 -12
- package/dist/commands/trade.js +0 -112
- package/dist/commands/watch.d.ts +0 -19
- package/dist/commands/watch.js +0 -157
- package/dist/commands/whatif.d.ts +0 -17
- package/dist/commands/whatif.js +0 -209
- package/dist/commands/x.d.ts +0 -28
- package/dist/commands/x.js +0 -167
- package/dist/config.d.ts +0 -55
- package/dist/config.js +0 -139
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -138
- package/dist/index.d.ts +0 -20
- package/dist/kalshi.d.ts +0 -144
- package/dist/kalshi.js +0 -498
- package/dist/polymarket.d.ts +0 -237
- package/dist/polymarket.js +0 -353
- package/dist/polymarket.test.d.ts +0 -1
- package/dist/polymarket.test.js +0 -424
- package/dist/share.d.ts +0 -4
- package/dist/share.js +0 -27
- package/dist/skills/loader.d.ts +0 -19
- package/dist/skills/loader.js +0 -86
- package/dist/telegram/agent-bridge.d.ts +0 -15
- package/dist/telegram/agent-bridge.js +0 -573
- package/dist/telegram/bot.d.ts +0 -10
- package/dist/telegram/bot.js +0 -297
- package/dist/telegram/commands.d.ts +0 -11
- package/dist/telegram/commands.js +0 -120
- package/dist/telegram/format.d.ts +0 -11
- package/dist/telegram/format.js +0 -51
- package/dist/telegram/format.test.d.ts +0 -1
- package/dist/telegram/format.test.js +0 -73
- package/dist/telegram/poller.d.ts +0 -6
- package/dist/telegram/poller.js +0 -32
- package/dist/topics.d.ts +0 -17
- package/dist/topics.js +0 -102
- package/dist/topics.test.d.ts +0 -1
- package/dist/topics.test.js +0 -131
- package/dist/tui/border.d.ts +0 -33
- package/dist/tui/border.js +0 -87
- package/dist/tui/chart.d.ts +0 -19
- package/dist/tui/chart.js +0 -117
- package/dist/tui/dashboard.d.ts +0 -9
- package/dist/tui/dashboard.js +0 -814
- package/dist/tui/layout.d.ts +0 -16
- package/dist/tui/layout.js +0 -41
- package/dist/tui/screen.d.ts +0 -33
- package/dist/tui/screen.js +0 -102
- package/dist/tui/state.d.ts +0 -40
- package/dist/tui/state.js +0 -36
- package/dist/tui/widgets/commandbar.d.ts +0 -8
- package/dist/tui/widgets/commandbar.js +0 -82
- package/dist/tui/widgets/detail.d.ts +0 -9
- package/dist/tui/widgets/detail.js +0 -151
- package/dist/tui/widgets/edges.d.ts +0 -4
- package/dist/tui/widgets/edges.js +0 -34
- package/dist/tui/widgets/liquidity.d.ts +0 -9
- package/dist/tui/widgets/liquidity.js +0 -142
- package/dist/tui/widgets/orders.d.ts +0 -4
- package/dist/tui/widgets/orders.js +0 -37
- package/dist/tui/widgets/portfolio.d.ts +0 -4
- package/dist/tui/widgets/portfolio.js +0 -59
- package/dist/tui/widgets/signals.d.ts +0 -4
- package/dist/tui/widgets/signals.js +0 -31
- package/dist/tui/widgets/statusbar.d.ts +0 -8
- package/dist/tui/widgets/statusbar.js +0 -72
- package/dist/tui/widgets/thesis.d.ts +0 -4
- package/dist/tui/widgets/thesis.js +0 -66
- package/dist/tui/widgets/trade.d.ts +0 -9
- package/dist/tui/widgets/trade.js +0 -117
- package/dist/tui/widgets/upcoming.d.ts +0 -4
- package/dist/tui/widgets/upcoming.js +0 -41
- package/dist/tui/widgets/whatif.d.ts +0 -7
- package/dist/tui/widgets/whatif.js +0 -113
- package/dist/types/output.d.ts +0 -412
- package/dist/types/output.js +0 -9
- package/dist/utils.d.ts +0 -52
- package/dist/utils.js +0 -146
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -111
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.announcementsCommand = announcementsCommand;
|
|
4
|
-
const kalshi_js_1 = require("../kalshi.js");
|
|
5
|
-
const utils_js_1 = require("../utils.js");
|
|
6
|
-
async function announcementsCommand(opts) {
|
|
7
|
-
const announcements = await (0, kalshi_js_1.getExchangeAnnouncements)();
|
|
8
|
-
if (opts.json) {
|
|
9
|
-
console.log(JSON.stringify(announcements, null, 2));
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (announcements.length === 0) {
|
|
13
|
-
console.log(`${utils_js_1.c.dim}No announcements.${utils_js_1.c.reset}`);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
console.log(`${utils_js_1.c.bold}${utils_js_1.c.cyan}Exchange Announcements${utils_js_1.c.reset}`);
|
|
17
|
-
console.log(`${utils_js_1.c.dim}${'─'.repeat(70)}${utils_js_1.c.reset}`);
|
|
18
|
-
for (const a of announcements.slice(0, 20)) {
|
|
19
|
-
const time = a.created_time ? new Date(a.created_time).toLocaleDateString() : '';
|
|
20
|
-
const type = a.type ? `[${a.type}]` : '';
|
|
21
|
-
console.log(` ${utils_js_1.c.dim}${time}${utils_js_1.c.reset} ${type} ${a.title || a.message || ''}`);
|
|
22
|
-
if (a.body) {
|
|
23
|
-
const body = String(a.body).slice(0, 120);
|
|
24
|
-
console.log(` ${utils_js_1.c.dim}${body}${utils_js_1.c.reset}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
console.log(`\n${utils_js_1.c.dim}${announcements.length} announcement(s)${utils_js_1.c.reset}`);
|
|
28
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sf augment <thesisId> [--dry-run]
|
|
3
|
-
*
|
|
4
|
-
* Review suggested causal tree nodes from recent evaluations,
|
|
5
|
-
* accept/reject via LLM, and merge into the tree (append-only).
|
|
6
|
-
*/
|
|
7
|
-
export declare function augmentCommand(thesisId: string, opts: {
|
|
8
|
-
dryRun?: boolean;
|
|
9
|
-
json?: boolean;
|
|
10
|
-
apiKey?: string;
|
|
11
|
-
apiUrl?: string;
|
|
12
|
-
}): Promise<void>;
|
package/dist/commands/augment.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* sf augment <thesisId> [--dry-run]
|
|
4
|
-
*
|
|
5
|
-
* Review suggested causal tree nodes from recent evaluations,
|
|
6
|
-
* accept/reject via LLM, and merge into the tree (append-only).
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.augmentCommand = augmentCommand;
|
|
10
|
-
const client_js_1 = require("../client.js");
|
|
11
|
-
async function augmentCommand(thesisId, opts) {
|
|
12
|
-
const client = new client_js_1.SFClient(opts.apiKey, opts.apiUrl);
|
|
13
|
-
console.log(`\x1b[2m${opts.dryRun ? 'Previewing' : 'Running'} tree augmentation for ${thesisId.slice(0, 8)}...\x1b[22m`);
|
|
14
|
-
const result = await client.augmentTree(thesisId, opts.dryRun);
|
|
15
|
-
if (opts.json) {
|
|
16
|
-
console.log(JSON.stringify(result, null, 2));
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// Display results
|
|
20
|
-
console.log();
|
|
21
|
-
if (result.warning) {
|
|
22
|
-
console.log(` \x1b[33m⚠ ${result.warning}\x1b[39m`);
|
|
23
|
-
console.log();
|
|
24
|
-
}
|
|
25
|
-
if (result.suggestedNodes?.length > 0) {
|
|
26
|
-
console.log(` \x1b[1mSuggested Nodes\x1b[22m (${result.suggestedNodes.length} from evaluations)`);
|
|
27
|
-
for (const s of result.suggestedNodes) {
|
|
28
|
-
console.log(` • ${s.label} \x1b[2m(parent: ${s.parentNodeId}, est: ${Math.round(s.estimatedProbability * 100)}%, seen ${s.frequency}x)\x1b[22m`);
|
|
29
|
-
}
|
|
30
|
-
console.log();
|
|
31
|
-
}
|
|
32
|
-
if (result.acceptedNodes?.length > 0) {
|
|
33
|
-
console.log(` \x1b[1m\x1b[32mAccepted Nodes\x1b[39m\x1b[22m (${result.acceptedNodes.length})`);
|
|
34
|
-
for (const n of result.acceptedNodes) {
|
|
35
|
-
console.log(` \x1b[32m+\x1b[39m ${n.id}: ${n.label} \x1b[2m(prob: ${Math.round(n.probability * 100)}%, imp: ${n.importance})\x1b[22m`);
|
|
36
|
-
}
|
|
37
|
-
console.log();
|
|
38
|
-
if (Object.keys(result.updatedImportanceWeights || {}).length > 0) {
|
|
39
|
-
console.log(` \x1b[1mRebalanced Weights\x1b[22m`);
|
|
40
|
-
for (const [nodeId, weight] of Object.entries(result.updatedImportanceWeights)) {
|
|
41
|
-
console.log(` ${nodeId} → ${weight}`);
|
|
42
|
-
}
|
|
43
|
-
console.log();
|
|
44
|
-
}
|
|
45
|
-
if (result.applied) {
|
|
46
|
-
console.log(` \x1b[32m✓ Applied to causal tree\x1b[39m`);
|
|
47
|
-
}
|
|
48
|
-
else if (opts.dryRun) {
|
|
49
|
-
console.log(` \x1b[2mDry run — use without --dry-run to apply\x1b[22m`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
console.log(' No nodes accepted.');
|
|
54
|
-
}
|
|
55
|
-
console.log();
|
|
56
|
-
}
|
package/dist/commands/balance.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.balanceCommand = balanceCommand;
|
|
4
|
-
const kalshi_js_1 = require("../kalshi.js");
|
|
5
|
-
const utils_js_1 = require("../utils.js");
|
|
6
|
-
async function balanceCommand(opts) {
|
|
7
|
-
const result = await (0, kalshi_js_1.getBalance)();
|
|
8
|
-
if (!result)
|
|
9
|
-
throw new Error('Kalshi not configured. Run: sf setup --kalshi');
|
|
10
|
-
if (opts.json) {
|
|
11
|
-
console.log(JSON.stringify(result, null, 2));
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
console.log(`${utils_js_1.c.bold}${utils_js_1.c.cyan}Kalshi Account${utils_js_1.c.reset}`);
|
|
15
|
-
console.log(` Balance: $${result.balance.toFixed(2)}`);
|
|
16
|
-
console.log(` Portfolio Value: $${result.portfolioValue.toFixed(2)}`);
|
|
17
|
-
}
|
package/dist/commands/book.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sf book — Orderbook depth, price history, and liquidity for individual markets
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* sf book KXWTIMAX-26DEC31-T135 Single Kalshi market
|
|
6
|
-
* sf book KXWTI-T135 KXCPI-26MAY Multiple markets
|
|
7
|
-
* sf book --poly "oil price" Polymarket search
|
|
8
|
-
* sf book KXWTIMAX-26DEC31-T135 --history With 7d price history
|
|
9
|
-
* sf book KXWTIMAX-26DEC31-T135 --json JSON output
|
|
10
|
-
*/
|
|
11
|
-
interface BookOpts {
|
|
12
|
-
poly?: string;
|
|
13
|
-
history?: boolean;
|
|
14
|
-
json?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare function bookCommand(tickers: string[], opts: BookOpts): Promise<void>;
|
|
17
|
-
export {};
|
package/dist/commands/book.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* sf book — Orderbook depth, price history, and liquidity for individual markets
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* sf book KXWTIMAX-26DEC31-T135 Single Kalshi market
|
|
7
|
-
* sf book KXWTI-T135 KXCPI-26MAY Multiple markets
|
|
8
|
-
* sf book --poly "oil price" Polymarket search
|
|
9
|
-
* sf book KXWTIMAX-26DEC31-T135 --history With 7d price history
|
|
10
|
-
* sf book KXWTIMAX-26DEC31-T135 --json JSON output
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.bookCommand = bookCommand;
|
|
14
|
-
const client_js_1 = require("../client.js");
|
|
15
|
-
const kalshi_js_1 = require("../kalshi.js");
|
|
16
|
-
const polymarket_js_1 = require("../polymarket.js");
|
|
17
|
-
const utils_js_1 = require("../utils.js");
|
|
18
|
-
async function bookCommand(tickers, opts) {
|
|
19
|
-
const results = [];
|
|
20
|
-
// ── Polymarket search mode ──
|
|
21
|
-
if (opts.poly) {
|
|
22
|
-
console.log(`${utils_js_1.c.dim}Searching Polymarket for "${opts.poly}"...${utils_js_1.c.reset}`);
|
|
23
|
-
const events = await (0, polymarket_js_1.polymarketSearch)(opts.poly, 10);
|
|
24
|
-
for (const event of events) {
|
|
25
|
-
for (const m of (event.markets || []).slice(0, 5)) {
|
|
26
|
-
if (!m.active || m.closed || !m.clobTokenIds)
|
|
27
|
-
continue;
|
|
28
|
-
const ids = (0, polymarket_js_1.parseClobTokenIds)(m.clobTokenIds);
|
|
29
|
-
if (!ids)
|
|
30
|
-
continue;
|
|
31
|
-
const depth = await (0, polymarket_js_1.polymarketGetOrderbookWithDepth)(ids[0]);
|
|
32
|
-
if (!depth)
|
|
33
|
-
continue;
|
|
34
|
-
const prices = (0, polymarket_js_1.parseOutcomePrices)(m.outcomePrices);
|
|
35
|
-
const book = {
|
|
36
|
-
venue: 'polymarket',
|
|
37
|
-
ticker: m.conditionId?.slice(0, 16) || m.id,
|
|
38
|
-
title: m.groupItemTitle
|
|
39
|
-
? `${event.title}: ${m.groupItemTitle}`
|
|
40
|
-
: m.question || event.title,
|
|
41
|
-
bestBid: depth.bestBid,
|
|
42
|
-
bestAsk: depth.bestAsk,
|
|
43
|
-
spread: depth.spread,
|
|
44
|
-
bidDepth: depth.totalBidDepth,
|
|
45
|
-
askDepth: depth.totalAskDepth,
|
|
46
|
-
liquidityScore: depth.liquidityScore,
|
|
47
|
-
volume24h: m.volume24hr || 0,
|
|
48
|
-
openInterest: m.liquidityNum || 0,
|
|
49
|
-
lastPrice: prices[0] ? (0, polymarket_js_1.toCents)(prices[0]) : 0,
|
|
50
|
-
expiry: m.endDateIso || null,
|
|
51
|
-
bidLevels: depth.levels.bids.slice(0, 5).map(l => ({ price: Math.round(parseFloat(l.price) * 100), size: Math.round(parseFloat(l.size)) })),
|
|
52
|
-
askLevels: depth.levels.asks.slice(0, 5).map(l => ({ price: Math.round(parseFloat(l.price) * 100), size: Math.round(parseFloat(l.size)) })),
|
|
53
|
-
};
|
|
54
|
-
// Price history sparkline
|
|
55
|
-
if (opts.history) {
|
|
56
|
-
try {
|
|
57
|
-
const hist = await (0, polymarket_js_1.polymarketGetPriceHistory)({ tokenId: ids[0], interval: '1w', fidelity: 360 });
|
|
58
|
-
if (hist.length > 0) {
|
|
59
|
-
book.sparkline = makeSparkline(hist.map(h => h.p * 100));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch { /* skip */ }
|
|
63
|
-
}
|
|
64
|
-
results.push(book);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// ── Kalshi tickers ──
|
|
69
|
-
for (const ticker of tickers) {
|
|
70
|
-
console.log(`${utils_js_1.c.dim}Fetching ${ticker}...${utils_js_1.c.reset}`);
|
|
71
|
-
try {
|
|
72
|
-
const market = await (0, client_js_1.kalshiFetchMarket)(ticker);
|
|
73
|
-
const ob = await (0, kalshi_js_1.getPublicOrderbook)(ticker);
|
|
74
|
-
const yesBids = (ob?.yes_dollars || [])
|
|
75
|
-
.map(([p, q]) => ({ price: Math.round(parseFloat(p) * 100), size: Math.round(parseFloat(q)) }))
|
|
76
|
-
.filter((l) => l.price > 0)
|
|
77
|
-
.sort((a, b) => b.price - a.price);
|
|
78
|
-
const noAsks = (ob?.no_dollars || [])
|
|
79
|
-
.map(([p, q]) => ({ price: Math.round(parseFloat(p) * 100), size: Math.round(parseFloat(q)) }))
|
|
80
|
-
.filter((l) => l.price > 0)
|
|
81
|
-
.sort((a, b) => b.price - a.price);
|
|
82
|
-
const bestBid = yesBids[0]?.price || 0;
|
|
83
|
-
const bestAsk = noAsks.length > 0 ? (100 - noAsks[0].price) : 100;
|
|
84
|
-
const spread = bestAsk - bestBid;
|
|
85
|
-
const bidDepth = yesBids.reduce((s, l) => s + l.size, 0);
|
|
86
|
-
const askDepth = noAsks.reduce((s, l) => s + l.size, 0);
|
|
87
|
-
const totalDepth = yesBids.slice(0, 3).reduce((s, l) => s + l.size, 0) +
|
|
88
|
-
noAsks.slice(0, 3).reduce((s, l) => s + l.size, 0);
|
|
89
|
-
const liq = spread <= 2 && totalDepth >= 500 ? 'high' : spread <= 5 && totalDepth >= 100 ? 'medium' : 'low';
|
|
90
|
-
const lastPrice = parseFloat(market.last_price_dollars || '0') * 100;
|
|
91
|
-
const book = {
|
|
92
|
-
venue: 'kalshi',
|
|
93
|
-
ticker: market.ticker || ticker,
|
|
94
|
-
title: market.title || market.subtitle || ticker,
|
|
95
|
-
bestBid,
|
|
96
|
-
bestAsk,
|
|
97
|
-
spread,
|
|
98
|
-
bidDepth,
|
|
99
|
-
askDepth,
|
|
100
|
-
liquidityScore: liq,
|
|
101
|
-
volume24h: parseFloat(market.volume_24h_fp || '0'),
|
|
102
|
-
openInterest: parseFloat(market.open_interest_fp || '0'),
|
|
103
|
-
lastPrice: Math.round(lastPrice),
|
|
104
|
-
expiry: market.close_time || market.expiration_time || null,
|
|
105
|
-
bidLevels: yesBids.slice(0, 5),
|
|
106
|
-
askLevels: noAsks.slice(0, 5).map((l) => ({ price: 100 - l.price, size: l.size })),
|
|
107
|
-
};
|
|
108
|
-
// Kalshi price history
|
|
109
|
-
if (opts.history) {
|
|
110
|
-
// Try authenticated candlestick API first (requires Kalshi keys)
|
|
111
|
-
if ((0, kalshi_js_1.isKalshiConfigured)()) {
|
|
112
|
-
try {
|
|
113
|
-
const now = Math.floor(Date.now() / 1000);
|
|
114
|
-
const weekAgo = now - 7 * 86400;
|
|
115
|
-
const candleResults = await (0, kalshi_js_1.getBatchCandlesticks)({
|
|
116
|
-
tickers: [ticker],
|
|
117
|
-
startTs: weekAgo,
|
|
118
|
-
endTs: now,
|
|
119
|
-
periodInterval: 1440,
|
|
120
|
-
});
|
|
121
|
-
const mktEntry = candleResults.find((e) => e.market_ticker === ticker) || candleResults[0];
|
|
122
|
-
const mktCandles = mktEntry?.candlesticks || [];
|
|
123
|
-
if (Array.isArray(mktCandles) && mktCandles.length > 0) {
|
|
124
|
-
const prices = mktCandles.map((cd) => {
|
|
125
|
-
// Kalshi nests prices: cd.price.close_dollars or cd.yes_ask.close_dollars
|
|
126
|
-
const p = cd.price?.close_dollars ?? cd.yes_ask?.close_dollars ?? cd.yes_bid?.close_dollars ?? cd.close ?? cd.price;
|
|
127
|
-
const v = typeof p === 'string' ? parseFloat(p) * 100 : (typeof p === 'number' ? p : 0);
|
|
128
|
-
return Math.round(v);
|
|
129
|
-
}).filter((p) => p > 0);
|
|
130
|
-
if (prices.length >= 2) {
|
|
131
|
-
book.sparkline = makeSparkline(prices);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch { /* skip */ }
|
|
136
|
-
}
|
|
137
|
-
// Fallback: show previous vs current from market data
|
|
138
|
-
if (!book.sparkline) {
|
|
139
|
-
const prev = parseFloat(market.previous_price_dollars || '0') * 100;
|
|
140
|
-
if (prev > 0 && Math.abs(prev - book.lastPrice) > 0) {
|
|
141
|
-
const delta = book.lastPrice - Math.round(prev);
|
|
142
|
-
const deltaColor = delta >= 0 ? utils_js_1.c.green : utils_js_1.c.red;
|
|
143
|
-
const deltaStr = delta >= 0 ? `+${delta}` : `${delta}`;
|
|
144
|
-
book.sparkline = `prev ${Math.round(prev)}¢ → now ${book.lastPrice}¢ ${deltaColor}${deltaStr}${utils_js_1.c.reset}`;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
results.push(book);
|
|
149
|
-
}
|
|
150
|
-
catch (err) {
|
|
151
|
-
console.error(`${utils_js_1.c.red}Failed to fetch ${ticker}: ${err.message}${utils_js_1.c.reset}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (results.length === 0) {
|
|
155
|
-
console.log(`\n ${utils_js_1.c.dim}No markets found. Check the ticker and try again.${utils_js_1.c.reset}\n`);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
// ── JSON output ──
|
|
159
|
-
if (opts.json) {
|
|
160
|
-
console.log(JSON.stringify(results, null, 2));
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
// ── Formatted output ──
|
|
164
|
-
for (const book of results) {
|
|
165
|
-
const venueTag = book.venue === 'polymarket' ? `${utils_js_1.c.blue}POLY${utils_js_1.c.reset}` : `${utils_js_1.c.cyan}KLSH${utils_js_1.c.reset}`;
|
|
166
|
-
console.log();
|
|
167
|
-
console.log(`${utils_js_1.c.bold}${venueTag} ${book.title}${utils_js_1.c.reset}`);
|
|
168
|
-
console.log(`${utils_js_1.c.dim}${book.ticker}${utils_js_1.c.reset}`);
|
|
169
|
-
console.log();
|
|
170
|
-
// Summary line
|
|
171
|
-
const liqColor = book.liquidityScore === 'high' ? utils_js_1.c.green : book.liquidityScore === 'medium' ? utils_js_1.c.yellow : utils_js_1.c.red;
|
|
172
|
-
console.log(` Last ${utils_js_1.c.bold}${book.lastPrice}¢${utils_js_1.c.reset} ` +
|
|
173
|
-
`Bid ${utils_js_1.c.green}${book.bestBid}¢${utils_js_1.c.reset} ` +
|
|
174
|
-
`Ask ${utils_js_1.c.red}${book.bestAsk}¢${utils_js_1.c.reset} ` +
|
|
175
|
-
`Spread ${liqColor}${book.spread}¢${utils_js_1.c.reset} ` +
|
|
176
|
-
`Liq ${liqColor}${book.liquidityScore}${utils_js_1.c.reset}`);
|
|
177
|
-
console.log(` Vol24h ${(0, utils_js_1.vol)(book.volume24h)} ` +
|
|
178
|
-
`OI ${(0, utils_js_1.vol)(book.openInterest)}` +
|
|
179
|
-
(book.expiry ? ` Expires ${book.expiry.slice(0, 10)}` : ''));
|
|
180
|
-
// Sparkline
|
|
181
|
-
if (book.sparkline) {
|
|
182
|
-
console.log(` 7d ${book.sparkline}`);
|
|
183
|
-
}
|
|
184
|
-
// Orderbook depth
|
|
185
|
-
if (book.bidLevels && book.askLevels) {
|
|
186
|
-
console.log();
|
|
187
|
-
console.log(` ${utils_js_1.c.dim}${(0, utils_js_1.pad)('BID', 18)} ${(0, utils_js_1.pad)('ASK', 18)}${utils_js_1.c.reset}`);
|
|
188
|
-
console.log(` ${utils_js_1.c.dim}${'─'.repeat(38)}${utils_js_1.c.reset}`);
|
|
189
|
-
const maxLevels = Math.max(book.bidLevels.length, book.askLevels.length);
|
|
190
|
-
for (let i = 0; i < Math.min(maxLevels, 5); i++) {
|
|
191
|
-
const bid = book.bidLevels[i];
|
|
192
|
-
const ask = book.askLevels[i];
|
|
193
|
-
const bidStr = bid ? `${utils_js_1.c.green}${(0, utils_js_1.rpad)(`${bid.price}¢`, 5)}${utils_js_1.c.reset} ${(0, utils_js_1.rpad)(String(bid.size), 8)}` : (0, utils_js_1.pad)('', 18);
|
|
194
|
-
const askStr = ask ? `${utils_js_1.c.red}${(0, utils_js_1.rpad)(`${ask.price}¢`, 5)}${utils_js_1.c.reset} ${(0, utils_js_1.rpad)(String(ask.size), 8)}` : '';
|
|
195
|
-
console.log(` ${bidStr} ${askStr}`);
|
|
196
|
-
}
|
|
197
|
-
console.log(` ${utils_js_1.c.dim}depth: ${book.bidDepth} bid / ${book.askDepth} ask${utils_js_1.c.reset}`);
|
|
198
|
-
}
|
|
199
|
-
console.log();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
// ── Sparkline helper ──
|
|
203
|
-
function makeSparkline(values) {
|
|
204
|
-
if (values.length < 2)
|
|
205
|
-
return '';
|
|
206
|
-
const min = Math.min(...values);
|
|
207
|
-
const max = Math.max(...values);
|
|
208
|
-
const range = max - min || 1;
|
|
209
|
-
const blocks = '▁▂▃▄▅▆▇█';
|
|
210
|
-
const line = values.map(v => {
|
|
211
|
-
const idx = Math.round(((v - min) / range) * 7);
|
|
212
|
-
return blocks[idx];
|
|
213
|
-
}).join('');
|
|
214
|
-
const startPrice = Math.round(values[0]);
|
|
215
|
-
const endPrice = Math.round(values[values.length - 1]);
|
|
216
|
-
const delta = endPrice - startPrice;
|
|
217
|
-
const deltaColor = delta >= 0 ? utils_js_1.c.green : utils_js_1.c.red;
|
|
218
|
-
const deltaStr = delta >= 0 ? `+${delta}` : `${delta}`;
|
|
219
|
-
return `${line} ${startPrice}¢→${endPrice}¢ ${deltaColor}${deltaStr}${utils_js_1.c.reset}`;
|
|
220
|
-
}
|
package/dist/commands/cancel.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cancelCommand = cancelCommand;
|
|
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 cancelCommand(orderId, opts) {
|
|
8
|
-
(0, config_js_1.requireTrading)();
|
|
9
|
-
if (opts.all) {
|
|
10
|
-
const result = await (0, kalshi_js_1.getOrders)({ status: 'resting', limit: 200 });
|
|
11
|
-
if (!result)
|
|
12
|
-
throw new Error('Kalshi not configured.');
|
|
13
|
-
let toCancel = result.orders;
|
|
14
|
-
if (opts.ticker) {
|
|
15
|
-
toCancel = toCancel.filter((o) => (o.ticker || '').startsWith(opts.ticker));
|
|
16
|
-
}
|
|
17
|
-
if (toCancel.length === 0) {
|
|
18
|
-
console.log(`\n ${utils_js_1.c.dim}No resting orders to cancel.${utils_js_1.c.reset}\n`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
console.log(`\n Cancelling ${toCancel.length} order(s)...`);
|
|
22
|
-
if (!opts.yesIAmSure) {
|
|
23
|
-
for (let i = 3; i > 0; i--) {
|
|
24
|
-
process.stdout.write(` Executing in ${i}... (Ctrl+C to cancel)\r`);
|
|
25
|
-
await new Promise(r => setTimeout(r, 1000));
|
|
26
|
-
}
|
|
27
|
-
process.stdout.write(' Executing... \n');
|
|
28
|
-
}
|
|
29
|
-
for (let i = 0; i < toCancel.length; i += 20) {
|
|
30
|
-
const batch = toCancel.slice(i, i + 20).map((o) => o.order_id);
|
|
31
|
-
await (0, kalshi_js_1.batchCancelOrders)(batch);
|
|
32
|
-
}
|
|
33
|
-
console.log(`\n ${utils_js_1.c.green}✓${utils_js_1.c.reset} Cancelled ${toCancel.length} order(s).\n`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (!orderId) {
|
|
37
|
-
throw new Error('Usage: sf cancel <orderId> or sf cancel --all');
|
|
38
|
-
}
|
|
39
|
-
await (0, kalshi_js_1.cancelOrder)(orderId);
|
|
40
|
-
console.log(`\n ${utils_js_1.c.green}✓${utils_js_1.c.reset} Order ${orderId} cancelled.\n`);
|
|
41
|
-
}
|
package/dist/commands/context.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.contextCommand = contextCommand;
|
|
4
|
-
const client_js_1 = require("../client.js");
|
|
5
|
-
const kalshi_js_1 = require("../kalshi.js");
|
|
6
|
-
const utils_js_1 = require("../utils.js");
|
|
7
|
-
const share_js_1 = require("../share.js");
|
|
8
|
-
const SF_API_URL = process.env.SF_API_URL || 'https://simplefunctions.dev';
|
|
9
|
-
async function contextCommand(id, opts) {
|
|
10
|
-
// ── Mode 1: No thesis ID → global market intelligence ─────────────────────
|
|
11
|
-
if (!id) {
|
|
12
|
-
const res = await fetch(`${opts.apiUrl || SF_API_URL}/api/public/context`);
|
|
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.share) {
|
|
19
|
-
await (0, share_js_1.shareOutput)('context', '', data);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (opts.json) {
|
|
23
|
-
console.log(JSON.stringify(data, null, 2));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const scanTime = data.scannedAt ? (0, utils_js_1.shortDate)(data.scannedAt) : 'no scan yet';
|
|
27
|
-
const meta = data.meta || {};
|
|
28
|
-
console.log();
|
|
29
|
-
console.log(`${utils_js_1.c.bold}Markets${utils_js_1.c.reset} ${utils_js_1.c.dim}${meta.totalMarkets || 0} markets (K:${meta.kalshiMarkets || 0} P:${meta.polymarketMarkets || 0}) · scan: ${scanTime}${utils_js_1.c.reset}`);
|
|
30
|
-
console.log();
|
|
31
|
-
// ── Traditional markets ────────────────────────────────────────────────
|
|
32
|
-
const trad = data.traditional || [];
|
|
33
|
-
if (trad.length > 0) {
|
|
34
|
-
const line = trad.map((m) => {
|
|
35
|
-
const ch = m.changePct || 0;
|
|
36
|
-
const color = ch > 0 ? utils_js_1.c.green : ch < 0 ? utils_js_1.c.red : utils_js_1.c.dim;
|
|
37
|
-
const sign = ch > 0 ? '+' : '';
|
|
38
|
-
return `${utils_js_1.c.bold}${m.symbol}${utils_js_1.c.reset} ${m.price} ${color}${sign}${ch.toFixed(1)}%${utils_js_1.c.reset}`;
|
|
39
|
-
}).join(' ');
|
|
40
|
-
console.log(` ${line}`);
|
|
41
|
-
console.log();
|
|
42
|
-
}
|
|
43
|
-
// ── Highlights (cross-category stories) ────────────────────────────────
|
|
44
|
-
const highlights = data.highlights || [];
|
|
45
|
-
if (highlights.length > 0) {
|
|
46
|
-
console.log(`${utils_js_1.c.bold}${utils_js_1.c.cyan}Highlights${utils_js_1.c.reset}`);
|
|
47
|
-
for (const h of highlights) {
|
|
48
|
-
console.log(` ${utils_js_1.c.bold}${h.title}${utils_js_1.c.reset}`);
|
|
49
|
-
console.log(` ${utils_js_1.c.dim}${h.detail}${utils_js_1.c.reset}`);
|
|
50
|
-
if (h.relatedTickers?.length > 0) {
|
|
51
|
-
console.log(` ${utils_js_1.c.dim}tickers: ${h.relatedTickers.join(', ')}${utils_js_1.c.reset}`);
|
|
52
|
-
}
|
|
53
|
-
console.log(` ${utils_js_1.c.cyan}→ ${h.suggestedAction}${utils_js_1.c.reset}`);
|
|
54
|
-
console.log();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// ── Categories ─────────────────────────────────────────────────────────
|
|
58
|
-
const cats = data.categories || [];
|
|
59
|
-
if (cats.length > 0) {
|
|
60
|
-
console.log(`${utils_js_1.c.bold}Categories${utils_js_1.c.reset} ${utils_js_1.c.dim}(${cats.length} total)${utils_js_1.c.reset}`);
|
|
61
|
-
console.log(`${utils_js_1.c.dim}${'─'.repeat(70)}${utils_js_1.c.reset}`);
|
|
62
|
-
for (const cat of cats) {
|
|
63
|
-
const desc = cat.description ? ` ${utils_js_1.c.dim}${cat.description}${utils_js_1.c.reset}` : '';
|
|
64
|
-
console.log(`\n ${utils_js_1.c.bold}${cat.name}${utils_js_1.c.reset} ${utils_js_1.c.dim}${cat.marketCount} mkts · vol ${(0, utils_js_1.vol)(cat.totalVolume24h)}${utils_js_1.c.reset}${desc}`);
|
|
65
|
-
// Top movers in category
|
|
66
|
-
const movers = cat.topMovers || [];
|
|
67
|
-
if (movers.length > 0) {
|
|
68
|
-
for (const m of movers) {
|
|
69
|
-
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}`;
|
|
70
|
-
const ch = m.change24h || 0;
|
|
71
|
-
const chColor = ch > 0 ? utils_js_1.c.green : ch < 0 ? utils_js_1.c.red : utils_js_1.c.dim;
|
|
72
|
-
const chStr = ch !== 0 ? `${chColor}${ch > 0 ? '+' : ''}${ch}¢${utils_js_1.c.reset}` : '';
|
|
73
|
-
console.log(` ${venue} ${(0, utils_js_1.rpad)(`${m.price}¢`, 5)} ${(0, utils_js_1.rpad)(chStr, 14)} ${(0, utils_js_1.trunc)(m.title, 45)} ${utils_js_1.c.dim}${m.ticker.slice(0, 18)}${utils_js_1.c.reset}`);
|
|
74
|
-
if (m.whyInteresting) {
|
|
75
|
-
console.log(` ${utils_js_1.c.dim}${m.whyInteresting}${utils_js_1.c.reset}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Most liquid
|
|
80
|
-
const liquid = cat.mostLiquid || [];
|
|
81
|
-
if (liquid.length > 0) {
|
|
82
|
-
for (const m of liquid) {
|
|
83
|
-
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}`;
|
|
84
|
-
console.log(` ${venue} ${(0, utils_js_1.rpad)(`${m.price}¢`, 5)} spread ${m.spread}¢ vol ${(0, utils_js_1.vol)(Math.round(m.volume24h))} ${utils_js_1.c.dim}${(0, utils_js_1.trunc)(m.title, 35)}${utils_js_1.c.reset}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
console.log();
|
|
89
|
-
}
|
|
90
|
-
// ── Thesis edges ───────────────────────────────────────────────────────
|
|
91
|
-
const edges = data.edges || [];
|
|
92
|
-
if (edges.length > 0) {
|
|
93
|
-
console.log(`${utils_js_1.c.bold}Thesis Edges${utils_js_1.c.reset}`);
|
|
94
|
-
for (const e of edges.slice(0, 6)) {
|
|
95
|
-
const venue = e.venue === 'kalshi' ? `${utils_js_1.c.cyan}K${utils_js_1.c.reset}` : `${utils_js_1.c.magenta}P${utils_js_1.c.reset}`;
|
|
96
|
-
const edgeColor = e.edge > 0 ? utils_js_1.c.green : utils_js_1.c.red;
|
|
97
|
-
console.log(` ${venue} ${(0, utils_js_1.rpad)(`${e.price}¢`, 5)} ${edgeColor}edge ${e.edge > 0 ? '+' : ''}${e.edge}¢${utils_js_1.c.reset} ${(0, utils_js_1.trunc)(e.title, 40)} ${utils_js_1.c.dim}${e.thesisSlug || ''}${utils_js_1.c.reset}`);
|
|
98
|
-
}
|
|
99
|
-
console.log();
|
|
100
|
-
}
|
|
101
|
-
// ── Recent evaluations ─────────────────────────────────────────────────
|
|
102
|
-
const signals = data.signals || [];
|
|
103
|
-
if (signals.length > 0) {
|
|
104
|
-
console.log(`${utils_js_1.c.bold}Recent Evaluations${utils_js_1.c.reset}`);
|
|
105
|
-
for (const s of signals.slice(0, 5)) {
|
|
106
|
-
const d = s.confidenceDelta;
|
|
107
|
-
const dStr = d > 0 ? `${utils_js_1.c.green}+${d}%${utils_js_1.c.reset}` : d < 0 ? `${utils_js_1.c.red}${d}%${utils_js_1.c.reset}` : `${utils_js_1.c.dim}0%${utils_js_1.c.reset}`;
|
|
108
|
-
const ago = timeAgo(s.evaluatedAt);
|
|
109
|
-
console.log(` ${(0, utils_js_1.rpad)(ago, 5)} ${(0, utils_js_1.rpad)(s.thesisSlug || '?', 18)} ${(0, utils_js_1.rpad)(dStr, 14)} ${(0, utils_js_1.trunc)(s.summary, 50)}`);
|
|
110
|
-
}
|
|
111
|
-
console.log();
|
|
112
|
-
}
|
|
113
|
-
// ── Actions ────────────────────────────────────────────────────────────
|
|
114
|
-
console.log(`${utils_js_1.c.dim}${'─'.repeat(60)}${utils_js_1.c.reset}`);
|
|
115
|
-
console.log(` ${utils_js_1.c.cyan}sf query${utils_js_1.c.reset} "topic" ${utils_js_1.c.dim}ask anything${utils_js_1.c.reset}`);
|
|
116
|
-
console.log(` ${utils_js_1.c.cyan}sf scan${utils_js_1.c.reset} "keywords" ${utils_js_1.c.dim}search markets${utils_js_1.c.reset}`);
|
|
117
|
-
console.log(` ${utils_js_1.c.cyan}sf explore${utils_js_1.c.reset} ${utils_js_1.c.dim}public theses${utils_js_1.c.reset}`);
|
|
118
|
-
console.log(` ${utils_js_1.c.cyan}sf create${utils_js_1.c.reset} "thesis" ${utils_js_1.c.dim}start monitoring${utils_js_1.c.reset}`);
|
|
119
|
-
console.log();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
// ── Mode 2: Thesis-specific context (requires API key) ────────────────────
|
|
123
|
-
const client = new client_js_1.SFClient(opts.apiKey, opts.apiUrl);
|
|
124
|
-
const ctx = await client.getContext(id);
|
|
125
|
-
if (opts.json) {
|
|
126
|
-
console.log(JSON.stringify(ctx, null, 2));
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
console.log(`\n${utils_js_1.c.bold}Thesis:${utils_js_1.c.reset} ${ctx.thesis || ctx.rawThesis || '(unknown)'}`);
|
|
130
|
-
const confStr = ctx.confidence !== null && ctx.confidence !== undefined ? (0, utils_js_1.pct)(ctx.confidence) : '-';
|
|
131
|
-
const confDelta = ctx.lastEvaluation?.confidenceDelta;
|
|
132
|
-
const deltaStr = confDelta ? ` (${(0, utils_js_1.delta)(confDelta)} since last eval)` : '';
|
|
133
|
-
console.log(`${utils_js_1.c.bold}Confidence:${utils_js_1.c.reset} ${confStr}${deltaStr}`);
|
|
134
|
-
console.log(`${utils_js_1.c.bold}Status:${utils_js_1.c.reset} ${ctx.status}`);
|
|
135
|
-
console.log(`${utils_js_1.c.bold}Last Updated:${utils_js_1.c.reset} ${(0, utils_js_1.shortDate)(ctx.updatedAt)}`);
|
|
136
|
-
const nodes = ctx.causalTree?.nodes;
|
|
137
|
-
if (nodes && nodes.length > 0) {
|
|
138
|
-
(0, utils_js_1.header)('Causal Tree');
|
|
139
|
-
for (const node of nodes) {
|
|
140
|
-
const indent = ' '.repeat((node.depth || 0) + 1);
|
|
141
|
-
const prob = node.probability !== undefined ? (0, utils_js_1.pct)(node.probability) : '-';
|
|
142
|
-
const label = node.label || node.id;
|
|
143
|
-
console.log(`${indent}${utils_js_1.c.cyan}${node.id}${utils_js_1.c.reset} ${(0, utils_js_1.pad)(label, 40)} ${(0, utils_js_1.rpad)(prob, 5)}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
let positions = null;
|
|
147
|
-
if ((0, kalshi_js_1.isKalshiConfigured)()) {
|
|
148
|
-
try {
|
|
149
|
-
positions = await (0, kalshi_js_1.getPositions)();
|
|
150
|
-
}
|
|
151
|
-
catch { /* optional */ }
|
|
152
|
-
}
|
|
153
|
-
const posMap = new Map();
|
|
154
|
-
if (positions) {
|
|
155
|
-
for (const p of positions)
|
|
156
|
-
posMap.set(p.ticker, p);
|
|
157
|
-
}
|
|
158
|
-
const edges = ctx.edges;
|
|
159
|
-
if (edges && edges.length > 0) {
|
|
160
|
-
(0, utils_js_1.header)('Top Edges');
|
|
161
|
-
const sorted = [...edges].sort((a, b) => Math.abs(b.edge ?? b.edgeSize ?? 0) - Math.abs(a.edge ?? a.edgeSize ?? 0));
|
|
162
|
-
for (const edge of sorted.slice(0, 10)) {
|
|
163
|
-
const edgeSize = edge.edge ?? edge.edgeSize ?? 0;
|
|
164
|
-
const edgeColor = edgeSize > 10 ? utils_js_1.c.green : edgeSize > 0 ? utils_js_1.c.yellow : utils_js_1.c.red;
|
|
165
|
-
const mktPrice = edge.marketPrice ?? edge.currentPrice ?? 0;
|
|
166
|
-
const title = edge.market || edge.marketTitle || edge.marketId || '?';
|
|
167
|
-
const ob = edge.orderbook;
|
|
168
|
-
const obStr = ob ? ` ${utils_js_1.c.dim}spread ${ob.spread}¢ ${ob.liquidityScore}${utils_js_1.c.reset}` : '';
|
|
169
|
-
const pos = posMap.get(edge.marketId);
|
|
170
|
-
let posStr = '';
|
|
171
|
-
if (pos) {
|
|
172
|
-
const pnl = pos.unrealized_pnl || 0;
|
|
173
|
-
const pnlColor = pnl > 0 ? utils_js_1.c.green : pnl < 0 ? utils_js_1.c.red : utils_js_1.c.dim;
|
|
174
|
-
const pnlFmt = pnl >= 0 ? `+$${(pnl / 100).toFixed(0)}` : `-$${(Math.abs(pnl) / 100).toFixed(0)}`;
|
|
175
|
-
posStr = ` ${utils_js_1.c.cyan}← ${pos.quantity}@${pos.average_price_paid}¢ ${pnlColor}${pnlFmt}${utils_js_1.c.reset}`;
|
|
176
|
-
}
|
|
177
|
-
console.log(` ${(0, utils_js_1.pad)(title, 35)} ${(0, utils_js_1.rpad)(mktPrice.toFixed(0) + '¢', 5)}` +
|
|
178
|
-
` ${edgeColor}edge ${edgeSize > 0 ? '+' : ''}${edgeSize.toFixed(1)}${utils_js_1.c.reset}` +
|
|
179
|
-
` ${utils_js_1.c.dim}${edge.venue || ''}${utils_js_1.c.reset}` + obStr + posStr);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (ctx.lastEvaluation?.summary) {
|
|
183
|
-
(0, utils_js_1.header)('Last Evaluation');
|
|
184
|
-
console.log(` ${utils_js_1.c.dim}${(0, utils_js_1.shortDate)(ctx.lastEvaluation.evaluatedAt)} | model: ${ctx.lastEvaluation.model || ''}${utils_js_1.c.reset}`);
|
|
185
|
-
console.log(` ${ctx.lastEvaluation.summary}`);
|
|
186
|
-
if (ctx.lastEvaluation.positionRecommendations?.length > 0) {
|
|
187
|
-
console.log(`\n ${utils_js_1.c.bold}Position Recommendations:${utils_js_1.c.reset}`);
|
|
188
|
-
for (const pr of ctx.lastEvaluation.positionRecommendations) {
|
|
189
|
-
const recColor = pr.recommendation === 'hold' ? utils_js_1.c.dim : pr.recommendation === 'close' ? utils_js_1.c.red : utils_js_1.c.yellow;
|
|
190
|
-
console.log(` [${(pr.positionId || '').slice(0, 8)}] ${recColor}${pr.recommendation}${utils_js_1.c.reset} — ${pr.reason}`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (ctx.edgeMeta?.lastRescanAt) {
|
|
195
|
-
console.log(`\n${utils_js_1.c.dim}Last rescan: ${(0, utils_js_1.shortDate)(ctx.edgeMeta.lastRescanAt)}${utils_js_1.c.reset}`);
|
|
196
|
-
}
|
|
197
|
-
console.log('');
|
|
198
|
-
}
|
|
199
|
-
function timeAgo(iso) {
|
|
200
|
-
const ms = Date.now() - new Date(iso).getTime();
|
|
201
|
-
const min = Math.round(ms / 60000);
|
|
202
|
-
if (min < 60)
|
|
203
|
-
return `${min}m`;
|
|
204
|
-
const hr = Math.round(min / 60);
|
|
205
|
-
if (hr < 24)
|
|
206
|
-
return `${hr}h`;
|
|
207
|
-
return `${Math.round(hr / 24)}d`;
|
|
208
|
-
}
|