Answer · Node.js · WebSocket
Apply Pinnacle WebSocket snapshot and deltas in a Node Map
Answer: After subscribe, apply snapshot part frames into a Map keyed by market id (eventId:key), then apply each delta changes[] (upsert / remove). Full client: Python/Node guide. Needs Builder (€99/mo).
Core merge logic#
import WebSocket from "ws";
const markets = new Map(); // id -> market object
const KEY = process.env.PINNFEED_KEY;
function applyChange(ch) {
if (ch.op === "upsert" || ch.type === "upsert") {
const m = ch.market || ch.value;
markets.set(m.id, m);
} else if (ch.op === "remove" || ch.type === "remove") {
markets.delete(ch.id || ch.marketId);
}
}
const ws = new WebSocket("wss://pinnfeed.io/v1/stream", {
headers: { "x-api-key": KEY },
perMessageDeflate: true,
});
ws.on("open", () => {
ws.send(JSON.stringify({
type: "subscribe",
sports: ["soccer"],
markets: ["moneyline"],
main: true,
}));
});
ws.on("message", (buf) => {
const msg = JSON.parse(buf.toString());
if (msg.type === "ping") return ws.send(JSON.stringify({ type: "pong" }));
if (msg.type === "snapshot" || msg.part != null) {
for (const m of msg.markets || []) markets.set(m.id, m);
}
if (msg.type === "delta" && Array.isArray(msg.changes)) {
for (const ch of msg.changes) applyChange(ch);
}
});
Field names follow the WebSocket docs. Paid plans: 3-day trial; a card is required and it is charged after day 3 unless you cancel. Educational content for adults (18+).
Questions people ask#
Do I merge events the same way?#
Yes — keep a second Map for events if you need home/away metadata; snapshot and delta frames can carry both.
Why Builder?#
Free/Hobby keys get 403 plan_lacks_ws on the WebSocket. REST pollers work on Free; push needs Builder or Pro.