Git Product home page Git Product logo

unifiedoddssdkjava's Introduction

Unified Feed SDK 2.x

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.getConfigurationBuilder().setAccessToken("your-token").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

That should be 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.getConfigurationBuilder().setAccessToken("your-token").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

Further reading

unifiedoddssdkjava's People

Contributors

dhrovat avatar eroznik-sr avatar ignastraskevicius-projects avatar aursic avatar shocevarsr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.