Dflow kalshi portfolio

From x402agent/solana-clawd · View interactive version

Dflow kalshi portfolio is an AI agent skill from the GitHub repository x402agent/solana-clawd. View what a wallet holds on DFlow's Kalshi prediction markets — current positions, unrealized mark-to-market, realized P&L, activity history, and redeemable winners. Use when the user asks "what are my positions?", "what do I own?", "am I up or down?", "what's my fill history?", "what can I redeem?"

How to use this skill

Skill file

DFlow Kalshi Portfolio

Read-only views on a wallet's Kalshi activity — holdings, mark-to-market valuations, realized P&L, fill history, redeemable positions.

Prerequisites

Surface

There is no /positions endpoint. A portfolio is assembled by hand from onchain wallet balances + metadata joins. Two ways to do it:

Quick path: `dflow positions` (CLI)

Output (single JSON envelope, same on every wallet):

{
  "ok": true,
  "data": {
    "wallet": "<pubkey>",
    "positions": [
      { "type": "spot",    "mint": "...", "symbol": "USDC", "amount": "1326161", "uiAmount": 1.326161, "decimals": 6 },
      { "type": "outcome", "mint": "...", "symbol": "DFlowYU0192", "amount": "2000000", "uiAmount": 2.0, "decimals": 6,
        "side": "yes", "market": { "title": "...", "status": "active" } }
    ]
  }
}

Full path: build-your-own (API)

The canonical pipeline, from the DFlow recipe CODE0:

  1. Read wallet balances via Solana RPC — getParsedTokenAccountsByOwner(wallet, { programId: TOKEN_2022_PROGRAM_ID }). Outcome tokens are Token-2022. (For stablecoin balances, also query the classic SPL token program.)
  2. POST /api/v1/filter_outcome_mints — send the wallet's mint list, get back just the PM outcome mints.
  3. POST /api/v1/markets/batch — fetch full market metadata for those outcome mints (title, status, closeTime, yesBid / yesAsk / noBid / noAsk, redemptionStatus, accounts.yesMint / noMint).
  4. Join — map each holding to its market; determine YES vs NO by matching the held mint against accounts.yesMint / accounts.noMint.

Field-level detail (response envelopes, pagination) → docs MCP.

Views on top of the pipeline

Current positions

Output of the pipeline above. Optionally attach current mark price per position (yesBid for YES holdings, noBid for NO holdings — see mark-to-market below).

Unrealized mark-to-market

Value each outcome holding at the bid on its side (what you could sell it for), not the ask:

Sum across positions for a wallet-level unrealized value. Subtract cost basis (below) for unrealized P&L.

Realized activity and P&L

GET /api/v1/onchain-trades?wallet=<pubkey>&sortBy=createdAt&sortOrder=desc&limit=N — DFlow-indexed view of the wallet's onchain fills.

Redeemable sweep

A holding is redeemable iff all three:

To redeem, hand off to dflow-kalshi-trading (redemption is a sell of the winning side back to the settlement mint).

Pending order check

If the app submitted the order itself, persist the orderAddress returned at submission and poll GET /order-status?orderAddress=<addr> until terminal. There's no list-by-wallet endpoint. Most fills terminate well under the CLI's 120s poll budget, so this is rarely a user-facing concern — but outside the maintenance window, don't assume a specific fill time.

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

View shape — infer if unambiguous, confirm if not:

  1. Which view — holdings / mark-to-market / realized P&L / activity / redeemable.
  2. Wallet pubkey — API only (CLI uses the active vault wallet).

Infra — always ask, never infer (HTTP/RPC pipeline only; the dflow positions quick path needs neither):

  1. DFlow API key (only when the script is hitting the Metadata API directly — markets/batch, onchain-trades, etc.). The CLI quick path (dflow positions) doesn't need one — it uses the CLI's stored config. For the HTTP pipeline, ask with a clean, neutral question: "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 Metadata + Trade APIs. Yes → prod host https://prediction-markets-api.dflow.net with x-api-key. No → dev host https://dev-prediction-markets-api.dflow.net, rate-limited. Pointer: https://pond.dflow.net/build/api-key. When you generate a script, log the resolved host + key-presence at startup.
  2. RPC URL — yes, ask here, unlike spot/PM trading or market-data. The HTTP pipeline reads token accounts directly via RPC; there's no wallet in the loop to do it for you. Recommend Helius. CLI users on the dflow positions quick path don't need one — dflow setup already configured it.

Do NOT ask about:

Gotchas (the docs MCP won't volunteer these)

When something doesn't fit

For anything not covered above — full response envelopes for filter_outcome_mints / markets/batch / onchain-trades, pagination params, Proof state in the picture, edge cases in redemptionStatus transitions, order-status terminal states — query the docs MCP (search_d_flow, query_docs_filesystem_d_flow). Don't guess.

For runnable reference code, point at CODE0 (and its Cookbook Repo link).

Sibling skills

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.