How to display odds (back/lay/draw) using betfair API

1.9k Views Asked by At

We have betfair API key and session key, but API documentation is relatable. We need to show data same as betfair shows. screenshot attached,

We are calling API for listMarketBook we got the data but don't know how this data will be show.

sample response:

https://gist.githubusercontent.com/manishoctal/7d30d4358ff38c56ba827f0fa4c91328/raw/ae0e7c3c008d3182dada39acdca8c7f77a1d1596/listMarketBook.json

shot

1

There are 1 best solutions below

5
On

Betfair subdivides its datasets so that one Event contains multiple Markets. Your screenshot is of an Event (Roma v AC Milan) containing multiple Markets (Match Odds, Over / Under 2.5 Goals, Half Time, Correct Score, etc.)

Your JSON example is the result of calling listMarketBook() on a single Market ID, which in this case is the Market ID (1.171451411) of Match Odds in the Lazio v Cagliari Event. Note that numberOfRunners = 3 and numberOfWinners = 1, meaning that there will only be one result from three possible outcomes: Home win, Draw, Away win. Some markets may have more than one winner (e.g.: top 3 in a horse race).

For each runner, you can bet that a team will win (back) or will not win (lay). Note that a team "not winning" includes both lose and draw results, so your question "How to display odds (back/lay/draw)" confuses terminologies. You may back or lay a runner / team - and a team may win, lose or draw - but back/lay/draw are not all related possibilities.

The three runners in the JSON example each have their own selectionId and provide price information via availableToBack and availableToLay. These include the three best prices for each of back and lay, along with the amount of money available at each price in your currency unit (e.g.: euro). This is all the price information you are likely to need.

However, you still need to know what each selection means (e.g.: selectionId 56966 in the market 1.171451411 might mean Lazio). For that, you need to call listMarketCatalogue() with the marketId you used before (e.g.: 1.171451411). You'll also need to set the MarketProjection to determine the quantity of information you require (pro-tip: ask for the minimum you require so as not to put unnecessary load on the Betfair API).

Note that you should cache / store the results of listMarketCatalogue() and not regularly make the same request; and certainly not every time you request prices from listMarketBook(). The Market Catalogue rarely-if-ever changes and Betfair does not appreciate you making repeated, identical calls to this service.