dflow-kalshi-portfolio

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

DFlow Kalshi Portfolio

DFlow Kalshi 投资组合

Read-only views on a wallet's Kalshi activity — holdings, mark-to-market valuations, realized P&L, fill history, redeemable positions.
钱包Kalshi活动的只读视图——包括持仓、按市值计价估值、已实现盈亏、成交历史、可赎回头寸。

Prerequisites

前置条件

  • DFlow docs MCP (
    https://pond.dflow.net/mcp
    ) — install per the repo README. This skill is the recipe; the MCP is the reference. Look up exact response shapes, pagination, and batch-endpoint payloads via
    search_d_flow
    /
    query_docs_filesystem_d_flow
    — don't guess.
  • dflow
    CLI
    (optional, for the fast-path holdings view) — install per the repo README.
  • DFlow docs MCP
    https://pond.dflow.net/mcp
    )——请按照仓库README进行安装。本技能是操作指南,MCP是参考依据。请通过
    search_d_flow
    /
    query_docs_filesystem_d_flow
    查询准确的响应格式、分页参数和批量端点负载——请勿自行猜测。
  • dflow
    CLI
    (可选,用于快速查看持仓)——请按照仓库README进行安装。

Surface

使用方式

There is no
/positions
endpoint.
A portfolio is assembled by hand from onchain wallet balances + metadata joins. Two ways to do it:
  • CLI —
    dflow positions
    — one command, dumps spot + outcome tokens for the active vault wallet with balances and market labels. Covers "what do I hold right now?" on the CLI, and the stablecoin
    uiAmount
    already reads as USD. Doesn't carry mark prices for outcome tokens,
    redemptionStatus
    , or fill history, so outcome-token valuation, redemption checks, and P&L still need the API pipeline. Active-vault only.
  • API — build-your-own pipeline — needed whenever the user wants any of: mark-to-market, P&L, activity history, redemption eligibility, or to inspect a wallet that isn't the CLI's active vault.
不存在
/positions
端点
。投资组合需要通过链上钱包余额+元数据关联手动组装。有两种实现方式:
  • CLI——
    dflow positions
    ——一条命令即可导出活跃金库钱包的现货+结果代币,包含余额和市场标签。适用于在CLI上快速查看“我当前持有什么?”,稳定币的
    uiAmount
    已按USD显示。但该命令不提供结果代币的标记价格、
    redemptionStatus
    或成交历史,因此结果代币估值、赎回检查和盈亏计算仍需通过API流程实现。仅支持活跃金库钱包。
  • API——自定义构建流程——当用户需要以下任意功能时必须使用:按市值计价、盈亏计算、活动历史、赎回资格检查,或者查看非CLI活跃金库的钱包。

Quick path:
dflow positions
(CLI)

快速路径:
dflow positions
(CLI)

Output (single JSON envelope, same on every wallet):
json
{
  "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" } }
    ]
  }
}
  • type: "spot"
    — SOL, USDC, CASH, and anything else in the wallet.
  • type: "outcome"
    — Kalshi outcome token; additionally carries
    side
    (
    "yes"
    |
    "no"
    ) and a minimal
    market
    (
    title
    ,
    status
    ).
  • No flag to inspect another wallet. For that, use the API pipeline.
输出(单个JSON包,所有钱包格式一致):
json
{
  "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" } }
    ]
  }
}
  • type: "spot"
    ——钱包中的SOL、USDC、CASH及其他代币。
  • type: "outcome"
    ——Kalshi结果代币;额外包含
    side
    "yes"
    |
    "no"
    )和极简
    market
    信息(
    title
    status
    )。
  • 无查看其他钱包的参数。如需查看其他钱包,请使用API流程。

Full path: build-your-own (API)

完整路径:自定义构建(API)

The canonical pipeline, from the DFlow recipe
/build/recipes/prediction-markets/track-positions
:
  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.
  1. 通过Solana RPC读取钱包余额——调用
    getParsedTokenAccountsByOwner(wallet, { programId: TOKEN_2022_PROGRAM_ID })
    。结果代币为Token-2022标准。(稳定币余额需同时查询经典SPL代币程序。)
  2. POST /api/v1/filter_outcome_mints
    ——发送钱包的代币铸造列表,仅返回预测市场的结果代币铸造地址。
  3. POST /api/v1/markets/batch
    ——获取这些结果代币对应的完整市场元数据(标题、状态、关闭时间、
    yesBid
    /
    yesAsk
    /
    noBid
    /
    noAsk
    redemptionStatus
    accounts.yesMint
    /
    accounts.noMint
    )。
  4. 关联数据——将每个持仓映射到对应市场;通过匹配持仓铸造地址与
    accounts.yesMint
    /
    accounts.noMint
    判断是YES还是NO头寸。
