dflow-kalshi-portfolio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDFlow 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 () — 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
https://pond.dflow.net/mcp/search_d_flow— don't guess.query_docs_filesystem_d_flow - CLI (optional, for the fast-path holdings view) — install per the repo README.
dflow
- DFlow docs MCP()——请按照仓库README进行安装。本技能是操作指南,MCP是参考依据。请通过
https://pond.dflow.net/mcp/search_d_flow查询准确的响应格式、分页参数和批量端点负载——请勿自行猜测。query_docs_filesystem_d_flow - CLI(可选,用于快速查看持仓)——请按照仓库README进行安装。
dflow
Surface
使用方式
There is no endpoint. A portfolio is assembled by hand from onchain wallet balances + metadata joins. Two ways to do it:
/positions- CLI — — 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
dflow positionsalready reads as USD. Doesn't carry mark prices for outcome tokens,uiAmount, or fill history, so outcome-token valuation, redemption checks, and P&L still need the API pipeline. Active-vault only.redemptionStatus - 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————一条命令即可导出活跃金库钱包的现货+结果代币,包含余额和市场标签。适用于在CLI上快速查看“我当前持有什么?”,稳定币的
dflow positions已按USD显示。但该命令不提供结果代币的标记价格、uiAmount或成交历史,因此结果代币估值、赎回检查和盈亏计算仍需通过API流程实现。仅支持活跃金库钱包。redemptionStatus - API——自定义构建流程——当用户需要以下任意功能时必须使用:按市值计价、盈亏计算、活动历史、赎回资格检查,或者查看非CLI活跃金库的钱包。
Quick path: dflow positions
(CLI)
dflow positions快速路径:dflow positions
(CLI)
dflow positionsOutput (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" } }
]
}
}- — SOL, USDC, CASH, and anything else in the wallet.
type: "spot" - — Kalshi outcome token; additionally carries
type: "outcome"(side|"yes") and a minimal"no"(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" } }
]
}
}- ——钱包中的SOL、USDC、CASH及其他代币。
type: "spot" - ——Kalshi结果代币;额外包含
type: "outcome"(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- Read wallet balances via Solana RPC — . Outcome tokens are Token-2022. (For stablecoin balances, also query the classic SPL token program.)
getParsedTokenAccountsByOwner(wallet, { programId: TOKEN_2022_PROGRAM_ID }) - — send the wallet's mint list, get back just the PM outcome mints.
POST /api/v1/filter_outcome_mints - — fetch full market metadata for those outcome mints (title, status, closeTime,
POST /api/v1/markets/batch/yesBid/yesAsk/noBid,noAsk,redemptionStatus/accounts.yesMint).noMint - 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.
标准流程来自DFlow指南:
/build/recipes/prediction-markets/track-positions- 通过Solana RPC读取钱包余额——调用。结果代币为Token-2022标准。(稳定币余额需同时查询经典SPL代币程序。)
getParsedTokenAccountsByOwner(wallet, { programId: TOKEN_2022_PROGRAM_ID }) - ——发送钱包的代币铸造列表,仅返回预测市场的结果代币铸造地址。
POST /api/v1/filter_outcome_mints - ——获取这些结果代币对应的完整市场元数据(标题、状态、关闭时间、
POST /api/v1/markets/batch/yesBid/yesAsk/noBid、noAsk、redemptionStatus/accounts.yesMint)。accounts.noMint - 关联数据——将每个持仓映射到对应市场;通过匹配持仓铸造地址与/
accounts.yesMint判断是YES还是NO头寸。accounts.noMint
字段级细节(响应包、分页)请参考docs MCP。
Views on top of the pipeline
基于流程的视图
Current positions
当前头寸
Output of the pipeline above. Optionally attach current mark price per position ( for YES holdings, for NO holdings — see mark-to-market below).
yesBidnoBid上述流程的输出结果。可选择性地为每个头寸附加当前标记价格(YES持仓用,NO持仓用——见下文按市值计价部分)。
yesBidnoBidUnrealized 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- 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 across fills in the settlement mint.
feeAmount
调用——DFlow索引的钱包链上成交记录视图。
GET /api/v1/onchain-trades?wallet=<pubkey>&sortBy=createdAt&sortOrder=desc&limit=N- 活动流:每一行包含、
createdAt、marketTicker、side、inputAmount、outputAmount。transactionSignature - 单市场成本基准:跟踪每个结果代币的结算代币净流量(买入时的结算代币流入减去卖出时的结算代币流出)。
- 手续费:汇总所有成交记录中的(结算代币计价)。
feeAmount
Redeemable sweep
可赎回头寸扫描
A holding is redeemable iff all three:
- market is
statusordetermined,finalized - market is
redemptionStatus,"open" - the held outcome mint is the winning side (from market ).
result
To redeem, hand off to (redemption is a sell of the winning side back to the settlement mint).
dflow-kalshi-trading持仓可赎回需同时满足以下三个条件:
- 市场为
status或determined,finalized - 市场为
redemptionStatus,"open" - 持有的结果代币属于获胜一方(来自市场)。
result
如需赎回,请转交至(赎回操作是将获胜方代币卖回给结算代币铸造方)。
dflow-kalshi-tradingPending order check
待处理订单检查
If the app submitted the order itself, persist the returned at submission and poll 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.
orderAddressGET /order-status?orderAddress=<addr>如果应用自行提交了订单,请保存提交时返回的并轮询直到订单进入终态。目前没有按钱包列出订单的端点。大多数成交会在CLI的120秒轮询时限内完成,因此这很少是用户关注的问题——但在维护窗口外,不要假设特定的成交时间。
orderAddressGET /order-status?orderAddress=<addr>What to ASK the user (and what NOT to ask)
需要询问用户的内容(及无需询问的内容)
View shape — infer if unambiguous, confirm if not:
- Which view — holdings / mark-to-market / realized P&L / activity / redeemable.
- Wallet pubkey — API only (CLI uses the active vault wallet).
Infra — always ask, never infer (HTTP/RPC pipeline only; the quick path needs neither):
dflow positions- DFlow API key (only when the script is hitting the Metadata API directly — ,
markets/batch, etc.). The CLI quick path (onchain-trades) 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 "isdflow positionsset?" 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 — sameDFLOW_API_KEYunlocks Metadata + Trade APIs. Yes → prod hostx-api-keywithhttps://prediction-markets-api.dflow.net. No → dev hostx-api-key, rate-limited. Pointer:https://dev-prediction-markets-api.dflow.net. When you generate a script, log the resolved host + key-presence at startup.https://pond.dflow.net/build/api-key - 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 quick path don't need one —
dflow positionsalready configured it.dflow setup
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
视图形式——明确时自行推断,不明确时确认:
- 需要哪种视图——持仓/按市值计价/已实现盈亏/活动历史/可赎回头寸。
- 钱包公钥——仅API流程需要(CLI使用活跃金库钱包)。
基础设施——必须询问,绝不自行推断(仅HTTP/RPC流程需要;快速路径无需):
dflow positions- DFlow API密钥(仅当脚本直接调用元数据API时需要——如、
markets/batch等)。onchain-trades快速路径不需要——它使用CLI存储的配置。**对于HTTP流程,请用简洁中立的问题询问:“您是否拥有DFlow API密钥?”**不要预设密钥的存储位置——类似“您是否将其存在环境变量中?”或“dflow positions是否已设置?”的表述会引导用户使用他们未要求的环境变量默认值。请给出选择,不要静默回退到环境变量或开发环境。所有场景使用同一个DFlow密钥——相同的DFLOW_API_KEY可解锁元数据API和交易API。如果有密钥 → 使用生产环境地址x-api-key并携带https://prediction-markets-api.dflow.net。如果没有 → 使用开发环境地址x-api-key,有速率限制。参考链接:https://dev-prediction-markets-api.dflow.net。当生成脚本时,请在启动时记录解析后的地址和密钥状态。https://pond.dflow.net/build/api-key - RPC URL——此处必须询问,不同于现货/预测市场交易或市场数据流程。HTTP流程需直接通过RPC读取代币账户;没有钱包代为执行此操作。推荐使用Helius。使用快速路径的CLI用户不需要——
dflow positions已配置好RPC。dflow setup
无需询问的内容:
- 结算代币、滑点、手续费、签名——本技能为只读模式。如果用户转向对头寸进行操作,请转交至。
dflow-kalshi-trading
Gotchas (the docs MCP won't volunteer these)
注意事项(docs MCP不会主动提及)
- No endpoint. Portfolio = wallet balances + metadata joins. Don't hunt the API for a shortcut.
/positions - Token-2022 program for outcome tokens. , not the classic token program. Query the classic program separately for USDC/SOL/CASH.
TOKEN_2022_PROGRAM_ID - Mark-to-market = bid, not ask. Long YES → . Long NO →
yesBid. Marking on the ask overstates the portfolio.noBid - Two POST endpoints. and
filter_outcome_mintsboth take a POST body with an address list. Easy to default to GET and fail.markets/batch - Stablecoins aren't outcome mints. strips them out (they're settlement, not positions). Track USDC / CASH balances separately from the PM view.
filter_outcome_mints - Redemption readiness is three ANDed conditions, not just "market closed." Surface a redeemable list only when status + + winning side all line up.
redemptionStatus - 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.
- is active-vault only. No
dflow positionsflag; switching wallets means--walletor the API pipeline.dflow setup - returns balances, not mark prices. You get
dflow positions/amount/uiAmountplusdecimals+side+market.titleon outcome tokens. That already gets you close to dollar value for USDC and CASH (theirmarket.status≈ USD modulo depeg), but outcome tokens needuiAmount/yesBidfromnoBidto mark, and other spot tokens (SOL, etc.) need an outside spot price. Nomarkets/batchand no cost basis in the output either — pair withredemptionStatusfor redemption eligibility,markets/batchfor P&L./onchain-trades - 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. 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.noMint - Two surfaces, two auth paths. 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 (
dflow positions,markets/batch, RPConchain-trades) 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.getParsedTokenAccountsByOwner
- 不存在端点。投资组合=钱包余额+元数据关联。不要在API中寻找捷径。
/positions - 结果代币使用Token-2022程序。使用,而非经典代币程序。需单独查询经典程序获取USDC/SOL/CASH余额。
TOKEN_2022_PROGRAM_ID - 按市值计价使用买方报价,而非卖方报价。持有YES头寸→。持有NO头寸→
yesBid。使用卖方报价会高估投资组合价值。noBid - 两个POST端点。和
filter_outcome_mints均接受包含地址列表的POST请求体。请勿默认使用GET请求,否则会失败。markets/batch - 稳定币不是结果代币。会过滤掉稳定币(它们是结算代币,而非头寸)。需将USDC/CASH余额与预测市场视图分开跟踪。
filter_outcome_mints - 赎回就绪需满足三个同时成立的条件,而非仅“市场关闭”。仅当状态++获胜方全部满足时,才展示可赎回列表。
redemptionStatus - 成交后余额延迟。刚上链的成交可能不会立即在非索引RPC上显示——代币账户更新会在交易最终确认后传播。请避免频繁刷新,如果用户预期余额变化但未看到,请重试后再判定为失败。
- 仅支持活跃金库钱包。无
dflow positions参数;切换钱包需使用--wallet或API流程。dflow setup - 返回余额,而非标记价格。结果包含
dflow positions/amount/uiAmount,以及结果代币的decimals+side+market.title。这已经可以得到USDC和CASH的近似美元价值(market.status≈美元,脱钩情况除外),但结果代币需要从uiAmount获取markets/batch/yesBid进行计价,其他现货代币(如SOL等)需要外部现货价格。输出中也没有noBid和成本基准——如需赎回资格检查,请搭配redemptionStatus;如需盈亏计算,请搭配markets/batch。/onchain-trades - 已关闭的结果代币账户。全部卖出或赎回后,代币账户可能会被关闭(收回租金),不再显示在钱包中。这是正常现象——如需记录,请查看链上成交历史。
- 同一市场,不同通道=独立头寸。DFlow上的每个Kalshi市场都有USDC通道和CASH通道,各自拥有独立的/
yesMint。钱包可在同一市场的两个通道持有YES头寸——这些是投资组合中的两行记录,两个赎回流程,按市值计价收益独立汇总。实际中很少见(大多数用户仅使用一个通道),但出现时需妥善处理。noMint - 两种使用方式,两种授权路径。通过CLI执行,使用其存储的配置(密钥、钱包、RPC)——脚本无需传入任何参数。自定义构建的HTTP流程(
dflow positions、markets/batch、RPConchain-trades)是纯HTTP/RPC请求,需显式传入DFlow API密钥+RPC URL。两者相互独立:CLI存储的密钥无法被同级HTTP客户端访问。仅在HTTP流程中询问API密钥+RPC URL。getParsedTokenAccountsByOwner
When something doesn't fit
未覆盖场景处理
For anything not covered above — full response envelopes for / / , pagination params, Proof state in the picture, edge cases in transitions, order-status terminal states — query the docs MCP (, ). Don't guess.
filter_outcome_mintsmarkets/batchonchain-tradesredemptionStatussearch_d_flowquery_docs_filesystem_d_flowFor runnable reference code, point at (and its Cookbook Repo link).
/build/recipes/prediction-markets/track-positions对于上述未覆盖的内容——//的完整响应包、分页参数、Proof状态、转换的边缘情况、订单状态终态——请查询docs MCP(、)。请勿自行猜测。
filter_outcome_mintsmarkets/batchonchain-tradesredemptionStatussearch_d_flowquery_docs_filesystem_d_flow如需可运行的参考代码,请指向(及其Cookbook仓库链接)。
/build/recipes/prediction-markets/track-positionsSibling skills
关联技能
- — sell, redeem, or otherwise act on a position you see here.
dflow-kalshi-trading - — market-centric data (orderbook, trades, candles, in-game) for a position you're watching.
dflow-kalshi-market-data - — find new markets to open positions in.
dflow-kalshi-market-scanner - — verify a wallet before it can buy into new positions.
dflow-proof-kyc
- ——对在此处查看的头寸进行卖出、赎回或其他操作。
dflow-kalshi-trading - ——获取关注头寸的市场中心数据(订单簿、成交记录、K线图、盘中数据)。
dflow-kalshi-market-data - ——寻找可建立头寸的新市场。
dflow-kalshi-market-scanner - ——验证钱包以使其能够买入新头寸。
dflow-proof-kyc