import { writeFile } from "node:fs/promises"
import { SimpleFunctions } from "@spfunctions/sdk"
const sf = new SimpleFunctions({
baseUrl: "https://simplefunctions.dev",
apiKey: process.env.SF_API_KEY,
})
const world = await sf.world.get()
const screen = await sf.intelligence.screen({
venue: "kalshi",
volMin: 100,
sort: "volume",
order: "desc",
limit: 12,
nextActions: false,
})
const inspected = []
for (const market of screen.markets.slice(0, 5)) {
inspected.push(await sf.markets.get(market.ticker, { nextActions: false }))
}
const ranked = inspected
.map(market => ({
ticker: market.ticker,
title: market.title,
price: market.price,
bestBid: market.bestBid,
bestAsk: market.bestAsk,
spread: market.spread,
volume24h: market.volume24h,
closeTime: market.closeTime,
score:
Math.log10(1 + Number(market.volume24h ?? 0)) * 20 -
Number(market.spread ?? 10) * 4,
}))
.sort((a, b) => b.score - a.score)
const packet = {
generatedAt: new Date().toISOString(),
worldAsOf: world.asOf,
regime: world.regime?.label,
candidates: ranked.slice(0, 5),
}
await writeFile("research-packet.json", JSON.stringify(packet, null, 2))
console.log(JSON.stringify(packet, null, 2))