这个脚本请求两家博彩公司的NBA独赢,遍历所有分页,每家博彩公司打印一行。需要Node.js 18或更高版本,无需任何软件包。下面的输出来自Node.js 24。
设置密钥
在控制台创建密钥,导出为DINO_API_KEY。脚本通过Authorization: Bearer请求头发送它。
运行脚本
保存为odds.mjs,运行node odds.mjs。
const url = new URL("https://api.dino.markets/v2/odds"); url.search = new URLSearchParams({ league: "nba", markets: "moneyline", books: "draftkings,fanduel", limit: "5" }); const headers = { Authorization: `Bearer ${process.env.DINO_API_KEY}` }; let cursor = null; do { if (cursor) url.searchParams.set("cursor", cursor); const response = await fetch(url, { headers }); const body = await response.json(); if (!response.ok) throw new Error(`${response.status} ${body.error}: ${body.message}`); for (const event of body.events) { if (new Date(event.start_time) <= new Date()) continue; // only games that have not started const team = Object.fromEntries(event.participants.map((p) => [p.role, p.name])); console.log(`${team.away} at ${team.home}, ${event.start_time}`); for (const book of event.books) { const prices = book.markets[0].outcomes.map((o) => `${o.name} ${o.american}`); console.log(` ${book.name}: ${prices.join(", ")}`); } } cursor = body.next_cursor; if (!cursor) console.log(`${response.headers.get("x-requests-remaining")} credits left`); } while (cursor);
前两场比赛和最后一行,运行于2026年11月25日03:33 UTC:
Miami Heat at Philadelphia 76ers, 2026-11-25T22:10:00Z DraftKings: Philadelphia 76ers -116, Miami Heat -102 FanDuel: Philadelphia 76ers -104, Miami Heat -112 Chicago Bulls at Charlotte Hornets, 2026-11-26T00:10:00Z DraftKings: Charlotte Hornets -163, Chicago Bulls +137 FanDuel: Charlotte Hornets -158, Chicago Bulls +134 ... 999960 credits left
翻页读取比赛
limit接受1到100场比赛,省略时为25。只要next_cursor不为null,就带着相同的过滤条件把它作为cursor传回。脚本用5来演示循环。
计算积分
脚本读取的每一页是一次调用,花1积分,因此limit越高,读取同样多比赛花的积分越少。GET /v2/events列出同样的比赛但不含价格,且免费。
处理错误
错误响应包含error、message和request_id。密钥错误时,脚本以下面这一行终止:
Error: 401 unauthorized: API key is invalid or not tied to a subscription.
错误页面列出了全部代码。
常见问题
有JavaScript SDK吗?
没有。API是基于HTTPS的纯JSON,内置的fetch就够用。
能从网页里直接调用吗?
请从你的服务器调用。任何看到你密钥的人都能花掉你的积分。
如何获取单场比赛?
用赛事id请求GET /v2/events/{id}/odds。响应中有博彩公司时花1积分。
遇到429该怎么办?
rate_limited时等待Retry-After指定的秒数。quota_exceeded时等到下个月或更换套餐。