Channels
The OddsPapi WebSocket channels documentation describes them together.
Load, then apply changes
The feed channels carry changes only. They never send the current state of a fixture. Build it in three steps:1
Connect and log in
Open the socket and log in with the channels and fixtures you want. Keep the messages that arrive from now on.
2
Load the state
Read the fixtures and their odds from
/v1/{lang}, for example GET /v1/en/fixtures/odds.3
Apply the changes
Apply the messages you kept, then every new one, on top of what you loaded.
Reload on snapshot_required
When Apexium cannot guarantee that you received every change, it tells you which channels to reload:
/v1/{lang}, then keep applying the messages. This happens when:
- The feed source was interrupted and Apexium has just subscribed to it again.
- Apexium fell behind the feed by more than one second: it discards what it could not send in time rather than send old prices, and asks the clients concerned to reload.
snapshot_required is older than the state you reload.
A connection receives snapshot_required at most once every 10 seconds, which leaves you time to reload. Channels that need a reload within those 10 seconds come in one snapshot_required when they end.
What you receive
oddsandbookmakerscome for the fixtures in yourfixtureIdsonly. Following a sport or a tournament does not bring its odds.fixtures,scoresandclockscome for yourfixtureIds, and for every fixture of yourtournamentIdsandsportIds.currenciescomes to every connection on the channel.- Bookmakers. Odds carry only the bookmakers of your account, except any closed to the API. A message left with none of them is not sent.
- Language.
fixturesfollows thelangof your login. See Languages.
- Log in with its
tournamentIdsonfixtures, or read its fixtures from/v1/{lang}. - Send
{ "type": "subscribe", "fixtureIds": [...] }with the fixtures you trade, and their odds start. - Send
unsubscribefor a fixture once it is over, to free its place.
Read too slowly, get closed
Apexium sends each client what it can absorb. A connection whose send buffer stays full is closed with4002, and the other clients are not slowed down. See Close codes.
To keep up:
- Use
zstd. It makes the feed about four times smaller. See Encodings. - Read in its own task. Decode and store each message quickly; do the slow work, such as pricing or database writes, elsewhere.
- Follow what you use. Every fixture in
fixtureIdsadds its odds to your stream.