字段级细节(响应包、分页)请参考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).
上述流程的输出结果。可选择性地为每个头寸附加当前标记价格(YES持仓用
yesBid
,NO持仓用
noBid
——见下文按市值计价部分)。

Unrealized mark-to-market

未实现按市值计价收益

Value each outcome holding at the bid on its side (what you could sell it for), not the ask:
  • Long YES →
    uiAmount * parseFloat(yesBid)
  • Long NO →
    uiAmount * parseFloat(noBid)
Sum across positions for a wallet-level unrealized value. Subtract cost basis (below) for unrealized P&L.
按头寸对应的买方报价(即卖出可得价格)计算每个结果持仓的价值,而非卖方报价:
  • 持有YES头寸 →
    uiAmount * parseFloat(yesBid)
  • 持有NO头寸 →
    uiAmount * parseFloat(noBid)
汇总所有头寸得到钱包级别的未实现价值。减去成本基准(见下文)即为未实现盈亏。

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.
  • Activity feed: each row has
    createdAt
    ,
    marketTicker
    ,
    side
    ,
    inputAmount
    ,
    outputAmount
    ,
    transactionSignature
    .
  • Cost basis per market: track net settlement-mint flow per outcome mint (settlement-in on buys minus settlement-out on sells).
  • Fees: sum
    feeAmount
    across fills in the settlement mint.
调用
GET /api/v1/onchain-trades?wallet=<pubkey>&sortBy=createdAt&sortOrder=desc&limit=N
——DFlow索引的钱包链上成交记录视图。
  • 活动流:每一行包含
    createdAt
    marketTicker
    side
    inputAmount
    outputAmount
    transactionSignature
  • 单市场成本基准:跟踪每个结果代币的结算代币净流量(买入时的结算代币流入减去卖出时的结算代币流出)。
  • 手续费:汇总所有成交记录中的
    feeAmount
    (结算代币计价)。

Redeemable sweep

可赎回头寸扫描

A holding is redeemable iff all three:
  • market
    status
    is
    determined
    or
    finalized
    ,
  • market
    redemptionStatus
    is
    "open"
    ,
  • the held outcome mint is the winning side (from market
    result
    ).
To redeem, hand off to
dflow-kalshi-trading
(redemption is a sell of the winning side back to the settlement mint).
持仓可赎回需同时满足以下三个条件
  • 市场
    status
    determined
    finalized
  • 市场
    redemptionStatus
    "open"
  • 持有的结果代币属于获胜一方(来自市场
    result
    )。
如需赎回,请转交至
dflow-kalshi-trading
(赎回操作是将获胜方代币卖回给结算代币铸造方)。

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.
如果应用自行提交了订单,请保存提交时返回的
orderAddress
并轮询
GET /order-status?orderAddress=<addr>
直到订单进入终态。目前没有按钱包列出订单的端点。大多数成交会在CLI的120秒轮询时限内完成,因此这很少是用户关注的问题——但在维护窗口外,不要假设特定的成交时间。

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 URLyes, 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:
  • Settlement mint, slippage, fees, signing — read-only skill. If the user pivots to acting on a position, hand off to
    dflow-kalshi-trading
    .
视图形式——明确时自行推断,不明确时确认:
  1. 需要哪种视图——持仓/按市值计价/已实现盈亏/活动历史/可赎回头寸。
  2. 钱包公钥——仅API流程需要(CLI使用活跃金库钱包)。
