Connect to the quote stream and read live bid/ask updates for a token pair
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.
Imports and config
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 devconst 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.
Each message is a batch covering one slot. Read the updates array, and handle the per-pair e field for pairs with no route.
Handle messages
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 secondssetTimeout(() => 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.