get
https://api.opticodds.com/api/v3/stream/live_stats/
Pushes a live-stats event every time the fast feed updates a fixture of the sport, with the same item as /fixtures/live_stats. Only fixtures in leagues covered by the fast feed are sent. There is no closing event: if the feed stops covering a fixture mid-game, its last event stays the latest one, so use /fixtures/results for the official result.
Description
This endpoint provides an alternative to polling the /fixtures/live_stats endpoint and allows you to passively listen for updates. This endpoint leverages the SSE responses of the http protocol.
Best Practices
While our endpoint supports passing multiple leagues and fixture ids, we recommend making a separate connection for each league you are trying to subscribe to.
- The
dataformat is the same as the items of the live-stats endpoint. - Only fixtures in leagues covered by the fast feed are sent.
Example Request
Python
Requirements
- Python 3.10.2
- requests==2.31.0
- sseclient-py==1.8.0 | Need to use this sseclient dependency: https://pypi.org/project/sseclient-py/
import requests
from requests.exceptions import ChunkedEncodingError
import json
import sseclient # pip install sseclient-py
while True:
try:
r = requests.get(
"https://api.opticodds.com/api/v3/stream/live_stats/soccer",
params={
"key": "1234-5678-124",
"league": ["Spain - La Liga 2"],
},
stream=True,
)
client = sseclient.SSEClient(r)
for event in client.events():
if event.event == "live-stats":
data = json.loads(event.data)
print("live stats data", ":", data)
else:
print(event.event, ":", event.data)
except ChunkedEncodingError as ex:
print("Disconnected, attempting to reconnect...")
except Exception as e:
print("Error:", r.status_code, r.text)
break
Example Request
Node.js
const EventSource = require("eventsource"); // npm install eventsource
const url = "https://api.opticodds.com/api/v3/stream/live_stats/soccer";
const params = {
key: "1234-5678-124",
league: ["Spain - La Liga 2"],
};
function connectToStream() {
// Construct the query string with repeated parameters
const queryString = new URLSearchParams();
queryString.append("key", params.key);
params.league.forEach((league) => queryString.append("league", league));
console.log(`${url}?${queryString.toString()}`);
const eventSource = new EventSource(`${url}?${queryString.toString()}`);
eventSource.onmessage = function (event) {
try {
const data = JSON.parse(event.data);
console.log("message data:", data);
} catch (e) {
console.log("Error parsing message data:", e);
}
};
eventSource.addEventListener("live-stats", function (event) {
const data = JSON.parse(event.data);
console.log("live stats data:", data);
});
eventSource.onerror = function (event) {
console.error("EventSource failed:", event);
eventSource.close();
setTimeout(connectToStream, 1000); // Attempt to reconnect after 1 second
};
}
connectToStream();
Example Events
Connected Event
event: connected
retry: 5000
data: ok go
Ping Event
event: ping
retry: 5000
data: 2026-11-02T18:14:31Z
Live Stats
event: live-stats
id: 1793643266755-0
retry: 5000
data: {"entry_id":"1793643266755-0","data":{"fixture_id":"20261102534707EF","status":"live","is_live":true,"period":"1H","clock":"42:33","scores":{"home":{"total":3,"periods":null,"aggregate":null},"away":{"total":1,"periods":null,"aggregate":null}}}}
Live Stats (halftime)
event: live-stats
id: 1793642622443-0
retry: 5000
data: {"entry_id":"1793642622443-0","data":{"fixture_id":"202611024A7B2F0F","status":"half","is_live":true,"period":"HALF","clock":null,"scores":{"home":{"total":0,"periods":null,"aggregate":null},"away":{"total":2,"periods":null,"aggregate":null}}}}