get https://api.opticodds.com/api/v3/stream/copilot//odds
Description
This endpoint provides an alternative to polling the /copilot/fixtures/odds
endpoint and allows you to passively listen for updates. This endpoint leverages the SSE responses of the http protocol.
Specific Parameter Information
include_fixture_updates
This will return any status or start date changes for fixtures that meet the criteria of the passing in data.
Best Practices
While our endpoint supports passing multiple leagues and game ids, we recommend grouping up to 10 leagues per connection.
Example Requests
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/copilot/basketball/odds",
params={
"key": "1234-5678-124",
"market": ["Moneyline"],
"league": ["NCAAB"],
# "is_main": True,
},
stream=True,
)
client = sseclient.SSEClient(r)
for event in client.events():
if event.event == "copilot-odds":
data = json.loads(event.data)
print("copilot-odds data", ":", data)
elif event.event == "copilot-locked-odds":
data = json.loads(event.data)
print("copilot-locked-odds 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
Node.js
const EventSource = require("eventsource"); // npm install eventsource
const url = "https://api.opticodds.com/api/v3/stream/copilot/basketball/odds";
const params = {
key: "1234-5678-124",
market: ["Moneyline"],
league: ["NCAAB"],
};
function connectToStream() {
// Construct the query string with repeated parameters
const queryString = new URLSearchParams();
queryString.append("key", params.key);
params.sportsbook.forEach((sportsbook) =>
queryString.append("sportsbook", sportsbook)
);
params.market.forEach((market) => queryString.append("market", market));
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("copilot-odds", function (event) {
const data = JSON.parse(event.data);
console.log("odds data:", data);
});
eventSource.addEventListener("copilot-locked-odds", function (event) {
const data = JSON.parse(event.data);
console.log("locked-odds 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: 2024-08-28T18:57:49Z
Copilot Odds Event
event: copilot-odds
id: 1730079534820-2
retry: 5000
data: { "entry_id": "1678113258940-2", "data": [ { "fixture_id": "4825158B6424", "game_id": "16903-41811-2024-10-22", "grouping_key": "default:104.5", "id": "1:-1:4825158B6424:1st_half_total_points:over_104_5", "is_main": false, "league": "NBA", "market": "1st Half Total Points", "name": "Over 104.5", "odd_id": "4825158B6424:1st_half_total_points:over_104_5", "player_id": "", "points": 104.5, "price": -196, "selection": "", "selection_line": "over", "sport": "basketball", "team_id": "", "timestamp": 1729646525, "version_id": -1 } ], "type": "copilot-odds" }
Copilot Locked Odds Event
event: copilot-locked-odds
id: 1730079527180-0
retry: 5000
data: { "entry_id": "1682600339900-0", "data": [ { "fixture_id": "D86AB59E8025", "game_id": "19370-30354-2024-10-23", "grouping_key": "miami_heat:105.5", "id": "1:-1:D86AB59E8025:team_total:miami_heat_over_105_5", "is_main": true, "league": "NBA", "market": "Team Total", "name": "Miami Heat Over 105.5", "odd_id": "D86AB59E8025:team_total:miami_heat_over_105_5", "player_id": "", "points": 105.5, "price": -103, "selection": "Miami Heat", "selection_line": "over", "sport": "basketball", "team_id": "26BB4DC5722F", "timestamp": 1729646600, "version_id": -1 } ], "type": "copilot-locked-odds" }
Copilot Settled Odds Event
event: copilot-settled-odds
id: 1730079534820-2
retry: 5000
data: { "entry_id": "1682600339900-0", "data": [ { "fixture_id": "D86AB59E8025", "game_id": "19370-30354-2024-10-23", "id": "1:-1:D86AB59E8025:team_total:miami_heat_over_105_5", "league": "NBA", "market": "Team Total", "name": "Miami Heat Over 105.5", "odd_id": "D86AB59E8025:team_total:miami_heat_over_105_5", "player_id": "", "sport": "basketball", "team_id": "26BB4DC5722F", "timestamp": 1729646600, "settlement": "Won", "settled_at": "2024-07-16T22:00:00+00:00", "version_id": -1 } ], "type": "copilot-settled-odds" }
Fixture Status Updates (Game Time Change)
This will only be sent if you have include_fixture_updates=true
event: fixture-status
id: 1724871720243-0
retry: 5000
data: {"data":{"fixture":{"away_team_display":"Lorenzo Musetti","game_id":"88067-26534-2024-35","home_team_display":"Miomir Kecmanovic","id":"FB0D30DCDD6C","start_date":"2024-08-28T20:30:00+00:00"},"fixture_id":"FB0D30DCDD6C","game_id":"88067-26534-2024-35","league":"ATP","new_start_date":"2024-08-28T20:30:00+00:00","new_status":null,"old_start_date":"2024-08-28T20:20:00+00:00","old_status":null,"sport":"tennis","timestamp":1724871720.2406485},"entry_id":"1724871720243-0"}
Fixture Status Updates (Status Change)
This will only be sent if you have include_fixture_updates=true
event: fixture-status
id: 1724871720243-0
retry: 5000
data: { "data": { "fixture": { "away_team_display": "Saisai Zheng", "game_id": "30697-79652-2024-35", "home_team_display": "Jessika Ponchet", "id": "E145B23767E0", "start_date": "2024-08-27T15:00:00+00:00" }, "fixture_id": "E145B23767E0", "game_id": "30697-79652-2024-35", "league": "WTA", "new_start_date": null, "new_status": "cancelled", "old_start_date": null, "old_status": "unplayed", "sport": "tennis", "timestamp": 1724761586.2172334 }, "entry_id": "1724761586216-0" }