Question

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.

Was it helpful?

Solution

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)

OTHER TIPS

It sounds like you are looking at the API-NG which is a json interface rather than the current service which is WSDL-based. API-NG is a new service which is still in development, and in particular the documentation isn't great at the moment. For API-NG this is what I did:

  • Log in to the Betfair site using a browser with your account credentials.
  • Inspect the session's cookies (in Chrome this is in the Resources tab of the developers tools
  • find the ssoid cookie value - that is your session token to use in this test page
  • create an application key using your application name
  • use the examples code on the betfair api-ng github to get started

On the other hand, if you are happy to use the existing WSDL service, then I understand quite a few people use this free python interface to it or this open source version.

Lastly, the free service is free so long as you have a funded account and operate within the throttling limits described, which should be fine at least to get you started if not much longer depending on what you want to do.

According to the web page you need:

An active Betfair account The Free Access API productId, which is "82" - use this along with your Betfair credentials in the log-in protocol. The Betfair API WSDL URL's:

The sessionToken is returned from the login.

Note the charges for using the free API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top