> ## Documentation Index
> Fetch the complete documentation index at: https://docs.simplefunctions.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Discover and inspect markets

> Use the SDK and Agent SDK for read-only prediction-market research, contract inspection, orderbook depth, and candle screening.

This cookbook uses the SDK:

```bash theme={null}
npm install @spfunctions/sdk@1.0.1
```

## Search markets

```ts theme={null}
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:

```text theme={null}
markets.search -> GET /api/public/scan -> sf scan "query" --json -> sf.markets.search()
```

## Discovery feed

```ts theme={null}
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

```ts theme={null}
const dossier = await sf.markets.get("KXRECESSION-26DEC31", {
  depth: true,
})
```

Contract mapping:

```text theme={null}
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

```ts theme={null}
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:

```text theme={null}
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

```ts theme={null}
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

```bash theme={null}
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.
