accessing betfair API to get horse prices

Padraic Cunningham picture Padraic Cunningham · Dec 20, 2013 · Viewed 7.9k times · Source

I would like to access certain content on betfair.com, I have been looking over the Betfair API documentation but I have no idea how to create Application Keys and sessionToken's I want to be able to go through the horseracing pages and get horse names and prices.

On a video from Pycon, "learn python through public data hacking", the Chicago transit authority had bus route info in xml format which made it easy to get any required info.

So my questions are, is there something similar in the betfair API, do I need to create application keys and sessionToken's and if so how do I do it?

I will be using Python.

Answer

mathematician1975 picture mathematician1975 · Dec 25, 2013

The following is based on my experience using the SOAP API rather than the new API-NG:

If you have an active account, you can use the free API calls at the specified calls/minute rates specified using the product ID of 82. If you want higher frequency API calls and access to those not within the free API, consider the payment option for full personal access.

You can compare products at this link.

Note that even using the free API you will incur charges even if you stay within the limits of calls per minute but exceed a number of calls per second. Details of this are here enter link description here.

For example lets say using the free API you made 60 calls to GetMarketPricesCompressed, but you did them all within one second. Your calls would succeed but subsequent calls would fail due to exceeding the throttle of 60 per second - at least until a minute elapses. Even though you adhere to the API limits you would still be in danger of exceeding the data usage limits and run the risk of getting charged. I have made this mistake before myself when delpoying a betfair application - I once omitted a sleep call from my code and the above example is exactly what happened in my app.

Note also that the betfair documentation here states that the SOAP API 6.0 is being pulled in November 2014 and encourages the use of the API-NG.

As for your question regarding the session tokens, you will receive this with a successful call of the API Login method using a registered (and active) betfair user account. In my experience active usually means an account with greater than 100 betfair points.

For getting the horse runners and prices you will want combinations of GetMarket to get runner names and IDs followed by GetMarketPrices and/or GetMarketPricesCompressed to get the prices themselves. You can also use GetMarketTradedVolume and its compressed alternative if you want a full breakdown of all money matched across all prices at the time the call is made. Using this you can get the rough equivalent of the candlestick charts used for tracking stocks and shares. Note that horse racing is tricky as non-runners introduce a reduction factor across all historical prices matches of all remaining runners when a horse is removed from the market. This can be very tricky to deal with.

If you have further questions there is the betfair developers forum itself as well as a number of betfair bot forums where you can ask seasoned betfair bot programmers (as well as about APIs for other betting exchanges too)