Dflow kalshi market scanner

From x402agent/solana-clawd · View interactive version

Dflow kalshi market scanner is an AI agent skill from the GitHub repository x402agent/solana-clawd. Find Kalshi prediction markets on DFlow that match a criterion — arbitrage (YES+NO<$1), cheap long-shots, near-certain short-dated plays, biggest movers, widest spreads, highest volume, closing soonest, and series/event-level scans. Use when the user asks "where's the free money?", "any mispriced ma

How to use this skill

Skill file

DFlow Kalshi Market Scanner

Find Kalshi markets that match a criterion. This skill is a set of named scans (filter-and-rank recipes) over the DFlow Metadata API.

Prerequisites

Surface

All scans here run against the Metadata API (https://pond.dflow.net/build/metadata-api) — REST for point-in-time queries, WebSockets for continuous streams. You can call both from anywhere: a quick curl from the command line, a Node/Python script, a cron job, a backend service, or a Next.js route proxying a browser UI.

If the user says "run this from my terminal", don't reach for the dflow CLI — it has no discovery subcommands. Write a short HTTP/WS script that hits the Metadata API instead.

The scanner skeleton

Every scan is the same four steps. Build around this pattern — don't reinvent it per scan:

  1. Enumerate the universe — GET /api/v1/markets (flat) or GET /api/v1/events?withNestedMarkets=true (grouped). Filter to status=active. Page through until done (see the pagination gotcha for the { markets, cursor } shape). Pass isInitialized=true only if the user wants markets tradable on DFlow right now (see Gotchas).
  2. Grab the per-market signal. For top-of-book scans the signal is already on the market object — yesBid / yesAsk / noBid / noAsk (4-decimal probability strings), volume24hFp / volumeFp / openInterestFp (dollar-equivalent strings), closeTime (unix) — no orderbook call needed. For momentum use candlesticks or the prices / trades WebSocket channels. For ladder depth use /api/v1/orderbook/by-mint/{mint}. For recent prints use /api/v1/trades or the trades channel.
  3. Compute the metric.
  4. Filter and rank. Return the top-N (default 10, ask if the user wants more).

Polling vs streaming

Pick the mode that fits the intent:

Exact endpoint params, channel payloads, and pagination → docs MCP.

Scans to offer

Each scan = a user question + a metric. Plug the metric into the skeleton.

Prefer rank-based filters over fixed numeric thresholds. Kalshi volume alone spans 5+ orders of magnitude across active markets — any hardcoded dollar floor is either a pass-through (too low) or excludes everything (too high), and it drifts as the platform grows. When a scan needs "busy" or "cheap" or "moved a lot," compute the cutoff from the scan result (percentile of the current universe), not from a number baked in here.

Only use a fixed number when it's semantic — e.g. YES + NO < $1.00 for arbitrage (that's the no-arb invariant, not a tunable), or status=active (a field value, not a threshold). If the user supplies a specific number, use theirs. If the user's phrasing implies a threshold you don't have ("serious volume", "big movers"), ask them — don't guess.

1. Arbitrage — `YES + NO < $1`

"Find markets where I can buy both sides for under a dollar."

2. Long-shot YES

"Cheap YES that's actually trading."

3. Near-certain short-dated YES

"YES above 97¢ closing soon — grind the theta."

4. Momentum

"What moved in the last hour?" or "Alert me when something moves"

5. Widest bid-ask spreads

"Inefficient markets — market-make or avoid."

6. Highest volume

"Where's the action?"

7. Closing soonest

"Theta clock."

8. Event- and series-level scans

"Cheapest YES across all outcomes in this event", "do mutually-exclusive buckets sum > 1?"

Point lookups (N=1)

When the user already has one market in mind, skip the skeleton:

The plural forms (/markets, /events) are the list endpoints and take ?cursor=&limit= for pagination. The singular forms are point lookups by id. Mixing them up gets you 404s.

What to ASK the user (and what NOT to ask)

Query shape — infer if unambiguous, confirm if not:

  1. Which scan (or a plain-English intent you can map to one).
  2. Thresholds the user supplies — use theirs verbatim. If they say "> 5%" or "under 2¢" or "this week", use those numbers. Otherwise, use the rank-based defaults from each scan above (top quartile by volume, etc.); do not propose a fixed numeric threshold of your own. If the user's phrasing implies a threshold the scan doesn't define ("big movers", "serious volume"), ask them — don't guess a number.
  3. Polling vs streaming — if the intent sounds like "show me now" go REST; if it sounds like "alert me / react when" go WebSocket.
  4. Top-N (default 10).

Infra — always ask, never infer:

  1. DFlow API key — for the discovery / HTTP portion of the script only; CLI shell-outs authenticate themselves (see the "two auth paths" gotcha below). Ask with a clean, neutral question: "For the scanner / discovery side, do you have a DFlow API key?" Don't presuppose where the key lives — phrasings like "do you have it in env?" or "is DFLOW_API_KEY set?" nudge the user toward env-var defaults they didn't ask for. Surface the choice; don't silently fall back to env or to dev. It's one DFlow key everywhere — same x-api-key unlocks the Trade API and the Metadata API, REST and WebSocket. If yes → prod hosts (https://prediction-markets-api.dflow.net REST, wss://prediction-markets-api.dflow.net/api/v1/ws WS) with x-api-key on every request (REST and the WS upgrade). If no → dev hosts (https://dev-prediction-markets-api.dflow.net, wss://dev-prediction-markets-api.dflow.net/api/v1/ws), rate-limited; point them at https://pond.dflow.net/build/api-key for a prod key. When you generate a script, log the resolved host + key-presence at startup (Using prod Metadata API / Using dev Metadata API — rate-limited) so the user can see which rails they're on without spelunking through code.

Do NOT ask about:

Gotchas (the docs MCP won't volunteer these)

When a user says "the CLI is already set up," that's the execution leg covered — not the discovery leg. Frame the API-key ask as "for the scanner/discovery side, do you have a DFlow API key?" — not as "the CLI isn't enough, you need another key." The two are independent: one DFlow key, two plumbing sites.

When something doesn't fit

For anything not covered above — full parameter lists, pagination tokens, response schemas, WS reconnection semantics, rare filters (sports, tags, categories, series search), candlestick intervals — query the docs MCP (search_d_flow, query_docs_filesystem_d_flow). Don't guess.

Sibling skills

When the user pivots from discovery to action, hand off:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.