Message on Telegram

Settling exchange bets from a results feed

Every market on an exchange site ends in a result: a winner, or a void. The Diamond Exch API records each result in order and keeps it for days, so your platform can settle automatically and catch up after any downtime. This guide covers the result lifecycle and a settlement routine that is safe to run more than once.

Updated 2026-11-17

A result entry

{
  "seq": 17327, "action": "SETTLED", "sport": "cricket",
  "event":  { "id": "ev_k9wtucdybikxygkh", "name": "Pakistan v Sri Lanka" },
  "market": { "id": "mk_ywxwfni42227wbyh", "name": "To Win The Toss", "type": "bookmaker" },
  "winner": { "id": "rn_jz7r79c78pm4y3dp", "name": "Sri Lanka" },
  "settledAt": "2026-11-09T04:23:43Z"
}

Match the winner by its runner id, not by name: names can change, ids never do.

The result lifecycle

ActionMeaningYour platform
SETTLEDFirst resultPay winners, close losers
CORRECTEDThe earlier result was wrongReverse, then settle to the new result
VOIDEDCancelledRefund every stake
UNSETTLEDResult withdrawnReverse and hold

The entry with the highest seq for a market is the current one.

Settling back and lay bets

// decimal odds; a bookmaker rate converts first: odds = 1 + rate / 100
function settleBet(bet, winnerRunnerId) {
  const won = bet.runnerId === winnerRunnerId
  if (bet.side === 'back') return won ? bet.stake * (bet.odds - 1) : -bet.stake
  return won ? -bet.stake * (bet.odds - 1) : bet.stake
}

Run it twice, pay once

Results reach you on the stream and through REST, and a reconnect can repeat one. Keep the last applied seq per market and skip anything not newer. Record each payout so a correction reverses exactly what was paid, in one database transaction with the new settlement.

Catching up after downtime

Call GET /v1/results?since= with the next you stored last time, and repeat while more is true. You never miss or repeat an entry. Results are kept for 7 days and guaranteed for at least 48 hours; if since is older than that you get 410 resync and start again from since=0.

let since = await db.resultsCursor()   // 0 the first time
for (;;) {
  const r = await (await get('/v1/results?since=' + since + '&limit=500')).json()
  for (const entry of r.results) await onResult(entry)   // seq check inside
  since = r.next; await db.saveResultsCursor(since)
  if (!r.more) break
}

Checking one match

GET /v1/events/{id}/results lists every market of a match as SETTLED, VOIDED or PENDING. It is a quick check before you close a match in your back office.

Common questions

Are results delayed like sandbox prices?

No. Results are never delayed, on any plan or key.

What happens to a market that closes before its result?

It leaves the event with a market-remove message; its result follows on the results feed.

Can I look up a single market?

Yes: GET /v1/markets/{id}/result returns its current result, or PENDING if there is none yet.

Related APIs

More guides