API से odds की अपनी history संभाल कर रखें

API current prices के साथ जवाब देता है। उनकी history रखने के लिए, अपनी जरूरत के हिसाब से data मांगें और हर बदलाव पर एक line save करें: जानिए कैसे काम करता है, क्या खर्च आता है और क्या मिस हो सकता है।

6 मिनट में पढ़ें ·

API हर market का current price लौटाता है, और हर price में उसके आखिरी बदलाव का time होता है। यह कोई tick-by-tick history नहीं रखता: अगर आपको हर movement चाहिए, तो हर request से मिलने वाले data को store करें।

उन मैचों के लिए request करें जिन्हें आप track करते हैं

मैचों को match_ids में डालें। odd_type_ids और odd_period_ids के बिना जवाब में हर मैच का हर market और period शामिल होता है।

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"scope":"odds","match_ids":[13682297]}'

जवाब · 26 नव॰ 2026 को API से मिला एक जवाब, जिसकी शुरुआती रो दिखाई गई हैं। आपके अपने जवाब में अलग ids होंगी: उन्हें अगली रिक्वेस्ट में इस्तेमाल करें।

JSON में जवाब: उन मैचों के लिए request करें जिन्हें आप track करते हैं
{
  "status": "ok",
  "data": {
    "prematch": [
      {
        "id": 390798263,
        "active": 1,
        "match_id": 13682297,
        "event_id": 72533074,
        "bookmaker": {
          "id": 59,
          "name": "Bet8"
        },
        "datetime": "2026-11-26T01:35:42",
        "period_id": 0,
        "type_id": 11,
        "order": 1,
        "back_lay_id": 0,
        "liquidity": -1,
        "hc": 0,
        "hc_as_draw": 0,
        "price": 1.231,
        "nav": "{\"v\":1,\"scope\":\"prematch\",\"eventId\":\"18450709\",\"oddId\":\"4..."
      },
      {
        "id": 390634623,
        "active": 1,
        "match_id": 13682297,
        "event_id": 72531615,
        "bookmaker": {
          "id": 34,
          "name": "Trbet"
        },
        "datetime": "2026-11-26T01:36:24",
        "period_id": 0,
        "type_id": 9,
        "order": 1,
        "back_lay_id": 0,
        "liquidity": -1,
        "hc": 2,
        "hc_as_draw": 0,
        "price": 1.14,
        "nav": "{\"v\":1,\"scope\":\"prematch\",\"eventId\":\"42575268\",\"oddId\":\"7..."
      }
    ],
    "inplay": []
  },
  "time": "2026-11-26T15:28:39",
  "ms": "14.74ms"
}

हर बदलाव पर एक line

हर price अपने खुद के id के साथ एक row है। जब इसका price या datetime उस id के लिए लिखी गई आखिरी line से अलग हो, तो एक नई line लिखें: हर दिखे बदलाव पर एक line।

Feed से हटने वाले prices

जो price अब जवाब में नहीं है, वह suspend या close हो चुका है। इसके id के लिए odds_seen से पूछें और इसका closed time save करें।

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"scope":"odds_seen","odd_ids":[390798263,390634623,400751435]}'

जवाब · 26 नव॰ 2026 को API से मिला एक जवाब, जिसकी शुरुआती रो दिखाई गई हैं।

JSON में जवाब: Feed से हटने वाले prices
{
  "status": "ok",
  "data": [
    {
      "id": 390798263,
      "open": "2026-11-26T01:35:42",
      "seen": "2026-11-26T15:28:15",
      "closed": ""
    },
    {
      "id": 390634623,
      "open": "2026-11-26T01:36:24",
      "seen": "2026-11-26T15:27:23",
      "closed": ""
    }
  ],
  "time": "2026-11-26T15:29:36",
  "ms": "55us"
}

Polling का खर्च क्या है

हर poll आपकी key की limit के खिलाफ एक request माना जाता है, और लंबी match list कई requests के बराबर होती है: नीचे दी गई row बताती है कैसे। उतनी ही बार पूछें जितनी आपकी जरूरत है, उससे ज्यादा नहीं: दो गुना ज्यादा पूछने पर दो गुना requests लगेंगी। आपकी key की limit services page पर है। जब किसी refusal का Retry-After एक घंटे से ज्यादा का समय मांगे, तो नीचे दिया गया script रुक जाता है और इंतज़ार करने के बजाय API का अपना message print करता है।

एरर रेस्पॉन्स
HTTP स्टेटसमतलब
429Rate limit exceeded, 8 requests of your key already being answered, a Free key's requests for the month used up (until the 1st of the next month, UTC; the error field names the plans), Free keys busy together, or the service busy for a few seconds; check Retry-After and slow down. Retry-After: the seconds to wait before asking again, at most a day; the message names the day the month renews. Long id lists count as several requests against your per-minute limit: an odds request counts once for every 25 match ids, any other id list once for every 100 ids, and the counts multiply. One request can count as at most 40, and never as more than your key's limit for a minute.