基础设施——必须询问,绝不自行推断(仅HTTP/RPC流程需要;
dflow positions
快速路径无需):
  1. DFlow API密钥(仅当脚本直接调用元数据API时需要——如
    markets/batch
    onchain-trades
    等)。
    dflow positions
    快速路径不需要——它使用CLI存储的配置。**对于HTTP流程,请用简洁中立的问题询问:“您是否拥有DFlow API密钥?”**不要预设密钥的存储位置——类似“您是否将其存在环境变量中?”或“
    DFLOW_API_KEY
    是否已设置?”的表述会引导用户使用他们未要求的环境变量默认值。请给出选择,不要静默回退到环境变量或开发环境。所有场景使用同一个DFlow密钥——相同的
    x-api-key
    可解锁元数据API和交易API。如果有密钥 → 使用生产环境地址
    https://prediction-markets-api.dflow.net
    并携带
    x-api-key
    。如果没有 → 使用开发环境地址
    https://dev-prediction-markets-api.dflow.net
    ,有速率限制。参考链接:
    https://pond.dflow.net/build/api-key
    当生成脚本时,请在启动时记录解析后的地址和密钥状态。
  2. RPC URL——此处必须询问,不同于现货/预测市场交易或市场数据流程。HTTP流程需直接通过RPC读取代币账户;没有钱包代为执行此操作。推荐使用Helius。使用
    dflow positions
    快速路径的CLI用户不需要——
    dflow setup
    已配置好RPC。
无需询问的内容:
  • 结算代币、滑点、手续费、签名——本技能为只读模式。如果用户转向对头寸进行操作,请转交至
    dflow-kalshi-trading

