Oddlyx LogoOddlyx

Examples

Real-world examples and common use cases for Oddlyx.

Fetching Games for Today

Get all games scheduled for today:

const today = new Date().toISOString().split('T')[0];

const response = await fetch(
  `https://odds-marketplace.onrender.com/api/v1/nba/odds/games?date=${today}`,
  {
    headers: {
      'Authorization': `Bearer ${process.env.ODDS_API_KEY}`
    }
  }
);

const { data } = await response.json();
console.log(`Found ${data.length} games today`);

Finding Best Odds

Compare odds across sportsbooks to find the best value:

const response = await fetch(
  'https://odds-marketplace.onrender.com/api/v1/nba/odds/markets/moneyline?date=2024-01-15&sort=odds',
  {
    headers: {
      'Authorization': `Bearer ${process.env.ODDS_API_KEY}`
    }
  }
);

const { data } = await response.json();

// Find best odds for each team
const bestOdds = data.reduce((acc, market) => {
  const teamId = market.team_id;
  if (!acc[teamId] || market.odds > acc[teamId].odds) {
    acc[teamId] = market;
  }
  return acc;
}, {});

Live Odds (WebSocket)

For real-time live odds, connect to the /live-odds WebSocket namespace. The server pushes updates every ~20 seconds. Optionally emit subscribe with filters.

import { io } from 'socket.io-client';

const socket = io('https://odds-marketplace.onrender.com/live-odds', {
  auth: { apiKey: process.env.ODDS_API_KEY },
  transports: ['websocket', 'polling'],
});

// Optional: filter by game, market, or book
socket.emit('subscribe', { game_id: 12345, market_type: 'moneyline' });

socket.on('live_odds', (payload) => {
  if (payload.success) {
    console.log('Live odds update:', payload.updated_at, payload.data);
  }
});

REST polling fallback

If you cannot use WebSockets, poll the REST endpoint on an interval (e.g. every 5 seconds).

async function pollLiveOdds(gameId: number) {
  const interval = setInterval(async () => {
    const res = await fetch(
      `https://odds-marketplace.onrender.com/api/v1/nba/odds/live?game_id=${gameId}`,
      { headers: { Authorization: `Bearer ${process.env.ODDS_API_KEY}` } }
    );
    const { data } = await res.json();
    console.log('Live odds update:', data);
  }, 5000);
  return () => clearInterval(interval);
}

Rate limiting

When using REST polling, avoid polling more than every 3–5 seconds; the API updates on a similar cadence.