On the wire · 04:52:55 UTC Live 550 · Prematch 14,382 · Markets 56,946 Vol. I · No. 5 · Friday 13 November 2026 wss://pinnfeed.io/v1/stream
PinnFeed
Risposta · Node · Riconnessione

WebSocket delle quote Pinnacle in Node.js: riconnessione

Aggiornato il · PinnFeed · 2 min di lettura

Risposta: su close, attendi min(delay*2, 30000) + jitter ms, apri un nuovo socket, reinvia subscribe e ricostruisci lo stato dal nuovo snapshot (svuota le mappe quando part === 1). Rispondi sempre al ping del server con {"type":"pong"}, altrimenti il server ti disconnette dopo circa 60 s. Serve il piano Builder (99 €/mese). File di riferimento: stream.mjs nella guida Python e Node.

Schema di riconnessione#

// Example — npm install ws; export PINNFEED_KEY=...
import WebSocket from 'ws';

const WS_URL = process.env.PINNFEED_WS || 'wss://pinnfeed.io/v1/stream';
const KEY = process.env.PINNFEED_KEY;
const events = new Map();
const markets = new Map();

function connect(delay = 1000) {
  const ws = new WebSocket(WS_URL, { headers: { 'x-api-key': KEY } });
  ws.on('open', () => {
    delay = 1000;
    ws.send(JSON.stringify({
      type: 'subscribe',
      sports: ['soccer', 'tennis'],
      markets: ['moneyline'],
      main: true,
      specials: false,
    }));
  });
  ws.on('message', (raw) => {
    const msg = JSON.parse(raw);
    if (msg.type === 'ping') return ws.send('{"type":"pong"}');
    if (msg.type === 'snapshot') {
      if (msg.part === 1) { events.clear(); markets.clear(); }
      msg.events.forEach((e) => events.set(e.id, e));
      msg.markets.forEach((m) => markets.set(m.id, m));
      if (msg.final) console.log(`book ready: ${events.size} events, ${markets.size} markets`);
    }
    // apply deltas the same way as in the full stream.mjs
  });
  ws.on('close', (code) => {
    const wait = Math.min(delay * 2, 30000);
    console.log(`closed (${code}); reconnecting in ${wait / 1000}s`);
    setTimeout(() => connect(wait), wait + Math.random() * 1000);
  });
}
connect();

Il codice di chiusura 1001 (server_shutdown) indica un deploy: riconnettiti con backoff (docs WebSocket). Evita la corsa simultanea: il jitter conta.

Piani#

Builder: Prova di 3 giorni; carta richiesta, addebito dopo il giorno 3 salvo disdetta. Vedi anche: esempio Python e snapshot e delta.

Contenuto educativo per maggiorenni (18+): non pronostici né promesse di guadagno. In Italia scommetti solo con operatori autorizzati ADM.

Domande frequenti#

Devo riusare la stessa Map tra una riconnessione e l'altra?#

Svuotala sulla prima parte dello snapshot (part === 1). Altrimenti tieni mercati che il nuovo snapshot non menziona più.

Hobby può riconnettersi allo stream?#

Hobby non ha WebSocket: ricevi 403 plan_lacks_ws prima di qualsiasi logica di riconnessione.

Il piano WebSocket: Builder, 99 €/mese.

Quote Pinnacle in tempo reale su un unico WebSocket: tutti i 13 sport, tutti i mercati, quote eque senza margine e quote di chiusura. 3 giorni gratis, disdici con un clic.

Form K-1 · Free API key

Get your free API key.

One field. No password, no card: enter your email, click the link we send, and your key is on screen.

By continuing you agree to the Terms and Privacy Policy.

One free key per email. Link valid for 20 minutes.