Skip to main content
This cookbook uses the SDK:
npm install @spfunctions/sdk@1.0.1

Search markets

import { SimpleFunctions } from "@spfunctions/sdk"

const sf = new SimpleFunctions({ baseUrl: process.env.SF_API_URL })

const results = await sf.markets.search({
  query: "Fed CPI",
  limit: 10,
  venue: "all",
})

console.log(results.markets?.map(market => ({
  ticker: market.ticker,
  venue: market.venue,
  price: market.price,
  title: market.title,
})))
Contract mapping:
markets.search -> GET /api/public/scan -> sf scan "query" --json -> sf.markets.search()

Discovery feed

const discovery = await sf.markets.discover({ limit: 5 })
markets.discover maps to the verified HTTP-backed discovery slice at /api/public/ideas. The CLI command sf discover --quality --json is broader because it also aggregates local CLI sources.

Inspect one market

const dossier = await sf.markets.get("KXRECESSION-26DEC31", {
  depth: true,
})
Contract mapping:
market.inspect -> GET /api/agent/inspect/{ticker}?format=json -> sf inspect <ticker> --json -> sf.markets.get(ticker)
depth: true asks the server to include orderbook levels where available. Contract-info reads run through the configured SimpleFunctions API base URL. By default that is https://simplefunctions.dev; the server then uses DB/cache rows, Kalshi orderbook proxy or credentials, or Polymarket CLOB depending on venue and deployment config.

Candles and K-lines

const chart = await sf.markets.candles("KXBTCD-26MAY1917-T76499.99", {
  venue: "kalshi",
  timeframe: "1m",
  limit: 500,
})

const screen = await sf.markets.screenCandles({
  venue: "kalshi",
  tickers: ["KXBTCD-26MAY1917-T76499.99", "KXWTI-26MAY1914-T104.99"],
  timeframes: ["1m", "5m", "15m", "1h"],
  minAbsReturnPct: 2,
  minRangePct: 3,
  concurrency: 4,
})
Contract mapping:
market.candles -> GET /api/public/market/{ticker}/candles?venue=kalshi|polymarket&timeframe=1m&limit=500 -> sf.markets.candles(ticker)
screenCandles() is an SDK helper. It calls market.candles for each ticker/timeframe and ranks movement, range, realized volatility, volume, breakout state, and trend. It is watchlist-first; it does not crawl every venue market from the client.

History

const history = await sf.markets.history("KXRECESSION-26DEC31")
The current endpoint returns the available cached 7-day indicator/regime history. It is read-only.

Direct Agent tool mode

sf agent --tool markets.search --stream-json --input '{"query":"Fed CPI","limit":5}'
sf agent --tool market.inspect --ndjson --input '{"ticker":"KXRECESSION-26DEC31"}'
sf agent --tool market.candles --ndjson --input '{"ticker":"KXBTCD-26MAY1917-T76499.99","venue":"kalshi","timeframe":"5m","limit":200}'
The trace stores a compact summary, not the full market payload.