您的首个 OddFeeds API 请求

从获取 API 密钥到通过四次请求获取单场比赛的赔率,每次请求的 ID 均来自上一步的响应结果。

6 分钟阅读 ·

API 的每次响应都会提供下一次请求所需的 ID:国家对应联赛,联赛对应比赛,比赛对应赔率。本指南将按顺序示范这四次请求,并解析各项响应内容。

您的 API 密钥

所有请求均为发送至单一地址的 POST 请求,请求头需包含 Authorization: Bearer 及密钥。注册账号后即可在账户页面获取密钥,服务页面 说明了具体获取方式。

1. 获取国家列表

不带 scope 的请求会列出当前包含赛前和滚球赔率的国家。

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"prematch":true,"inplay":true}'

返回结果 · API 于 2026年11月26日 返回的结果,仅展示前几行。 实际返回结果会包含其他 ID,请在下一个请求中使用对应的 ID。

JSON 返回结果: 1. 获取国家列表
{
  "status": "ok",
  "data": [
    {
      "id": 136,
      "name": "Slovakia",
      "prematch_leagues_cnt": 1,
      "inplay_leagues_cnt": 0
    },
    {
      "id": 42,
      "name": "Costa Rica",
      "prematch_leagues_cnt": 2,
      "inplay_leagues_cnt": 0
    }
  ],
  "time": "2026-11-26T15:14:19",
  "ms": "479us"
}

prematch_leagues_cnt 和 inplay_leagues_cnt 分别统计该国家拥有赛前和滚球赔率的联赛数量。请选择一个数量大于零的国家。

2. 获取国家的联赛列表

将国家的 id 传入 tournament_ids。响应将列出其包含的联赛以及拥有赔率的比赛数量。

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

返回结果 · API 于 2026年11月26日 返回的结果。 实际返回结果会包含其他 ID,请在下一个请求中使用对应的 ID。

JSON 返回结果: 2. 获取国家的联赛列表
{
  "status": "ok",
  "data": [
    {
      "id": 10618,
      "tournament_id": 136,
      "name": "Super Liga",
      "prematch_matches_cnt": 6,
      "inplay_matches_cnt": 0
    }
  ],
  "time": "2026-11-26T15:14:19",
  "ms": "400us"
}

3. 获取联赛的比赛列表

将联赛的 ID 传入 league_ids。

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

返回结果 · API 于 2026年11月26日 返回的结果,仅展示前几行。 实际返回结果会包含其他 ID,请在下一个请求中使用对应的 ID。

JSON 返回结果: 3. 获取联赛的比赛列表
{
  "status": "ok",
  "data": [
    {
      "id": 13682297,
      "league_id": 10618,
      "teams": {
        "home": "Dukla Banska Bystrica",
        "away": "MFK Ruzomberok"
      },
      "start": "2026-11-28T14:30:00",
      "active": {
        "prematch": 1,
        "inplay": 0
      },
      "stats": {
        "start": "2026-11-28T14:30:00"
      }
    },
    {
      "id": 13683299,
      "league_id": 10618,
      "teams": {
        "home": "Slovan Bratislava",
        "away": "FC Kosice"
      },
      "start": "2026-11-28T17:00:00",
      "active": {
        "prematch": 1,
        "inplay": 0
      },
      "stats": {
        "start": "2026-11-28T17:00:00"
      }
    }
  ],
  "time": "2026-11-26T15:14:20",
  "ms": "700us"
}

start 为 UTC 开赛时间。active 表示比赛当前拥有哪种模式的赔率,滚球比赛还会附带包含比赛分钟数和比分的 stats.runtime。

4. 获取单场比赛的赔率

将比赛的 ID 传入 match_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":[13682297]}'

返回结果 · API 于 2026年11月26日 返回的结果,仅展示前几行。

JSON 返回结果: 4. 获取单场比赛的赔率
{
  "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:15:19",
  "ms": "15.97ms"
}

赔率数据分为 prematch 和 inplay 两个列表(对应两种模式),每行代表某家博彩公司的单项赔率。以下是优先读取的字段:

赔率数据行字段说明
字段含义
bookmakerid + name of the source bookmaker.
type_idMarket type, see the type_id table.
period_id0 = first half, 1 = full time, 6 = second half.
hcThe handicap / total line, e.g. -0.5 or 2.5. On 1X2 rows (type_id 2, 3, 4) a non-zero hc is a European handicap line, and for correct score (type_id 66) it carries the score; see the type_id table.
priceThe odd, decimal format. On an exchange it's the price as the exchange shows it, with no commission taken off.
datetimeWhen this price last changed (UTC).

数据行中各数字代表的含义见 文档参考表。

当 API 返回错误时

以下是初次请求中最常遇到的两种 API 错误响应原文:

错误响应
HTTP 状态码含义
400A body that is not valid JSON, a malformed parameter, a scope without its id list, or id lists that count as more requests than one request may (see 429); the error field says what was wrong.
401Missing or unknown API key.

完整流程示例脚本

该脚本将按顺序执行这四次请求并传递各个 ID。脚本从环境变量 ODDFEEDS_KEY 中读取密钥,避免将密钥写入代码。

// The whole walk: the countries, a country's leagues, a league's
// matches and the odds of one match. Run it with your key:
//   ODDFEEDS_KEY=<your key> node first-request.mjs
const API = process.env.ODDFEEDS_URL || 'https://oddfeeds.com/api/v1/feeds';

async function ask(body) {
  const res = await fetch(API, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.ODDFEEDS_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body),
  });
  const feed = await res.json();
  if (feed.status !== 'ok') throw new Error(`${res.status}: ${feed.error}`);
  return feed.data;
}

const countries = await ask({ prematch: true, inplay: true });
const country = countries.find(
  (c) => c.prematch_leagues_cnt > 0 || c.inplay_leagues_cnt > 0);
if (!country) throw new Error('No country has odds right now.');

const leagues = await ask({ scope: 'leagues', tournament_ids: [country.id] });
const league = leagues.find(
  (l) => l.prematch_matches_cnt > 0 || l.inplay_matches_cnt > 0);

const matches = await ask({ scope: 'matches', league_ids: [league.id] });
const match = matches[0];

const odds = await ask({ scope: 'odds', match_ids: [match.id] });
const rows = [...odds.prematch, ...odds.inplay];

const { home, away } = match.teams;
console.log(`${country.name} / ${league.name} / ${home} - ${away}: ${rows.length} prices`);
for (const r of rows.slice(0, 5)) {
  console.log(r.bookmaker.name, r.type_id, r.hc, r.price);
}

下一步

技术文档 包含所有作用域、字段和盘口对照表,应用场景页面 展示了开发者基于这些请求构建的应用场景。

使用实时数据测试

在免费账户的测试场中,直接通过浏览器使用实时数据运行这些请求。