Guide / API quote in JavaScript

API quote in JavaScript

Dal team di dino.markets · Aggiornato il 25 nov 2026

Questo script chiede le moneyline NBA a due bookmaker, scorre tutte le pagine e stampa una riga per ogni bookmaker. Richiede Node.js 18 o successivo e nessun pacchetto. L’output qui sotto viene da Node.js 24.

Imposta la chiave

Crea una chiave nella dashboard ed esportala come DINO_API_KEY. Lo script la invia nell’header Authorization: Bearer.

Esegui lo script

Salva questo come odds.mjs ed esegui node odds.mjs.

const url = new URL("https://api.dino.markets/v2/odds");
url.search = new URLSearchParams({ league: "nba", markets: "moneyline", books: "draftkings,fanduel", limit: "5" });
const headers = { Authorization: `Bearer ${process.env.DINO_API_KEY}` };

let cursor = null;
do {
  if (cursor) url.searchParams.set("cursor", cursor);
  const response = await fetch(url, { headers });
  const body = await response.json();
  if (!response.ok) throw new Error(`${response.status} ${body.error}: ${body.message}`);

  for (const event of body.events) {
    if (new Date(event.start_time) <= new Date()) continue; // only games that have not started
    const team = Object.fromEntries(event.participants.map((p) => [p.role, p.name]));
    console.log(`${team.away} at ${team.home}, ${event.start_time}`);
    for (const book of event.books) {
      const prices = book.markets[0].outcomes.map((o) => `${o.name} ${o.american}`);
      console.log(`  ${book.name}: ${prices.join(", ")}`);
    }
  }
  cursor = body.next_cursor;
  if (!cursor) console.log(`${response.headers.get("x-requests-remaining")} credits left`);
} while (cursor);

Le prime due partite e l’ultima riga, eseguito il 25 nov 2026 alle 03:33 UTC:

Output
Miami Heat at Philadelphia 76ers, 2026-11-25T22:10:00Z
  DraftKings: Philadelphia 76ers -116, Miami Heat -102
  FanDuel: Philadelphia 76ers -104, Miami Heat -112
Chicago Bulls at Charlotte Hornets, 2026-11-26T00:10:00Z
  DraftKings: Charlotte Hornets -163, Chicago Bulls +137
  FanDuel: Charlotte Hornets -158, Chicago Bulls +134
...
999960 credits left

Scorri le pagine delle partite

limit accetta da 1 a 100 partite ed è 25 se lo ometti. Finché next_cursor non è null, rimandalo come cursor con gli stessi filtri. Lo script usa 5 per mostrare il ciclo.

Conta i crediti

Ogni pagina letta dallo script è una chiamata e costa 1 credito, quindi un limit più alto legge le stesse partite con meno crediti. GET /v2/events elenca le stesse partite senza prezzi ed è gratuito.

Leggi gli errori

Una risposta di errore contiene error, message e request_id. Con una chiave errata lo script si ferma con questa riga:

Output
Error: 401 unauthorized: API key is invalid or not tied to a subscription.

La pagina degli errori elenca tutti i codici.

Domande

Esiste un SDK JavaScript?

No. L'API è semplice JSON via HTTPS, quindi basta la fetch integrata.

Posso chiamarla da una pagina web?

Chiamala dal tuo server. Chiunque veda la tua chiave può spendere i tuoi crediti.

Come ottengo una sola partita?

Chiama GET /v2/events/{id}/odds con l'id dell'evento. Costa 1 credito quando la risposta contiene un bookmaker.

Cosa devo fare con un 429?

Per rate_limited, attendi i secondi indicati da Retry-After. Per quota_exceeded, aspetta il mese successivo o cambia piano.