Skip to main content
During development, the developer endpoints work without an API key. Access to the quote stream in production is gated: request an API key with quote stream access, or have an existing key upgraded.
This recipe connects to the quote stream and reads live bid and ask updates for a single pair. See Market Data Streams for how the quotes are built.
1

Set up

Import a WebSocket client, read the endpoint from the environment, and pick the pair to watch.
import "dotenv/config";
import WebSocket from "ws";

const DFLOW_TRADE_API_WS_URL =
  process.env.DFLOW_TRADE_API_WS_URL ?? "wss://dev-quote-api.dflow.net";
const DFLOW_API_KEY = process.env.DFLOW_API_KEY; // optional; not needed for dev

const SOL_MINT = "So11111111111111111111111111111111111111112";
const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
2

Connect and subscribe

Open the connection to /quote-stream and send a subscribe op once it is open. The API key header is only needed in production.
const ws = new WebSocket(
  `${DFLOW_TRADE_API_WS_URL}/quote-stream`,
  DFLOW_API_KEY ? { headers: { "x-api-key": DFLOW_API_KEY } } : undefined
);

ws.on("open", () => {
  ws.send(
    JSON.stringify({ op: "subscribe", base_mint: SOL_MINT, quote_mint: USDC_MINT })
  );
});
3

Read updates

Each message is a batch covering one slot. Read the updates array, and handle the per-pair e field for pairs with no route.
ws.on("message", (data) => {
  const frame = JSON.parse(data.toString());
  for (const u of frame.updates ?? []) {
    if (u.e) {
      console.log(`${u.sb} / ${u.sq}: ${u.e}`);
      continue;
    }
    console.log(`slot ${frame.u}  bid ${u.b}  ask ${u.a}`);
  }
});

ws.on("error", (err) => console.error("WebSocket error:", err));
ws.on("close", () => console.log("Connection closed"));

// demo only: stop after a few seconds
setTimeout(() => ws.close(), 4000);
Quotes are approximations and can briefly cross (bid above ask) between slots. Treat them as a live read on the market, not a guaranteed execution price.

Market Data Streams

How the streams work and when to use each.

Quote Stream API

Messages, fields, and the all-markets subscription.

Stream Order Book Depth

Read ten levels of depth per side.

Authenticate Requests

Authenticate requests for production rate limits.