Betfair’s lame API
Betfair may be doing well, but their SOAP api is stuck in 2002. You can see it was basically designed for Java/DotNet clients when the whole SOAP/WSDL/UDDI stack was all the range, and no-one ever thought you would want to do this stuff in Python, Ruby or anything non-enterprisely.
Well, 2009, here we are and Python, Ruby and friends are most definitely in the ascendency at the expense of their enterprisey brethren. And I want to use the Betfair API. Problem is, given the general disdain of the open source community for the whole WS-clusterfuck, there aren’t really any good SOAP libraries for dynamic languages around. I had a bad experience with soap4r [Ruby] a while back and then an even worse one with Suds [Python], where different versions of the same library returned different results on different platforms.
So here’s my own answer – use Ruby’s excellent XmlSimple library to convert your offending SOAP messages to JSON, and live in a lovely world of ruby Arrays and Hashes.
It’s not quite perfect –
- You can’t build the full SOAP message as XmlSimple/JSON doesn’t differentiate between XML elements and attributes [attributes being required in the SOAP envelope but thankfully not in the body]
- You still have to deal with all the SOAP content types within the messages; but thankfully, once converted to JSON, they’re easy to filter out
But hey, this is open source … get to work!
Basically you need to extend the BetfairApiClient class to include your own methods such as get_all_markets, implementing the bits of the API you’re interested in.
The code also contains an implementation of HTTP post which may be useful; building on the standard net/http libraries to handle HTTPS, custom headers etc.