dflow-market-data
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDFlow Market Data (Streaming)
DFlow 市场数据(流式传输)
Real-time market data for Solana spot pairs over WebSocket. Read-only: this streams prices, depth, and fee estimates for display and analysis. To execute a swap, use .
dflow-spot-trading通过 WebSocket 提供 Solana 现货交易对的实时市场数据。只读:此功能仅流式传输用于展示和分析的价格、深度及费用估算。若要执行 swap,请使用 。
dflow-spot-tradingThe three streams
三种数据流
All are paths on the DFlow Trade API WebSocket host (prod , dev ). One connection; subscribe per pair.
wss://quote-api.dflow.netwss://dev-quote-api.dflow.net| Stream | Path | Gives you |
|---|---|---|
| Quotes | | live top-of-book bid/ask for a pair |
| Order book | | ten levels of depth per side |
| Priority fees | | live priority-fee estimates (no polling) |
它们都是 DFlow Trade API WebSocket 主机上的路径(生产环境为 ,开发环境为 )。只需建立一个连接,然后按交易对分别订阅。
wss://quote-api.dflow.netwss://dev-quote-api.dflow.net| 数据流 | 路径 | 提供内容 |
|---|---|---|
| Quotes | | 交易对的实时盘口最优买一/卖一报价 |
| Order book | | 买卖双方各十档深度 |
| Priority fees | | 实时优先费估算(无需轮询) |
Keep the key on the backend (proxy the stream)
将 key 保存在后端(代理数据流)
As a security best practice, keep your DFlow API key on the backend, not in browser code where anyone can read it. Stream through a backend proxy that holds the key, connects to DFlow, and relays messages to the browser.
A server-side app (Node/CLI, no browser) is already the trusted backend, so it connects directly with the key as an header.
x-api-keyjs
// Backend relay (Node, `ws`). The browser connects to THIS; the backend holds the key.
import { WebSocketServer, WebSocket } from "ws";
const wss = new WebSocketServer({ server }); // same origin as your app
wss.on("connection", (client) => {
const up = new WebSocket(`${process.env.DFLOW_TRADE_API_WS_URL}/book-stream`,
{ headers: { "x-api-key": process.env.DFLOW_API_KEY } });
const q = [];
up.on("open", () => { q.forEach((m) => up.send(m)); q.length = 0; });
up.on("message", (d) => client.readyState === 1 && client.send(d.toString()));
client.on("message", (m) => up.readyState === 1 ? up.send(m.toString()) : q.push(m.toString()));
client.on("close", () => up.close()); up.on("close", () => client.close());
});作为安全最佳实践,应将 DFlow API key 保存在后端,而不是放入任何人都可以读取的浏览器代码中。通过后端代理转发数据流,由后端持有 key、连接 DFlow,并将消息中继到浏览器。
服务端应用(Node/CLI,非浏览器环境)本身已是可信后端,因此可以直接使用 key,并将其作为 请求头进行连接。
x-api-keyjs
// Backend relay (Node, `ws`). The browser connects to THIS; the backend holds the key.
import { WebSocketServer, WebSocket } from "ws";
const wss = new WebSocketServer({ server }); // same origin as your app
wss.on("connection", (client) => {
const up = new WebSocket(`${process.env.DFLOW_TRADE_API_WS_URL}/book-stream`,
{ headers: { "x-api-key": process.env.DFLOW_API_KEY } });
const q = [];
up.on("open", () => { q.forEach((m) => up.send(m)); q.length = 0; });
up.on("message", (d) => client.readyState === 1 && client.send(d.toString()));
client.on("message", (m) => up.readyState === 1 ? up.send(m.toString()) : q.push(m.toString()));
client.on("close", () => up.close()); up.on("close", () => client.close());
});Prerequisites
前置条件
- DFlow docs MCP (): this skill is the recipe; the MCP is the reference. Before wiring a specific stream, load its message-schema page with
https://pond.dflow.net/mcp/search_d_flowforquery_docs_filesystem_d_flow. Don't guess field names./resources/trading-api/websockets/{overview,quote-stream,book-stream,priority-fees-stream} - A DFlow API key (see "What to ASK").
In production, access to the quote and book streams is granted per key: a key that works formay need stream access enabled on it, so a valid key can still be refused on the stream until the team turns it on. The priority-fees stream is not gated./order
- DFlow 文档 MCP():本 skill 提供接入方法,MCP 用作参考文档。在接入具体数据流之前,使用
https://pond.dflow.net/mcp/search_d_flow加载query_docs_filesystem_d_flow对应的消息 schema 页面。不要猜测字段名。/resources/trading-api/websockets/{overview,quote-stream,book-stream,priority-fees-stream} - DFlow API key(参见“需要询问的信息”)。
在生产环境中,quote 和 book 数据流的访问权限按 key 授予:适用于的 key 可能仍需单独启用数据流访问权限,因此即使 key 有效,在团队启用权限前,访问数据流仍可能被拒绝。priority-fees 数据流不受此限制。/order
Subscribe and handle frames (quote and book)
订阅并处理帧(quote 和 book)
- Subscribe: with base58 mints, not symbols.
{ "op": "subscribe", "base_mint": "<mint>", "quote_mint": "<mint>" }mirrors it. One connection multiplexes many pairs.unsubscribe - Frames batch per slot: . Each entry in
{ u: <slot>, ts, updates: [ { sb, sq, ... } ] }is keyed by its subject mints (updates[]/sb); a per-pair error arrives inline assq, which you handle without tearing down the whole feed. Load the stream's doc page for the exact per-level fields ({ e: <code>, sb, sq }/b,a,mid,tick, and so on).cumulative_size_human - Reconnect and re-subscribe. WebSockets drop; on reopen, resend every subscription with a backoff. Track the slot (and
u, which is 0 when the stream kept up) to detect gaps.skipped
- 订阅: ,使用 base58 mint,而不是交易对符号。
{ "op": "subscribe", "base_mint": "<mint>", "quote_mint": "<mint>" }与其对称。一个连接可复用多个交易对。unsubscribe - 帧按 slot 批量发送: 。
{ u: <slot>, ts, updates: [ { sb, sq, ... } ] }中的每个条目都以其主体 mint(updates[]/sb)为键;单个交易对的错误会以内联形式返回,即sq,应单独处理该错误,而无需中断整个数据流。请加载相应数据流的文档页面,以获取确切的逐档字段({ e: <code>, sb, sq }/b、a、mid、tick等)。cumulative_size_human - 重连并重新订阅。 WebSocket 会断开;重新打开后,应采用 backoff 重新发送每个订阅。跟踪 slot (以及
u,当数据流跟得上时其值为 0),以检测数据缺口。skipped
Priority-fees stream
Priority-fees 数据流
The priority-fees stream works differently from quote and book: no subscribe message, just connect and read. Each message is a flat object (the same shape as ), and this stream is not gated. Details: load via the docs MCP.
{ mediumMicroLamports, highMicroLamports, veryHighMicroLamports }GET /priority-fees/resources/trading-api/websockets/priority-fees-streampriority-fees 数据流的工作方式不同于 quote 和 book:无需发送 subscribe 消息,只需连接并读取。每条消息都是一个扁平对象 (其结构与 相同),并且此数据流不受访问限制。详情:请通过文档 MCP 加载 。
{ mediumMicroLamports, highMicroLamports, veryHighMicroLamports }GET /priority-fees/resources/trading-api/websockets/priority-fees-streamCaveats: set expectations
注意事项:合理设定预期
Book and quote levels are approximations: the book is direct-routes-only (10 levels); quotes are direct plus one-hop, computed from a roughly $10 USDC round-trip. They can differ from the real quote at trade time. Don't present them as an exchange-grade order book or as the executable price. For the price a user will actually get, quote (see ).
/order/orderdflow-spot-trading订单簿和报价档位是近似值:订单簿仅包含直接路由(10 档);quotes 由直接路由加一跳路由计算得出,参考约 $10 USDC 的往返交易规模。它们可能与交易时实际的 报价不同。不要将其描述为交易所级别的订单簿或可执行价格。若需要用户实际获得的价格,请请求 报价(参见 )。
/order/orderdflow-spot-tradingWhat to ASK
需要询问的信息
- API key. Ask neutrally: "Do you have a DFlow API key?" It's one key for everything DFlow (the same across the REST APIs and the WebSocket streams). Yes: prod
x-api-key. No: devwss://quote-api.dflow.net(rate-limited, for testing). Prod key:wss://dev-quote-api.dflow.net.https://pond.dflow.net/get-started/api-key - Surface. Browser or server-side? A browser app proxies through its backend (above); a server-side app connects directly with the header.
- API key。 中性询问:“你有 DFlow API key 吗?” DFlow 的所有功能共用同一个 key(REST API 和 WebSocket 数据流均使用相同的 )。有:使用生产环境
x-api-key。没有:使用开发环境wss://quote-api.dflow.net(有速率限制,仅用于测试)。生产环境 key:wss://dev-quote-api.dflow.net。https://pond.dflow.net/get-started/api-key - 接入位置。 浏览器端还是服务端?浏览器应用应通过其后端进行代理(见上文);服务端应用则可以直接连接,并在请求头中携带 key。
When something doesn't fit
其他情况
Per-stream message schema, ping/keepalive, priority-fee fields: docs MCP (). Runnable reference: the DFlow order-book-visualization demo (a complete plus proxy build), plus docs recipes and .
/resources/trading-api/websockets/*/book-stream/spot/recipes/stream-order-book/spot/recipes/stream-quotes各数据流的消息 schema、ping/keepalive、优先费字段:文档 MCP()。可运行参考:DFlow 订单簿可视化 demo(包含完整的 和代理构建),以及文档 recipe 和 。
/resources/trading-api/websockets/*/book-stream/spot/recipes/stream-order-book/spot/recipes/stream-quotesSibling skills
相关 skill
- : execute a swap, or take a builder platform fee. A "show live prices / order book / depth" task belongs here; a "buy / swap / convert" task belongs in
dflow-spot-trading.dflow-spot-trading
- :执行 swap,或收取 builder platform fee。“显示实时价格/订单簿/深度”的任务属于本 skill;“买入/swap/兑换”的任务属于
dflow-spot-trading。dflow-spot-trading