dflow-market-data

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

DFlow 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-trading
。

The three streams

三种数据流

All are paths on the DFlow Trade API WebSocket host (prod
wss://quote-api.dflow.net
, dev
wss://dev-quote-api.dflow.net
). One connection; subscribe per pair.
StreamPathGives you
Quotes
/quote-stream
live top-of-book bid/ask for a pair
Order book
/book-stream
ten levels of depth per side
Priority fees
/priority-fees/stream
live priority-fee estimates (no polling)
它们都是 DFlow Trade API WebSocket 主机上的路径(生产环境为
wss://quote-api.dflow.net
,开发环境为
wss://dev-quote-api.dflow.net
)。只需建立一个连接,然后按交易对分别订阅。
数据流路径提供内容
Quotes
/quote-stream
交易对的实时盘口最优买一/卖一报价
Order book
/book-stream
买卖双方各十档深度
Priority fees
/priority-fees/stream
实时优先费估算(无需轮询)

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
x-api-key
header.
js
// 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-key
请求头进行连接。
js
// 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 (
    https://pond.dflow.net/mcp
    ): this skill is the recipe; the MCP is the reference. Before wiring a specific stream, load its message-schema page with
    search_d_flow
    /
    query_docs_filesystem_d_flow
    for
    /resources/trading-api/websockets/{overview,quote-stream,book-stream,priority-fees-stream}
    . Don't guess field names.
  • 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 for
/order
may 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.
  • DFlow 文档 MCP(
    https://pond.dflow.net/mcp
    ):本 skill 提供接入方法,MCP 用作参考文档。在接入具体数据流之前,使用
    search_d_flow
    /
    query_docs_filesystem_d_flow
    加载
    /resources/trading-api/websockets/{overview,quote-stream,book-stream,priority-fees-stream}
    对应的消息 schema 页面。不要猜测字段名。
  • DFlow API key(参见“需要询问的信息”)。
在生产环境中,quote 和 book 数据流的访问权限按 key 授予:适用于
/order
的 key 可能仍需单独启用数据流访问权限,因此即使 key 有效,在团队启用权限前,访问数据流仍可能被拒绝。priority-fees 数据流不受此限制。

Subscribe and handle frames (quote and book)

订阅并处理帧(quote 和 book)

  • Subscribe:
    { "op": "subscribe", "base_mint": "<mint>", "quote_mint": "<mint>" }
    with base58 mints, not symbols.
    unsubscribe
    mirrors it. One connection multiplexes many pairs.
  • Frames batch per slot:
    { u: <slot>, ts, updates: [ { sb, sq, ... } ] }
    . Each entry in
    updates[]
    is keyed by its subject mints (
    sb
    /
    sq
    ); a per-pair error arrives inline as
    { e: <code>, sb, sq }
    , which you handle without tearing down the whole feed. Load the stream's doc page for the exact per-level fields (
    b
    /
    a
    ,
    mid
    ,
    tick
    ,
    cumulative_size_human
    , and so on).
  • Reconnect and re-subscribe. WebSockets drop; on reopen, resend every subscription with a backoff. Track the slot
    u
    (and
    skipped
    , which is 0 when the stream kept up) to detect gaps.
  • 订阅:
    { "op": "subscribe", "base_mint": "<mint>", "quote_mint": "<mint>" }
    ,使用 base58 mint,而不是交易对符号。
    unsubscribe
    与其对称。一个连接可复用多个交易对。
  • 帧按 slot 批量发送:
    { u: <slot>, ts, updates: [ { sb, sq, ... } ] }
    。
    updates[]
    中的每个条目都以其主体 mint(
    sb
    /
    sq
    )为键;单个交易对的错误会以内联形式返回,即
    { e: <code>, sb, sq }
    ,应单独处理该错误,而无需中断整个数据流。请加载相应数据流的文档页面,以获取确切的逐档字段(
    b
    /
    a
    、
    mid
    、
    tick
    、
    cumulative_size_human
    等)。
  • 重连并重新订阅。 WebSocket 会断开;重新打开后,应采用 backoff 重新发送每个订阅。跟踪 slot
    u
    (以及
    skipped
    ,当数据流跟得上时其值为 0),以检测数据缺口。

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
{ mediumMicroLamports, highMicroLamports, veryHighMicroLamports }
object (the same shape as
GET /priority-fees
), and this stream is not gated. Details: load
/resources/trading-api/websockets/priority-fees-stream
via the docs MCP.
priority-fees 数据流的工作方式不同于 quote 和 book:无需发送 subscribe 消息,只需连接并读取。每条消息都是一个扁平对象
{ mediumMicroLamports, highMicroLamports, veryHighMicroLamports }
(其结构与
GET /priority-fees
相同),并且此数据流不受访问限制。详情:请通过文档 MCP 加载
/resources/trading-api/websockets/priority-fees-stream
。

Caveats: 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
/order
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
/order
(see
dflow-spot-trading
).
订单簿和报价档位是近似值:订单簿仅包含直接路由(10 档);quotes 由直接路由加一跳路由计算得出,参考约 $10 USDC 的往返交易规模。它们可能与交易时实际的
/order
报价不同。不要将其描述为交易所级别的订单簿或可执行价格。若需要用户实际获得的价格,请请求
/order
报价(参见
dflow-spot-trading
)。

What to ASK

需要询问的信息

  • API key. Ask neutrally: "Do you have a DFlow API key?" It's one key for everything DFlow (the same
    x-api-key
    across the REST APIs and the WebSocket streams). Yes: prod
    wss://quote-api.dflow.net
    . No: dev
    wss://dev-quote-api.dflow.net
    (rate-limited, for testing). Prod key:
    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
    。没有:使用开发环境
    wss://dev-quote-api.dflow.net
    (有速率限制,仅用于测试)。生产环境 key:
    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 (
/resources/trading-api/websockets/*
). Runnable reference: the DFlow order-book-visualization demo (a complete
/book-stream
plus proxy build), plus docs recipes
/spot/recipes/stream-order-book
and
/spot/recipes/stream-quotes
.
各数据流的消息 schema、ping/keepalive、优先费字段:文档 MCP(
/resources/trading-api/websockets/*
)。可运行参考:DFlow 订单簿可视化 demo(包含完整的
/book-stream
和代理构建),以及文档 recipe
/spot/recipes/stream-order-book
和
/spot/recipes/stream-quotes
。

Sibling skills

相关 skill

  • dflow-spot-trading
    : 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
    。