Polling से क्या मिस होता है

Poll हर price को उस वक्त की स्थिति में देखता है जब request की जाती है। जो price दो polls के बीच दो बार बदला है, वह सिर्फ अपनी आखिरी value दिखाता है, और datetime बताता है कि वह आखिरी बदलाव कब हुआ था। आपके दो requests के बीच जो होता है, वही मिस हो सकता है।

पूरा loop एक script में

यह script आपके दिए गए मैचों को poll करता है और एक file में हर बदलाव पर एक JSON line जोड़ता है, साथ ही जवाब से हटने वाले हर price के closing time की line भी जोड़ता है। यह ODDFEEDS_KEY से आपकी key पढ़ता है और हर मिनट पूछना शुरू करता है, जब तक कि ODDFEEDS_EVERY में कुछ और न लिखा हो।

// Keep your own history: ask for the prices of some matches every EVERY_S seconds and
// append one JSON line per change you saw to a file. Stop it with Ctrl+C.
//   ODDFEEDS_KEY=<your key> node your-own-history.mjs <file> <match id> ...
import { appendFileSync } from 'fs';

const API = process.env.ODDFEEDS_URL || 'https://oddfeeds.com/api/v1/feeds';
const [file, ...ids] = process.argv.slice(2);
const matchIds = ids.map(Number);
const EVERY_S = Number(process.env.ODDFEEDS_EVERY || 60); // as often as you need
const ROUNDS = Number(process.env.ODDFEEDS_ROUNDS || Infinity);
const sleep = (s) => new Promise((r) => setTimeout(r, s * 1000));
const write = (line) => appendFileSync(file, `${JSON.stringify(line)}\n`);

const MAX_WAIT_S = 3600; // a longer Retry-After ends the program

// The seconds a 429 or 5xx asks to wait: Retry-After in seconds or as a date;
// anything else (none, 0, a date gone by, text) gets our own wait, longer each time.
function waitOf(res, wait) {
  const v = (res.headers.get('Retry-After') || '').trim();
  const s = /^\d+$/.test(v) ? Number(v) : Math.ceil((Date.parse(v) - Date.now()) / 1000);
  return s >= 1 ? s : wait;
}

// One request; on 429 it waits the seconds of Retry-After, on a 5xx longer each time.
async function ask(body) {
  for (let wait = 2; ; wait = Math.min(wait * 2, 60)) {
    const res = await fetch(API, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.ODDFEEDS_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(body),
    });
    if (res.status === 429 || res.status >= 500) {
      const s = waitOf(res, wait);
      if (s > MAX_WAIT_S) {
        const why = await res.json().then((f) => f.error, () => null);
        throw new Error(`${res.status}: ${why || `retry after ${s} s`}`);
      }
      console.log(`${res.status}: waiting ${s} s`);
      await sleep(s);
      continue;
    }
    const feed = await res.json();
    if (feed.status !== 'ok') throw new Error(`${res.status}: ${feed.error}`);
    return feed;
  }
}

const last = new Map(); // odd id -> price and datetime of the last line written for it
for (let round = 1; round <= ROUNDS; round++) {
  const odds = await ask({ scope: 'odds', match_ids: matchIds });
  const rows = [...odds.data.prematch, ...odds.data.inplay];
  const polled = new Date().toISOString();
  let lines = 0;
  for (const r of rows) {
    const now = `${r.price}|${r.datetime}`;
    if (last.get(r.id) === now) continue;
    last.set(r.id, now);
    write({
      id: r.id, match_id: r.match_id, bookmaker: r.bookmaker.name,
      type_id: r.type_id, period_id: r.period_id, hc: r.hc,
      back_lay_id: r.back_lay_id, order: r.order,
      price: r.price, datetime: r.datetime, polled,
    });
    lines++;
  }
  // A price that left the answer was suspended or closed: keep when it closed.
  const here = new Set(rows.map((r) => r.id));
  const gone = [...last.keys()].filter((id) => !here.has(id));
  for (let i = 0; i < gone.length; i += 500) {
    const seen = await ask({ scope: 'odds_seen', odd_ids: gone.slice(i, i + 500) });
    for (const s of seen.data) write({ id: s.id, closed: s.closed, polled });
  }
  for (const id of gone) last.delete(id);
  console.log(`Round ${round}: ${rows.length} prices, ${lines} lines written`);
  if (round < ROUNDS) await sleep(EVERY_S);
}

आगे

betting models use case दिखाता है कि एक model API से और क्या-क्या read करता है।

इसे लाइव डेटा पर आज़माएं

फ्री अकाउंट में प्लेग्राउंड आपके ब्राउज़र में लाइव डेटा पर इन रिक्वेस्ट को रन करता है।