Gotchas (the docs MCP won't volunteer these)

注意事项(docs MCP不会主动提及)

  • No
    /positions
    endpoint.
    Portfolio = wallet balances + metadata joins. Don't hunt the API for a shortcut.
  • Token-2022 program for outcome tokens.
    TOKEN_2022_PROGRAM_ID
    , not the classic token program. Query the classic program separately for USDC/SOL/CASH.
  • Mark-to-market = bid, not ask. Long YES →
    yesBid
    . Long NO →
    noBid
    . Marking on the ask overstates the portfolio.
  • Two POST endpoints.
    filter_outcome_mints
    and
    markets/batch
    both take a POST body with an address list. Easy to default to GET and fail.
  • Stablecoins aren't outcome mints.
    filter_outcome_mints
    strips them out (they're settlement, not positions). Track USDC / CASH balances separately from the PM view.
  • Redemption readiness is three ANDed conditions, not just "market closed." Surface a redeemable list only when status +
    redemptionStatus
    + winning side all line up.
  • Balance lag after fill. A fill that just landed onchain may not show up immediately on a non-indexed RPC — the token account update propagates after the transaction finalizes. Debounce rapid refreshes, and if the user expected a balance change and doesn't see it, retry before assuming failure.
  • dflow positions
    is active-vault only.
    No
    --wallet
    flag; switching wallets means
    dflow setup
    or the API pipeline.
  • dflow positions
    returns balances, not mark prices.
    You get
    amount
    /
    uiAmount
    /
    decimals
    plus
    side
    +
    market.title
    +
    market.status
    on outcome tokens. That already gets you close to dollar value for USDC and CASH (their
    uiAmount
    ≈ USD modulo depeg), but outcome tokens need
    yesBid
    /
    noBid
    from
    markets/batch
    to mark, and other spot tokens (SOL, etc.) need an outside spot price. No
    redemptionStatus
    and no cost basis in the output either — pair with
    markets/batch
    for redemption eligibility,
    /onchain-trades
    for P&L.
  • Closed outcome token accounts. After a full sell or redeem, the token account may be closed (rent reclaimed) and will no longer show up on the wallet. That's expected — check onchain-trades history if you need the record.
  • Same market, different rail = separate position. Every Kalshi market on DFlow has a USDC rail and a CASH rail, each with its own
    yesMint
    /
    noMint
    . A wallet can hold YES on both rails of the same market — those are two rows in the portfolio, two redemption flows, and their mark-to-market sums independently. Rare in practice (most users stick to one rail) but worth handling if it shows up.
  • Two surfaces, two auth paths.
    dflow positions
    shells out through the CLI and uses its stored config (key, wallet, RPC) — the script plumbs nothing for that call. The build-your-own HTTP pipeline (
    markets/batch
    ,
    onchain-trades
    , RPC
    getParsedTokenAccountsByOwner
    ) is plain HTTP/RPC and needs the DFlow API key + RPC URL plumbed in explicitly. They're independent: the CLI's stored key isn't reachable from a sibling HTTP client. Only ask about API key + RPC for the HTTP pipeline.
  • 不存在
    /positions
    端点
    。投资组合=钱包余额+元数据关联。不要在API中寻找捷径。
  • 结果代币使用Token-2022程序。使用
    TOKEN_2022_PROGRAM_ID
    ,而非经典代币程序。需单独查询经典程序获取USDC/SOL/CASH余额。
  • 按市值计价使用买方报价,而非卖方报价。持有YES头寸→
    yesBid
    。持有NO头寸→
    noBid
    。使用卖方报价会高估投资组合价值。
  • 两个POST端点
    filter_outcome_mints
    markets/batch
    均接受包含地址列表的POST请求体。请勿默认使用GET请求,否则会失败。
  • 稳定币不是结果代币
    filter_outcome_mints
    会过滤掉稳定币(它们是结算代币,而非头寸)。需将USDC/CASH余额与预测市场视图分开跟踪。
  • 赎回就绪需满足三个同时成立的条件,而非仅“市场关闭”。仅当状态+
    redemptionStatus
    +获胜方全部满足时,才展示可赎回列表。
  • 成交后余额延迟。刚上链的成交可能不会立即在非索引RPC上显示——代币账户更新会在交易最终确认后传播。请避免频繁刷新,如果用户预期余额变化但未看到,请重试后再判定为失败。
  • dflow positions
    仅支持活跃金库钱包
    。无
    --wallet
    参数;切换钱包需使用
    dflow setup
    或API流程。
  • dflow positions
    返回余额,而非标记价格
    。结果包含
    amount
    /
    uiAmount
    /
    decimals
    ,以及结果代币的
    side
    +
    market.title
    +
    market.status
    。这已经可以得到USDC和CASH的近似美元价值(
    uiAmount
    ≈美元,脱钩情况除外),但结果代币需要从
    markets/batch
    获取
    yesBid
    /
    noBid
    进行计价,其他现货代币(如SOL等)需要外部现货价格。输出中也没有
    redemptionStatus
    和成本基准——如需赎回资格检查,请搭配
    markets/batch
    ;如需盈亏计算,请搭配
    /onchain-trades
  • 已关闭的结果代币账户。全部卖出或赎回后,代币账户可能会被关闭(收回租金),不再显示在钱包中。这是正常现象——如需记录,请查看链上成交历史。
  • 同一市场,不同通道=独立头寸。DFlow上的每个Kalshi市场都有USDC通道和CASH通道,各自拥有独立的
    yesMint
    /
    noMint
    。钱包可在同一市场的两个通道持有YES头寸——这些是投资组合中的两行记录,两个赎回流程,按市值计价收益独立汇总。实际中很少见(大多数用户仅使用一个通道),但出现时需妥善处理。
  • 两种使用方式,两种授权路径
    dflow positions
    通过CLI执行,使用其存储的配置(密钥、钱包、RPC)——脚本无需传入任何参数。自定义构建的HTTP流程(
    markets/batch
    onchain-trades
    、RPC
    getParsedTokenAccountsByOwner
    )是纯HTTP/RPC请求,需显式传入DFlow API密钥+RPC URL。两者相互独立:CLI存储的密钥无法被同级HTTP客户端访问。仅在HTTP流程中询问API密钥+RPC URL。

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
/build/recipes/prediction-markets/track-positions
(and its Cookbook Repo link).
对于上述未覆盖的内容——
filter_outcome_mints
/
markets/batch
/
onchain-trades
的完整响应包、分页参数、Proof状态、
redemptionStatus
转换的边缘情况、订单状态终态——请查询docs MCP(
search_d_flow
query_docs_filesystem_d_flow
)。请勿自行猜测。
如需可运行的参考代码,请指向
/build/recipes/prediction-markets/track-positions
(及其Cookbook仓库链接)。

Sibling skills

关联技能

  • dflow-kalshi-trading
    — sell, redeem, or otherwise act on a position you see here.
  • dflow-kalshi-market-data
    — market-centric data (orderbook, trades, candles, in-game) for a position you're watching.
  • dflow-kalshi-market-scanner
    — find new markets to open positions in.
  • dflow-proof-kyc
    — verify a wallet before it can buy into new positions.
  • dflow-kalshi-trading
    ——对在此处查看的头寸进行卖出、赎回或其他操作。
  • dflow-kalshi-market-data
    ——获取关注头寸的市场中心数据(订单簿、成交记录、K线图、盘中数据)。
  • dflow-kalshi-market-scanner
    ——寻找可建立头寸的新市场。
  • dflow-proof-kyc
    ——验证钱包以使其能够买入新头寸。