Skip navigation links

Unified Odds SDK 2.0.61 API

The Unified Odds SDK provides a simple and efficient way to access Sportradar's odds and sport information for a bookmaker.

See: Description

Packages 
Package Description
com.sportradar.unifiedodds.sdk  
com.sportradar.unifiedodds.sdk.cfg  
com.sportradar.unifiedodds.sdk.custombetentities  
com.sportradar.unifiedodds.sdk.entities  
com.sportradar.unifiedodds.sdk.entities.markets  
com.sportradar.unifiedodds.sdk.entities.status  
com.sportradar.unifiedodds.sdk.exceptions  
com.sportradar.unifiedodds.sdk.extended  
com.sportradar.unifiedodds.sdk.oddsentities  
com.sportradar.unifiedodds.sdk.replay  
com.sportradar.utils  
The Unified Odds SDK provides a simple and efficient way to access Sportradar's odds and sport information for a bookmaker. It combines subscription of messages and RESTful API calls into a unified Java interface that hides most of the complexity including recovery.

A Basic way to use the OddsFeed

First you need to implement the SDK event listeners that will receive callbacks for each message/event.

Then to actually connect and start receiving messages you do the following:

        MyOddsFeedListener listener = new MyOddsFeedListener();
        MySDKGlobalEventsListener globalEventsListener = new MySDKGlobalEventsListener();

        OddsFeedConfiguration config = OddsFeed.getOddsFeedConfigurationBuilder()
            .setAccessToken("your-integration-token-here")
            .selectIntegration()
            .build();

        OddsFeed oddsFeed = new OddsFeed(globalEventsListener, config);

        OddsFeedSessionBuilder sessionBuilder = oddsFeed.getSessionBuilder();
        sessionBuilder.setListener(listener).setMessageInterest(MessageInterest.AllMessages).build();

        oddsFeed.open();

See OddsFeed, OddsFeedSessionBuilder, SDKGlobalEventsListener and OddsFeedListener for details.

That should be about it!

If you want to get available sport events, active tournaments, or all sports you can get the SportsInfoManager from the main OddsFeed instance:

        SportsInfoManager sportsInfoManager = oddsFeed.getSportsInfoManager();
        // Get all sports, translated in the desired locales
        for (Sport sport : sportsInfoManager.getSports()) {

        }
        // Get all soccer active tournaments, the returned data will be translated in the desired locales
        for (SportEvent tournament : sportsInfoManager.getActiveTournaments("soccer")) {

        }
        // Get all competitions scheduled for today
        for (SportEvent sportEvent : sportsInfoManager.getCompetitionsFor(new Date())) {

        }

        // Get all live competitions
        for (SportEvent sportEvent : sportsInfoManager.getLiveCompetitions()) {

        }

More Advanced Usage

Note that there is one thread handling message reception and calling your registered listener per session, so the processing within your listener should be as quick as possible to not prevent following messages from being processed.

Another more scalable way of listening to events is to have two different sessions one for high-priority messages and another for low-priority-messages. This means that the low priority messages will not prevent high-priority messages from getting processed (ex., BetSettlement is considered low-priority, OddsChange is considered high-priority). To create two different sessions for the high and low-priority messages you do the following:

        MyOddsFeedListener listener = new MyOddsFeedListener();
        MySDKGlobalEventsListener globalEventsListener = new MySDKGlobalEventsListener();

        OddsFeedConfiguration config = OddsFeed.getOddsFeedConfigurationBuilder()
            .setAccessToken("your-integration-token-here")
            .selectIntegration()
            .build();

        OddsFeed oddsFeed = new OddsFeed(globalEventsListener, config);

        OddsFeedSessionBuilder sessionBuilder = oddsFeed.getSessionBuilder();
        sessionBuilder.setListener(listener).setMessageInterest(MessageInterest.HiPrioMessagesOnly).build();
        sessionBuilder.setListener(listener).setMessageInterest(MessageInterest.LoPrioMessagesOnly).build();

        oddsFeed.open();
Note that the same listener is used for both channels, but when creating the two different sessions, different MessageInterest levels are provided. In this case, you will get two different threads doing the processing of the different types of messages.

Live Only Processing

If you wish to only process live events in your system and maybe process prematch events in a completely different system, you can do this in a similar manner.
        sessionBuilder.setListener(listener).setMessageInterest(MessageInterest.LiveMessagesOnly).build();
This kind of session will receive all messages except OddsChange happening before the game starts (you will start receiving OddsChange some minutes before the game starts) and BetSettlement resulting from confirmed results (you will still receive BetSettlments when the game ends, but only after 15minutes or even later after the game confirms the match results).

Localization

By default all the data is available in English. You can add additional desired "prefetch" languages and set the default locale with the use of the OddsFeedConfigurationBuilder (addDesiredLocales, setDefaultLocale). If you need to access a locale that was not specified as the default locale and neither added to the desired locales list, you can still access the locale translated content trough the SportsInfoManager and MarketDescriptionManager.

System Failures

The Unified Odds SDK is designed to help you handle various networking outages and Sportradar subsystem failures.

If some malfunction of the system is detected(Sportradar subsystem stops working, alive interval violations,...), the SDK will dispatch a ProducerDown event, when this happens it is advised that you disable all the markets related to this producer.

When the SDK detects that the malfunction is corrected it will automatically reconnect and request the most recent odds information and any other missed messages(a recovery request will be executed), after the recovery is completed the ProducerUp event is dispatched, after the producer is up again you can safely re-enable all the markets.

If your system crashes or if you take down/restart your system you need to provide the timestamp of the last processed message per producer, so the SDK performs the recovery for the missed messages(the max time from the last processed message can not be more than 3 days). You can do this trough the ProducerManager available on the OddsFeed instance. If the last processed message timestamp is not provided, the SDK will perform a full recovery, beware: with a full recovery you do not recover any lost BetSettlement messages!

        // as an example, we set the last message received timestamp to 2 days ago for the producer with the id 1(LiveOdds)
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -2);
        ProducerManager producerManager = oddsFeed.getProducerManager();
        producerManager.setProducerLastMessageTimestamp(1, cal.getTime().getTime());

        // session creation,...

        oddsFeed.open(); // finally we open the feed

References

For a quick start you should also check out the following pages:
Skip navigation links

Copyright © 2016–2023. All rights reserved.