跳转到主要内容

登录消息

连接后立即发送login消息:
{
  "type": "login",
  "apiKey": "YOUR_API_KEY"
}
规则:
  • 必须是第一条消息
  • 在10秒内发送
  • 定义所有订阅和过滤器

带频道和过滤器的登录

{
  "type": "login",
  "apiKey": "YOUR_API_KEY",
  "receiveType": "binary",
  "lang": "zh",
  "channels": ["fixtures", "scores", "odds"],
  "sportIds": [10, 11, 12, 13],
  "tournamentIds": [35430, 39351],
  "fixtureIds": ["id1103543066138356", "id1103935163991375"],
  "bookmakers": ["stake"]
}

过滤模式

字段类型描述
channelsstring[]您想要接收的流。
sportIdsnumber[]限制为这些体育运动。
tournamentIdsnumber[]限制为这些锦标赛。
fixtureIdsstring[]精确的赛事(仅限赛事范围频道)。
futureIdsstring[]特定的期货(期货范围频道)。
bookmakersstring[]仅接收这些博彩公司(博彩公司门控)。
langstring翻译语言(使用 "zh" 获取中文,默认 "en")。
receiveTypestring"json""binary"
clientNamestring可选的调试/指标标签。
serverEpochstring用于恢复。
lastSeenIdobject{ "<channel>": "<entryId>" }用于恢复。
fixtureIdfutureId这样的ID是结构化的,但在您的逻辑中应被视为不透明的。参见概念

访问权限:实时 vs 赛前

登录后,服务器会告诉您允许接收什么:
{
  "access": { "live": true, "pregame": false }
}
这些由您的apiKey决定,而不是客户端过滤器。

博彩公司门控频道

这些频道需要明确的博彩公司访问权限:
  • oddsbookmakers
  • oddsFuturesbookmakersFutures
您可以限制接收哪些博彩公司:
{
  "type": "login",
  "apiKey": "YOUR_API_KEY",
  "channels": ["odds", "bookmakers"],
  "receiveType": "binary",
  "lang": "zh",
  "bookmakers": ["stake", "pinnacle"]
}

Python示例

import asyncio, json, websockets, msgpack

WS_URL = "wss://v5.oddspapi.io/ws"
API_KEY = "your-api-key"

LOGIN = {
    "type": "login",
    "apiKey": API_KEY,
    "channels": ["fixtures", "scores", "odds"],
    "receiveType": "binary",
    "lang": "zh",
    "sportIds": [10, 11],
    "bookmakers": ["stake"],
}

async def main():
    async with websockets.connect(WS_URL) as ws:
        await ws.send(json.dumps(LOGIN))

        async for raw in ws:
            if isinstance(raw, str):
                print("CONTROL:", json.loads(raw))
            else:
                msg = msgpack.unpackb(raw, raw=False)
                print("DATA:", msg.get("channel"), msg.get("entryId"))

asyncio.run(main())