The trades channel streams real-time trade execution updates for prediction markets. Use this channel to build trade feeds, activity monitors, and market analysis tools.
// Dev endpoint — no API key required, but rate-limited.// For production, use your production WS URL and add:// { headers: { "x-api-key": "YOUR_API_KEY" } }// as the second argument to new WebSocket().const WS_URL = "wss://dev-prediction-markets-api.dflow.net/api/v1/ws";const ws = new WebSocket(WS_URL);ws.onopen = () => { console.log("Connected to WebSocket"); // Subscribe to all trade updates ws.send( JSON.stringify({ type: "subscribe", channel: "trades", all: true, }) );};ws.onmessage = (event) => { const message = JSON.parse(event.data); if (message.channel === "trades") { console.log("Trade executed:", { ticker: message.market_ticker, tradeId: message.trade_id, side: message.taker_side, count: message.count, yesPrice: message.yes_price_dollars, noPrice: message.no_price_dollars, time: new Date(message.created_time).toISOString(), }); }};ws.onerror = (error) => { console.error("WebSocket error:", error);};ws.onclose = () => { console.log("WebSocket connection closed");};
Subscribe to Specific Markets
Copy
Ask AI
// Dev endpoint — no API key required, but rate-limited.// For production, use your production WS URL and add:// { headers: { "x-api-key": "YOUR_API_KEY" } }// as the second argument to new WebSocket().const WS_URL = "wss://dev-prediction-markets-api.dflow.net/api/v1/ws";// Market tickers to subscribe toconst marketTickers = ["BTCD-25DEC0313-T92749.99", "SPX-25DEC0313-T5000"];const ws = new WebSocket(WS_URL);ws.onopen = () => { console.log("Connected to WebSocket"); // Subscribe to specific tickers for trades ws.send( JSON.stringify({ type: "subscribe", channel: "trades", tickers: marketTickers, }) );};ws.onmessage = (event) => { const message = JSON.parse(event.data); console.log(`Trade on ${message.market_ticker}:`, message);};