このガイドは進行中の試合のidを基に説明を進めます。取得方法は最初のリクエストで解説しています。ポーリングとは同じリクエストを繰り返し送信することであり、各レスポンスはその時点のフィードを表します。
取引対象のみをリクエストする
各リクエストはAPIキーの制限回数にカウントされるため、取引する試合をmatch_idsで、マーケットをodd_type_idsで指定してください。bookmaker_idsを使用すると、参照するブックメーカーのみにレスポンスを絞り込めます。
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":[13675188],"odd_type_ids":[2,3,4],"odd_period_ids":[1]}'const res = await fetch('https://oddfeeds.com/api/v1/feeds', {
method: 'POST',
headers: {
'Authorization': 'Bearer ofk_your_api_key',
'Content-Type': 'application/json',
},
body: JSON.stringify({"scope":"odds","match_ids":[13675188],"odd_type_ids":[2,3,4],"odd_period_ids":[1]}),
});
const feed = await res.json();import requests
res = requests.post(
'https://oddfeeds.com/api/v1/feeds',
headers={'Authorization': 'Bearer ofk_your_api_key'},
json={"scope":"odds","match_ids":[13675188],"odd_type_ids":[2,3,4],"odd_period_ids":[1]},
timeout=20,
)
feed = res.json()レスポンス例 · 2026/11/26 にAPIから取得したレスポンスです。最初の数行を表示しています。 実際のレスポンスに含まれるIDは異なります。次のリクエストには取得したIDを使用してください。
JSONレスポンス: 取引対象のみをリクエストする
{
"status": "ok",
"data": {
"prematch": [],
"inplay": [
{
"id": 401958384,
"active": 1,
"match_id": 13675188,
"event_id": 72567276,
"bookmaker": {
"id": 47,
"name": "BetfairExchange"
},
"datetime": "2026-11-26T15:21:20",
"period_id": 1,
"type_id": 3,
"order": 2,
"back_lay_id": 0,
"liquidity": 45,
"hc": -1,
"hc_as_draw": 0,
"price": 5.8,
"nav": "{\"v\":1,\"scope\":\"inplay\",\"eventId\":\"36359303\",\"url\":\"https...",
"runtime": {
"play": {
"codec": 16,
"display": "1H 16'"
},
"points": {
"home": 0,
"away": 0
}
}
},
{
"id": 401958562,
"active": 1,
"match_id": 13675188,
"event_id": 72567276,
"bookmaker": {
"id": 47,
"name": "BetfairExchange"
},
"datetime": "2026-11-26T15:21:11",
"period_id": 1,
"type_id": 3,
"order": 1,
"back_lay_id": 0,
"liquidity": 94,
"hc": 1,
"hc_as_draw": 0,
"price": 3.6,
"nav": "{\"v\":1,\"scope\":\"inplay\",\"eventId\":\"36359303\",\"url\":\"https...",
"runtime": {
"play": {
"codec": 16,
"display": "1H 16'"
},
"points": {
"home": 0,
"away": 0
}
}
}
]
},
"time": "2026-11-26T15:21:22",
"ms": "5.07ms"
}
経過時間とスコア
インプレイの価格はinplayの下に含まれ、各行にはその価格時点での経過時間とスコアを示すruntimeが付与されます。
| フィールド | 説明 |
|---|---|
runtime | In-play only: playtime + score snapshot at this price. |
datetime | When this price last changed (UTC). |
active | 1: the bookmaker offers this price. When the bookmaker suspends or closes a price, a market or a match, it leaves the feed instead of showing 0; odds_seen gives the time a price closed. |
各価格のフレッシュネス
対象とする価格のidをodds_seenに渡します。レスポンスには、ブックメーカーが各価格を公表した日時、最後に確認された日時、およびクローズされた日時が含まれます。
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":[401958384,401958562,401959094]}'const res = await fetch('https://oddfeeds.com/api/v1/feeds', {
method: 'POST',
headers: {
'Authorization': 'Bearer ofk_your_api_key',
'Content-Type': 'application/json',
},
body: JSON.stringify({"scope":"odds_seen","odd_ids":[401958384,401958562,401959094]}),
});
const feed = await res.json();import requests
res = requests.post(
'https://oddfeeds.com/api/v1/feeds',
headers={'Authorization': 'Bearer ofk_your_api_key'},
json={"scope":"odds_seen","odd_ids":[401958384,401958562,401959094]},
timeout=20,
)
feed = res.json()レスポンス例 · 2026/11/26 にAPIから取得したレスポンスです。最初の数行を表示しています。
JSONレスポンス: 各価格のフレッシュネス
{
"status": "ok",
"data": [
{
"id": 401958562,
"open": "2026-11-26T15:05:21",
"seen": "2026-11-26T15:21:22",
"closed": ""
},
{
"id": 401959094,
"open": "2026-11-26T15:05:21",
"seen": "2026-11-26T15:21:22",
"closed": ""
}
],
"time": "2026-11-26T15:21:23",
"ms": "32us"
}
| フィールド | 説明 |
|---|---|
open | When the bookmaker published this price. |
seen | When we last scanned and confirmed it. |
closed | When it disappeared, empty while still live. |
中断またはクローズされた価格はオッズのレスポンスには含まれません。フィードから削除され、closedにクローズされた時間が返されます。
APIから待機を指示された場合
429が発生した場合は、再リクエスト前にRetry-Afterヘッダーで指定された秒数だけ待機してください。1時間以上の待機が要求された場合、以下のスクリプトは停止し、APIからのメッセージを出力します。5xxエラーはすべて一時的なものとして扱い、待機時間を徐々に延ばしながら再試行してください。APIキーの制限についてはサービスページを確認してください。
| HTTPステータス | 説明 |
|---|---|
429 | Rate 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. |
502 | Feed service temporarily unavailable, retry with backoff. |
単一スクリプトによるポーリングループ
このスクリプトは、1試合の1X2価格をポーリングし、経過時間とスコア、各価格の最終変更日時および最終確認日時を出力します。APIキーをODDFEEDS_KEYから読み込み、試合IDを引数として受け取り、ODDFEEDS_EVERYで別段の指定がない限り10秒ごとにリクエストを送信します(1ラウンドあたり2リクエスト)。
// Poll the 1X2 prices of one match in play: the minute, the score, and for each
// price when it last changed and when it was last confirmed. Stop it with Ctrl+C.
// ODDFEEDS_KEY=<your key> node in-play-polling.mjs <match id>
const API = process.env.ODDFEEDS_URL || 'https://oddfeeds.com/api/v1/feeds';
const matchId = Number(process.argv[2]);
const EVERY_S = Number(process.env.ODDFEEDS_EVERY || 10); // how often: yours to choose
const ROUNDS = Number(process.env.ODDFEEDS_ROUNDS || Infinity);
const SIDE = { 2: '1', 3: 'X', 4: '2' };
const sleep = (s) => new Promise((r) => setTimeout(r, s * 1000));
const ago = (utc) => Math.round((Date.now() - Date.parse(`${utc}Z`)) / 1000);
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;
}
}
for (let round = 1; round <= ROUNDS; round++) {
const odds = await ask({
scope: 'odds',
match_ids: [matchId],
odd_type_ids: [2, 3, 4],
odd_period_ids: [1],
});
const rows = odds.data.inplay;
const rt = rows[0]?.runtime;
const play = rt ? `, ${rt.play.display}, ${rt.points.home}-${rt.points.away}` : '';
console.log(`Round ${round}: ${rows.length} prices${play}`);
if (rows.length) {
const ids = rows.slice(0, 500).map((r) => r.id);
const seen = await ask({ scope: 'odds_seen', odd_ids: ids });
const seenAt = new Map(seen.data.map((s) => [s.id, s.seen]));
for (const r of rows) {
const changed = `changed ${ago(r.datetime)} s ago`;
const at = seenAt.get(r.id);
const confirmed = at ? `, confirmed ${ago(at)} s ago` : '';
const price = `${r.bookmaker.name} ${SIDE[r.type_id]} ${r.price}`;
console.log(` ${price}: ${changed}${confirmed}`);
}
}
if (round < ROUNDS) await sleep(EVERY_S);
}# Poll the 1X2 prices of one match in play: the minute, the score, and for each
# price when it last changed and when it was last confirmed. Stop it with Ctrl+C.
# ODDFEEDS_KEY=<your key> python in-play-polling.py <match id>
import math
import os
import re
import sys
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
import requests
API = os.environ.get('ODDFEEDS_URL', 'https://oddfeeds.com/api/v1/feeds')
match_id = int(sys.argv[1])
EVERY_S = float(os.environ.get('ODDFEEDS_EVERY', 10)) # how often: yours to choose
ROUNDS = float(os.environ.get('ODDFEEDS_ROUNDS', 'inf'))
SIDE = {2: '1', 3: 'X', 4: '2'}
MAX_WAIT_S = 3600 # a longer Retry-After ends the program
def wait_of(res, wait):
"""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."""
v = res.headers.get('Retry-After', '').strip()
if re.fullmatch(r'[0-9]+', v):
s = float(v)
else:
try:
at = parsedate_to_datetime(v)
if at.tzinfo is None:
at = at.replace(tzinfo=timezone.utc)
s = math.ceil((at - datetime.now(timezone.utc)).total_seconds())
except (TypeError, ValueError):
s = 0
return s if s >= 1 else wait
def ago(utc):
then = datetime.fromisoformat(utc).replace(tzinfo=timezone.utc)
return round((datetime.now(timezone.utc) - then).total_seconds())
def ask(body):
"""One request; on 429 it waits the seconds of Retry-After, on a 5xx longer."""
wait = 2
while True:
res = requests.post(
API,
headers={'Authorization': f"Bearer {os.environ['ODDFEEDS_KEY']}"},
json=body,
timeout=20,
)
if res.status_code == 429 or res.status_code >= 500:
s = wait_of(res, wait)
if s > MAX_WAIT_S:
try:
why = res.json().get('error')
except ValueError:
why = None
raise RuntimeError(f"{res.status_code}: {why or f'retry after {s:g} s'}")
print(f"{res.status_code}: waiting {s:g} s", flush=True)
time.sleep(s)
wait = min(wait * 2, 60)
continue
feed = res.json()
if feed['status'] != 'ok':
raise RuntimeError(f"{res.status_code}: {feed['error']}")
return feed
round_no = 1
while round_no <= ROUNDS:
odds = ask({'scope': 'odds', 'match_ids': [match_id],
'odd_type_ids': [2, 3, 4], 'odd_period_ids': [1]})
rows = odds['data']['inplay']
rt = rows[0].get('runtime') if rows else None
play = ''
if rt:
score = f"{rt['points']['home']}-{rt['points']['away']}"
play = f", {rt['play']['display']}, {score}"
print(f"Round {round_no}: {len(rows)} prices{play}", flush=True)
if rows:
seen = ask({'scope': 'odds_seen', 'odd_ids': [r['id'] for r in rows[:500]]})
seen_at = {s['id']: s['seen'] for s in seen['data']}
for r in rows:
at = seen_at.get(r['id'])
confirmed = f", confirmed {ago(at)} s ago" if at else ''
print(f" {r['bookmaker']['name']} {SIDE[r['type_id']]} {r['price']}: "
f"changed {ago(r['datetime'])} s ago{confirmed}")
if round_no < ROUNDS:
time.sleep(EVERY_S)
round_no += 1次のステップ
インプレイ取引のユースケースではインプレイ取引で他に確認すべきデータ項目を解説し、ドキュメントのエラー一覧にはすべてのエラーの一覧を掲載しています。