> ## Documentation Index
> Fetch the complete documentation index at: https://oddspapi-v4.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket and Live Odds on v4: Polling Guide

> How to keep odds fresh with the OddsPapi v4 REST API: polling intervals, rate limits and caching. WebSocket streaming is part of the v5 enterprise API.

> [!NOTE]
>
> **v4 is a REST API without a WebSocket.** WebSocket streaming is part of the v5 API.

On v4 you keep data fresh by **polling**: you ask again, on a schedule you choose. This page shows how to do it well, and when you have outgrown it.

## How fast can I poll?

Each endpoint has a minimum wait between two calls from the same key:

| Endpoint | Rate limit (minimum wait between two calls) |
| - | - |
| `/v4/odds`, `/v4/fixture` | 0.5 seconds |
| `/v4/odds-by-tournaments`, `/v4/scores` and the reference endpoints | 1 second |
| `/v4/fixtures`, `/v4/settlements` | 2 seconds |
| `/v4/historical-odds` | 5 seconds |

Call sooner and you get `429 RATE_LIMITED` with a `retryMs` field that tells you how long to wait. See [rate limits](https://oddspapi-v4.mintlify.site/docs/errors.md#rate-limits). In practice your **request allowance** decides how often you can poll, because every poll is one request. See [Requests & quota](https://oddspapi-v4.mintlify.site/docs/requests-and-quota.md).

## Polling that doesn't burn your quota

1. **Poll only what is about to matter.** Ask [`/v4/fixtures`](https://oddspapi-v4.mintlify.site/docs/get-fixtures) for a date range with `hasOdds=true`, then poll odds just for the events you act on.
2. **Slow down far from kick-off.** Poll rarely days ahead and more often in the last hour.
3. **Use the widest call that fits.** [`/v4/odds-by-tournaments`](https://oddspapi-v4.mintlify.site/docs/get-odds-by-tournaments) returns a whole league for one bookmaker in one request. [`/v4/odds`](https://oddspapi-v4.mintlify.site/docs/get-odds) returns one event for several bookmakers in one request.
4. **Cache reference data.** Fetch sports, bookmakers, markets and languages once a day, not once per loop.
5. **Diff on `changedAt`.** Compare each price's `changedAt` with what you stored and only react when it moved.
6. **Use history instead of recording.** [`/v4/historical-odds`](https://oddspapi-v4.mintlify.site/docs/get-historical-odds) gives you the price changes of an event and does not use your quota.

## A simple polling loop

```python Python theme={null}
import os
import time
import requests

BASE = "https://api.oddspapi.io/v4"
KEY = os.environ["ODDSPAPI_KEY"]
seen = {}

def poll(fixture_id, bookmakers="bet365,1xbet"):
    r = requests.get(
        f"{BASE}/odds",
        params={"fixtureId": fixture_id, "bookmakers": bookmakers, "apiKey": KEY},
    )
    if r.status_code == 429:
        body = r.json()
        error = body.get("error", body)
        if error.get("code") == "RATE_LIMITED":
            time.sleep(error.get("retryMs", 1000) / 1000)
            return
        raise SystemExit("Monthly request allowance used up")
    r.raise_for_status()

    for book, data in r.json()["bookmakerOdds"].items():
        for market_id, market in data["markets"].items():
            for outcome_id, outcome in market["outcomes"].items():
                for player_id, price in outcome["players"].items():
                    key = (book, outcome_id, player_id)
                    if seen.get(key) != price["changedAt"]:
                        seen[key] = price["changedAt"]
                        print(book, market_id, outcome_id, player_id, price["price"])

while True:
    poll("id1000001761301153")
    time.sleep(30)  # one request every 30 seconds
```

```javascript JavaScript theme={null}
const BASE = "https://api.oddspapi.io/v4";
const KEY = process.env.ODDSPAPI_KEY;
const seen = new Map();
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function poll(fixtureId, bookmakers = "bet365,1xbet") {
  const res = await fetch(
    `${BASE}/odds?fixtureId=${fixtureId}&bookmakers=${bookmakers}&apiKey=${KEY}`
  );
  if (res.status === 429) {
    const body = await res.json();
    const error = body.error ?? body;
    if (error.code === "RATE_LIMITED") return sleep(error.retryMs ?? 1000);
    throw new Error("Monthly request allowance used up");
  }
  if (!res.ok) throw new Error(`HTTP ${res.status}`);

  const { bookmakerOdds } = await res.json();
  for (const [book, data] of Object.entries(bookmakerOdds)) {
    for (const [marketId, market] of Object.entries(data.markets)) {
      for (const [outcomeId, outcome] of Object.entries(market.outcomes)) {
        for (const [playerId, price] of Object.entries(outcome.players)) {
          const key = `${book}:${outcomeId}:${playerId}`;
          if (seen.get(key) !== price.changedAt) {
            seen.set(key, price.changedAt);
            console.log(book, marketId, outcomeId, playerId, price.price);
          }
        }
      }
    }
  }
}

while (true) {
  await poll("id1000001761301153");
  await sleep(30_000); // one request every 30 seconds
}
```

A loop like this uses 120 requests per hour for one event.

## When polling stops being enough

Polling fits odds comparison, pre-match models, alerts and dashboards. If you need every price change pushed the moment it happens, for example for in-play trading across many events, the v5 WebSocket does that.

> [card] [WebSocket API docs (v5)](https://docs.oddspapi.io/websocket/overview)
>
> Connect, authenticate and stream live odds, scores and fixtures in real time.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.