dflow-kalshi-market-data
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDFlow Kalshi Market Data
DFlow Kalshi 市场数据
Pull data about a known Kalshi market (or set of markets) — orderbook, trades, prices, candles, forecasts, in-game live data — as a snapshot, a historical range, or a live stream.
拉取已知Kalshi市场(或一组市场)的相关数据——订单簿、交易记录、价格、K线图、预测数据、游戏内实时数据——支持快照、历史范围查询或实时流三种方式。
Prerequisites
前置条件
- DFlow docs MCP () — install per the repo README. This skill is the recipe; the MCP is the reference. Query params, pagination, exact payload schemas, WS snapshot-vs-diff semantics, and the category-specific
https://pond.dflow.net/mcpshapes all live there — don't guess.live_data.details
- DFlow文档MCP()——请按照仓库README中的说明安装。本技能是操作指南,MCP是参考依据。查询参数、分页规则、精确的负载 schema、WebSocket快照与增量更新的语义,以及特定分类的
https://pond.dflow.net/mcp结构均在MCP中定义——请勿自行猜测。live_data.details
Surface
调用方式
All data endpoints in this skill run against the Metadata API () — REST for snapshots and history, WebSockets for live streams. Call it from anywhere: a from the command line, a Node/Python script, a cron job, a backend, or a Next.js proxy fronting a browser UI.
https://pond.dflow.net/build/metadata-apicurlIf the user says "run this from my terminal", don't reach for the CLI — it has no market-data subcommands. Write a short HTTP/WS script against the Metadata API instead.
dflow本技能中的所有数据端点均基于Metadata API()——REST接口用于快照和历史查询,WebSocket用于实时流。可从任意环境调用:命令行的、Node/Python脚本、定时任务、后端服务,或是为浏览器UI提供代理的Next.js应用。
https://pond.dflow.net/build/metadata-apicurl如果用户要求“从我的终端运行”,请勿使用 CLI——它没有市场数据相关的子命令。请编写一个简短的HTTP/WS脚本直接调用Metadata API。
dflowPick the shape first
先选择数据形态
Three intents, three shapes. Match the user's phrasing, then pick the endpoint:
- Snapshot ("right now", "current") → REST, one call.
- History ("last hour", "between T1 and T2", "last N trades") → REST with time / limit params.
- Stream ("live", "as it happens", "alert me when") → WebSocket subscription.
三种需求对应三种数据形态。匹配用户的表述,然后选择对应的端点:
- 快照(“当前”、“现在”)→ REST接口,单次调用。
- 历史数据(“过去一小时”、“T1到T2之间”、“最近N笔交易”)→ REST接口,附带时间/限制参数。
- 实时流(“实时”、“即时更新”、“当...时提醒我”)→ WebSocket订阅。
Data → endpoint map
数据→端点映射
For each dataset below, the one-liner covers all three shapes. Field-level details (exact params, pagination tokens, payload schemas) → docs MCP.
以下每个数据集的说明涵盖了三种数据形态。字段级详情(精确参数、分页令牌、负载schema)请参考文档MCP。
Orderbook
订单簿
- Snapshot: or
GET /api/v1/orderbook/{ticker}(includes/api/v1/orderbook/by-mint/{mint}).sequence - Stream: channel (
orderbook+yes_bidsmaps per update; nono_bidson the stream payload).sequence
- 快照:或
GET /api/v1/orderbook/{ticker}(包含/api/v1/orderbook/by-mint/{mint}字段)。sequence - 实时流:频道(每次更新包含
orderbook和yes_bids映射;流负载中不包含no_bids字段)。sequence
Trades — two endpoints, overlapping but different scopes
交易记录——两个端点,范围重叠但有所不同
- (and
GET /api/v1/trades) — the complete market print tape. All trades that hit Kalshi's orderbook, which includes DFlow onchain fills (those hit Kalshi's book too; see the "Do onchain trades show up on Kalshi's trade websocket?" FAQ). This is the default for "show me trades on this market." Stream equivalent:/trades/by-mint/{mint}channel.trades - (and
GET /api/v1/onchain-trades,/onchain-trades/by-market/{ticker}) — DFlow onchain fills only, with onchain-specific fields that/onchain-trades/by-event/{eventTicker}doesn't carry:/trades,wallet,transactionSignature,id,inputAmount,outputAmount. Subset of what's oncreatedAt, but richer per-row. No WS stream./trades - Decision: complete tape → . Wallet-scoped activity feed, DFlow-execution analytics, tx-signature lookups →
/trades. Real-time fill detection for a specific user order → parse program events directly (see/onchain-trades)./build/prediction-markets/onchain-trade-parsing
- (以及
GET /api/v1/trades)——完整的市场交易记录。所有在Kalshi订单簿上成交的交易,包括DFlow链上成交的订单(这些订单也会进入Kalshi的订单簿;请查看FAQ“链上交易会出现在Kalshi的交易WebSocket上吗?”)。这是“展示该市场的交易记录”的默认选择。对应的实时流频道:/trades/by-mint/{mint}。trades - (以及
GET /api/v1/onchain-trades、/onchain-trades/by-market/{ticker})——仅DFlow链上成交的订单,包含/onchain-trades/by-event/{eventTicker}端点没有的链上专属字段:/trades、wallet、transactionSignature、id、inputAmount、outputAmount。是createdAt的子集,但每行数据更丰富。无WebSocket流。/trades - 选择建议:需要完整交易记录→使用。需要钱包范围的活动流、DFlow执行分析、交易签名查询→使用
/trades。要实时检测特定用户订单的成交情况→直接解析程序事件(请参阅/onchain-trades)。/build/prediction-markets/onchain-trade-parsing
Top-of-book prices
最优报价
- Snapshot: read /
yesBid/yesAsk/noBiddirectly from the market object (noAsk— singular) — no separate endpoint.GET /api/v1/market/{ticker} - Stream: channel.
prices
- 快照:直接从市场对象中读取/
yesBid/yesAsk/noBid字段(noAsk——单个市场)——无需单独的端点。GET /api/v1/market/{ticker} - 实时流:频道。
prices
Candlesticks (OHLCV)
K线图(OHLCV)
- Market-level: or
GET /api/v1/market/{ticker}/candlesticks./api/v1/market/by-mint/{mint}/candlesticks - Event-level: .
GET /api/v1/event/{ticker}/candlesticks - 5,000-candle cap per request (see Gotchas).
- 市场级:或
GET /api/v1/market/{ticker}/candlesticks。/api/v1/market/by-mint/{mint}/candlesticks - 事件级:。
GET /api/v1/event/{ticker}/candlesticks - 每次请求最多返回5000根K线(请参阅注意事项)。
Forecast percentile history
预测百分位历史
- Event-level: (plus
GET /api/v1/event/{seriesTicker}/{eventId}/forecast_percentile_history). Kalshi's historical forecast distribution for an event./api/v1/event/by-mint/{mint}/forecast_percentile_history
- 事件级:(以及
GET /api/v1/event/{seriesTicker}/{eventId}/forecast_percentile_history)。Kalshi针对某一事件的历史预测分布数据。/api/v1/event/by-mint/{mint}/forecast_percentile_history
Live data (Kalshi passthrough)
实时数据(Kalshi直通)
- ,
GET /api/v1/live_data,/live_data/by-event/{ticker}./live_data/by-mint/{mint} - Response includes a object whose fields depend on the milestone type — football, soccer, tennis, golf, MMA, baseball, cricket, racing each have their own known-field sets. See
detailsin the docs MCP before touchinglive-data-details.details
- 、
GET /api/v1/live_data、/live_data/by-event/{ticker}。/live_data/by-mint/{mint} - 响应包含一个对象,其字段取决于里程碑类型——足球、足球(英式)、网球、高尔夫、MMA、棒球、板球、赛车各自有一套已知的字段集合。在使用
details之前,请查看文档MCP中的details。live-data-details
Streaming lifecycle
流生命周期
Connect → subscribe → handle → reconnect. In a sentence each:
- Connect: dev is (no auth). Prod is
wss://dev-prediction-markets-api.dflow.net/api/v1/wswithwss://prediction-markets-api.dflow.net/api/v1/wson the WS upgrade headers. REST equivalents:x-api-keyandhttps://dev-prediction-markets-api.dflow.net.https://prediction-markets-api.dflow.net - Subscribe: send . Each channel holds its own subscription state.
{ type: "subscribe", channel: "prices" | "trades" | "orderbook", all: true | tickers: [...] } - Handle: parse each message by , process asynchronously — don't block the read loop.
channel - Reconnect: exponential backoff on disconnect, and re-send every subscription after reconnect. The server doesn't remember you.
Exact message schemas (prices, trades, orderbook), heartbeat/ping behavior, and incremental-vs-snapshot semantics on the orderbook channel → docs MCP.
连接→订阅→处理→重连。各步骤简述:
- 连接:开发环境地址为(无需认证)。生产环境地址为
wss://dev-prediction-markets-api.dflow.net/api/v1/ws,需在WebSocket升级请求头中携带wss://prediction-markets-api.dflow.net/api/v1/ws。对应的REST地址分别为:x-api-key和https://dev-prediction-markets-api.dflow.net。https://prediction-markets-api.dflow.net - 订阅:发送。每个频道独立维护订阅状态。
{ type: "subscribe", channel: "prices" | "trades" | "orderbook", all: true | tickers: [...] } - 处理:按解析每条消息,异步处理——不要阻塞读取循环。
channel - 重连:断开连接时使用指数退避策略重试,并且重连后重新发送所有订阅请求。服务器不会保留你的订阅状态。
精确的消息schema(价格、交易、订单簿)、心跳/ ping行为、订单簿频道的增量更新与快照语义,请参考文档MCP。
What to ASK the user (and what NOT to ask)
需要询问用户的内容(以及无需询问的内容)
Query shape — infer if unambiguous, confirm if not:
- Which market — ticker or outcome mint.
- Which dataset — orderbook, trades (Kalshi vs onchain), prices, candles, forecasts, or live data.
- Snapshot / history / stream — infer from phrasing, confirm if ambiguous.
- History bounds / interval — time range (,
startTs) andendTsfor candles; limit for trades.periodInterval
Infra — always ask, never infer:
- DFlow API key. 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 set?" nudge the user toward env-var defaults they didn't ask for. Don't assume the user has one just because they mention the
DFLOW_API_KEYCLI is configured. Surface the choice; don't silently fall back to env or to dev. It's one key for everything DFlow — samedflowunlocks the Trade API and the Metadata API, REST and WebSocket. If yes → prod host (x-api-keyREST,https://prediction-markets-api.dflow.netWS) withwss://prediction-markets-api.dflow.net/api/v1/wson every request (REST and the WS upgrade). If no → dev host (x-api-key,https://dev-prediction-markets-api.dflow.net), rate-limited; point them atwss://dev-prediction-markets-api.dflow.net/api/v1/wsfor a prod key. When you generate a script, log the resolved host + key-presence at startup so the user can see which rails they're on.https://pond.dflow.net/build/api-key
Do NOT ask about:
- RPC, wallet, signing — this skill is read-only public data.
- Settlement mint / slippage / fees — trade-side concerns; if the user pivots to placing an order off something they see here, hand off to .
dflow-kalshi-trading
查询形态——表述明确则自行推断,表述模糊则确认:
- 哪个市场——ticker或标的mint地址。
- 哪种数据集——订单簿、交易记录(Kalshi vs 链上)、价格、K线图、预测数据或实时数据。
- 快照/历史数据/实时流——根据用户表述推断,模糊时确认。
- 历史范围/时间间隔——K线图的时间范围(、
startTs)和endTs;交易记录的数量限制。periodInterval
基础设施相关——必须询问,切勿自行推断:
- DFlow API密钥。**请用简洁中立的问题询问:“你是否拥有DFlow API密钥?”**不要预设密钥的存储位置——类似“你是否将其存放在环境变量中?”或“是否设置了?”的表述会引导用户使用他们未要求的环境变量默认值。不要因为用户提到
DFLOW_API_KEYCLI已配置就假设他们拥有密钥。请给出选择;不要默认使用环境变量或开发环境。一个密钥可用于所有DFlow服务——同一个dflow可解锁Trade API和Metadata API,包括REST和WebSocket。如果用户拥有密钥→使用生产环境地址(REST:x-api-key,WebSocket:https://prediction-markets-api.dflow.net),并在每个请求(REST和WebSocket升级)中携带wss://prediction-markets-api.dflow.net/api/v1/ws。如果没有→使用开发环境地址(x-api-key,https://dev-prediction-markets-api.dflow.net),该环境有速率限制;请引导用户访问wss://dev-prediction-markets-api.dflow.net/api/v1/ws获取生产环境密钥。当你生成脚本时,请在启动时输出已解析的地址和密钥状态,以便用户了解当前使用的环境。https://pond.dflow.net/build/api-key
无需询问的内容:
- RPC、钱包、签名——本技能仅处理只读的公开数据。
- 结算mint地址/滑点/手续费——这些是交易相关的问题;如果用户根据此处看到的数据转而提出下单需求,请转交至技能。
dflow-kalshi-trading
Gotchas (the docs MCP won't volunteer these)
注意事项(文档MCP未主动提及)
- Two trade endpoints, overlapping scopes. is the complete market tape (Kalshi-offchain order flow plus DFlow onchain fills — DFlow fills hit Kalshi's book).
/api/v1/tradesis the DFlow-onchain subset, enriched with/api/v1/onchain-trades/wallet/ input-output amounts. When a user says "show trades on this market" they wanttransactionSignature; when they say "show this wallet's DFlow activity" they want/trades./onchain-trades?wallet=... - Orderbook returns only bid ladders (,
yes_bids). Best YES ask is derived:no_bids(a NO bid at1 - max(no_bids keys)is a YES offer atp). Same on REST and the WS channel.1-p - Two price scales. Probability strings () on orderbook + prices channels. Integer 0–10000 on
"0.4200"+/tradeschannel, withtrades/yes_price_dollarsstring companions. Normalize before you compute.no_price_dollars - 5,000-candle cap per request, hard 400. If the range × interval would produce more than 5,000 candles, the endpoint returns a 400 with no partial result — it's Kalshi's upstream cap forwarded through DFlow. Narrow the range, widen the interval, or page yourself.
- is in minutes, not seconds. Kalshi convention:
periodInterval= 1-minute candles,1= hourly,60= daily. Easy to blow past the 5,000-candle cap by assuming seconds.1440 - is categorical, not generic. Fields differ per milestone type. Don't hardcode cross-category field access; branch on
live_data.detailsand pull the known fields for that category from the MCP'stypereference.live-data-details - WebSocket is a firehose. Especially on
all: trueandprices. Use a ticker list unless the monitor truly needs universe-wide coverage.orderbook - WS subscriptions don't survive reconnects. After every reconnect, resend every message you had before the drop.
subscribe - Streams can go quiet in the maintenance window — Thursdays 3:00–5:00 AM ET, Kalshi is offline; expect sparse or missing WS traffic and stale REST fields.
- The CLI's stored key doesn't flow into your script's HTTP client. stores the key for the
dflow setupbinary's own use. The Metadata API calls your script makes directly are separate — they need the key plumbed in (env,dflow, flag). It's one DFlow key, but two plumbing sites any time you mix CLI invocations with direct HTTP/WS calls in the same codebase..env
- 两个交易记录端点,范围重叠但不同。是完整的市场交易记录(Kalshi链下订单流加上DFlow链上成交的订单——DFlow成交的订单会进入Kalshi的订单簿)。
/api/v1/trades是DFlow链上成交的子集,包含/api/v1/onchain-trades/wallet/输入输出金额等额外字段。当用户说“展示该市场的交易记录”时,他们需要的是transactionSignature;当用户说“展示该钱包的DFlow活动”时,他们需要的是/trades。/onchain-trades?wallet=... - 订单簿仅返回买单队列(、
yes_bids)。最优YES卖价需推导得出:no_bids(NO买单价格为1 - max(no_bids的键值)等价于YES卖价为p)。REST接口和WebSocket频道均遵循此规则。1-p - 两种价格刻度。订单簿和价格频道使用概率字符串()。
"0.4200"和/trades频道使用0–10000的整数,附带trades/yes_price_dollars字符串格式的价格。计算前请先统一格式。no_price_dollars - 每次请求最多返回5000根K线,超出则返回400错误。如果时间范围×时间间隔会生成超过5000根K线,端点会返回400错误且无部分结果——这是Kalshi上游的限制,DFlow直接转发。请缩小时间范围、增大时间间隔,或自行分页。
- 的单位是分钟,而非秒。Kalshi的约定:
periodInterval=1分钟K线,1=小时级,60=日级。若误以为单位是秒,很容易超出5000根K线的限制。1440 - 是分类特定的,而非通用结构。字段因里程碑类型而异。请勿硬编码跨分类的字段访问;请根据
live_data.details分支处理,并从MCP的type参考中获取对应分类的已知字段。live-data-details - WebSocket的是全量数据流。尤其是
all: true和prices频道。除非监控确实需要覆盖全市场,否则请使用ticker列表订阅。orderbook - WebSocket订阅不会在重连后保留。每次重连后,重新发送所有之前的消息。
subscribe - 维护窗口期间流可能中断——每周四美国东部时间3:00–5:00,Kalshi会下线;此时WebSocket流量可能稀疏或缺失,REST字段可能过时。
- CLI存储的密钥不会自动流入脚本的HTTP客户端。为
dflow setup二进制文件存储密钥。你的脚本直接调用Metadata API时是独立的——需要手动传入密钥(环境变量、dflow文件、命令行参数)。虽然是同一个DFlow密钥,但当你在同一代码库中混合使用CLI调用和直接HTTP/WS调用时,需要在两个地方配置密钥。.env
When something doesn't fit
超出范围的内容
For anything not covered above — full parameter lists, pagination tokens, exact WS message shapes (snapshot-vs-diff on orderbook, heartbeat cadence), candlestick interval enums, category-specific fields, forecast-percentile response shape — query the docs MCP (, ). Don't guess.
live_data.detailssearch_d_flowquery_docs_filesystem_d_flow对于上述未涵盖的内容——完整参数列表、分页令牌、精确的WebSocket消息结构(订单簿的快照与增量更新、心跳频率)、K线图时间间隔枚举、特定分类的字段、预测百分位响应结构——请查询文档MCP(、)。请勿自行猜测。
live_data.detailssearch_d_flowquery_docs_filesystem_d_flowSibling skills
关联技能
- — find markets matching a criterion across the universe (uses these primitives, shapes them into named scans).
dflow-kalshi-market-scanner - — place buy / sell / redeem orders on a market you're watching here.
dflow-kalshi-trading - — view the user's own positions and P&L.
dflow-kalshi-portfolio
- ——在全市场中查找符合特定条件的市场(基于本技能的基础功能,构建为命名扫描)。
dflow-kalshi-market-scanner - ——在你监控的市场上下买单/卖单/赎回单。
dflow-kalshi-trading - ——查看用户自身的持仓和盈亏。
dflow-kalshi-portfolio