Polling or streaming: how to fetch live odds
There are two ways to keep live odds on your site: ask for them on a timer, or hold a stream open and be told when they change. The Diamond Exch API supports both. This guide compares them and shows a polling loop that stays cheap and correct when a stream is not an option.
Updated 2026-11-17
The short answer
Stream if you can. One live stream replaces hundreds of requests a minute and delivers changes sooner. Poll when your hosting cannot hold long connections, or for a back-office job that runs every few minutes.
How they compare
| Live stream (SSE) | Polling | |
|---|---|---|
| Delay after a price moves | Usually under a second | Up to your poll interval |
| Requests | One, held open | One per interval |
| Missed updates | None: resume with Last-Event-ID | None, with the changes feed |
| Best for | Live boards and in-play | Batch jobs, simple hosting |
Polling the right way: snapshot, then changes
Do not fetch every event in full every second. Take one snapshot of up to 50 events with GET /v1/odds?events=, keep its next token, then call GET /v1/changes?since= every second or two. Each call returns only the markets that changed and a new token.
const BASE = 'https://api-sandbox.diamondexchapi.live'
const headers = { 'X-API-Key': process.env.DIAMONDEXCHAPI_KEY, 'Accept-Encoding': 'gzip' }
const get = (path) => fetch(BASE + path, { headers })
async function snapshot(ids) {
const r = await (await get('/v1/odds?events=' + ids.join(','))).json()
for (const ev of r.events) book.set(ev.id, ev)
return r.next
}
let next = await snapshot(ids)
setInterval(async () => {
const res = await get(`/v1/changes?since=${next}&events=${ids.join(',')}`)
if (res.status === 410) { next = await snapshot(ids); return } // token too old: resync
const { changes, next: n } = await res.json()
for (const c of changes) apply(c.type, c.data) // same messages as the stream
next = n
}, 1500)Save bandwidth with ETags and gzip
Single-event responses carry an ETag. Send it back as If-None-Match and you get 304 Not Modified while nothing has changed. Send Accept-Encoding: gzip on every call: event snapshots shrink about tenfold.
Rate limits
Your plan sets requests per second; going over returns 429 rate_limited with a Retry-After header. GET /v1/me shows your limits, including the shortest poll interval (minPollMs). A stream counts as one request however long it stays open.
Common questions
How often should I poll?
No faster than the minPollMs your key shows in /v1/me. Every one to two seconds on the changes feed is typical.
What does 410 resync mean?
Your token is too old to continue. Take a fresh snapshot and carry on from its token.
Can I mix both?
Yes. Many platforms stream for the live board and use REST for back-office jobs and settlement checks.