Como exibir odds de apostas

How to display betting odds comparison

Neste tutorial veremos como buscar e exibir odds de apostas para uma partida, comparando diferentes casas de apostas.

In this tutorial we'll see how to fetch and display betting odds for a match, comparing different bookmakers.

1. Buscar odds / Get odds

O endpoint /odds retorna as odds de apostas para uma partida específica. Precisamos passar o ID do fixture como parâmetro.

The /odds endpoint returns betting odds for a specific match. We need to pass the fixture ID as a parameter.

const API_KEY = 'YOUR_API_KEY';
const BASE = 'https://football.api.insyde.one';

async function fetchApi(endpoint, params = {}) {
  params.key = API_KEY;
  const qs = new URLSearchParams(params).toString();
  const res = await fetch(`${BASE}/${endpoint}?${qs}`);
  return res.json();
}

// Get odds for a specific fixture
const oddsData = await fetchApi('odds', { fixture: 1351266 });
console.log(`Bookmakers found: ${oddsData.response[0].bookmakers.length}`);

2. Resposta da API / API response

A resposta inclui a liga, o fixture e uma lista de bookmakers, cada um com seus tipos de aposta e odds.

The response includes the league, fixture, and a list of bookmakers, each with their bet types and odds.

{
  "response": [{
    "league": { "id": 71, "name": "Serie A", "season": 2025 },
    "fixture": { "id": 1351266, "date": "2025-09-14T21:30:00+00:00" },
    "bookmakers": [{
      "id": 8, "name": "Bet365",
      "bets": [{
        "name": "Match Winner",
        "values": [
          { "value": "Home", "odd": "2.10" },
          { "value": "Draw", "odd": "3.40" },
          { "value": "Away", "odd": "3.50" }
        ]
      }]
    }]
  }]
}

3. Tipos de apostas / Bet types

Cada bookmaker pode oferecer diversos tipos de apostas. Os mais comuns incluem:

Each bookmaker may offer several bet types. The most common ones include:

4. Comparar bookmakers / Compare bookmakers

Para montar uma tabela de comparacao, iteramos sobre os bookmakers e extraimos as odds do tipo de aposta desejado (ex: "Match Winner").

To build a comparison table, we iterate over the bookmakers and extract the odds for the desired bet type (e.g., "Match Winner").

function buildComparison(bookmakers, betName) {
  const rows = [];

  bookmakers.forEach(bk => {
    const bet = bk.bets.find(b => b.name === betName);
    if (!bet) return;

    const row = { bookmaker: bk.name };
    bet.values.forEach(v => {
      row[v.value] = parseFloat(v.odd);
    });
    rows.push(row);
  });

  return rows;
}

const comparison = buildComparison(
  oddsData.response[0].bookmakers,
  'Match Winner'
);

// Find the best odds for each outcome
const bestHome = Math.max(...comparison.map(r => r.Home));
const bestDraw = Math.max(...comparison.map(r => r.Draw));
const bestAway = Math.max(...comparison.map(r => r.Away));

console.log('Best Home:', bestHome);
console.log('Best Draw:', bestDraw);
console.log('Best Away:', bestAway);

// Render as HTML table
let html = '<table><thead><tr>';
html += '<th>Bookmaker</th><th>Home</th><th>Draw</th><th>Away</th>';
html += '</tr></thead><tbody>';

comparison.forEach(row => {
  html += `<tr>
    <td>${row.bookmaker}</td>
    <td class="${row.Home === bestHome ? 'best' : ''}">${row.Home.toFixed(2)}</td>
    <td class="${row.Draw === bestDraw ? 'best' : ''}">${row.Draw.toFixed(2)}</td>
    <td class="${row.Away === bestAway ? 'best' : ''}">${row.Away.toFixed(2)}</td>
  </tr>`;
});

html += '</tbody></table>';

Saida esperada / Expected output:

Best Home: 2.15
Best Draw: 3.50
Best Away: 3.60

5. Cache e endpoints de referencia / Cache & reference endpoints

Cache: As odds de uma partida (/odds?fixture=ID) sao cacheadas por 60 segundos. Dados de referencia como bookmakers e tipos de aposta sao cacheados por 1 dia.
Fixture odds (/odds?fixture=ID) are cached for 60 seconds. Reference data like bookmakers and bet types are cached for 1 day.

A API tambem oferece endpoints de referencia para consultar a lista de bookmakers e tipos de aposta disponveis:

The API also provides reference endpoints to query available bookmakers and bet types:

// Get all available bookmakers
const bookmakers = await fetchApi('odds/bookmakers');
console.log(`Total bookmakers: ${bookmakers.results}`);

// Get all available bet types
const betTypes = await fetchApi('odds/bets');
console.log(`Total bet types: ${betTypes.results}`);

Back to Football API docs