I've decided to have another tickle at the official API but am slightly rusty. I'm using Python and only need half a dozen functions, so i am hand-rolling rather using ZSI. Now i have a small problem with the the XML format. According to the bdp samples, a login request should look like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<login xmlns="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<request>
<locationId xmlns="">0</locationId>
<password xmlns="">bfpassword</password>
<productId xmlns="">82</productId>
<username xmlns="">bfusername</username>
<vendorSoftwareId xmlns="">0</vendorSoftwareId>
</request>
</login>
</soap:Body>
</soap:Envelope>
HOWEVER, i'm using gSOAP (a C code generator which also spits out XML files), and it generates the following XML from the WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://www.betfair.com/publicapi/types/global/v3/"
xmlns:ns1="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<SOAP-ENV:Body>
<ns1:login>
<ns1:request>
<ipAddress></ipAddress>
<locationId>0</locationId>
<password></password>
<productId>0</productId>
<username></username>
<vendorSoftwareId>0</vendorSoftwareId>
</ns1:request>
</ns1:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So the question is: should both of these requests work ok? Why are they different?
I reckon both of those will work fine, they both sort of say the same thing. I don't really know why they're different, maybe just because different soap libraries choose slightly different (but valid) ways to represent data. They may include superfluous bits. Some of the references that are in those samples aren't even needed, e.g. when I was mucking around hand rolling I chopped login down to this:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:n="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<s:Body>
<n:login>
<n:request>
<ipAddress></ipAddress>
<locationId>0</locationId>
<password></password>
<productId>82</productId>
<username></username>
<vendorSoftwareId>0</vendorSoftwareId>
</n:request>
</n:login>
</s:Body>
</s:Envelope>
I was having a few problems getting back into coding the API, so wondered if i was sending the right info. Then i read the manual and realised that i wasn't sending the SoapAction header. DOH!
What i'm doing at present is running gsoap to create the xml request files and then loading them into a global dictionary at startup, so all my requests are sat in less than 50kb of ram. It's then just a case of referencing the XML by it's key name (e.g. "login") and filling in the missing bits. Should end up with a nice lean API library that will be easy to maintain.
Very good, sounds like an interesting plan. I find that rewriting the
wheel is usually more fulfilling than writing strategies - even when my
wheels come out square... lol
Yeah, i know that some other forum users have the opinion that we should spend our time developing strategies rather than dicking about with the API but i think i'm more addicted to the programming than i am to betfair. lol
I'm having trouble with getAllMarkets and there's no obvious reason why. According to the documentation, i don't need to specify anything other than the sessionToken, yet i am getting INTERNAL_ERROR when i send the following request to https://api.betfair.com/exchange/v5/BFExchangeService:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://www.betfair.com/publicapi/types/exchange/v5/"
xmlns:ns1="http://www.betfair.com/publicapi/v5/BFExchangeService/">
<SOAP-ENV:Body>
<ns1:getAllMarkets>
<ns1:request>
<header>
<sessionToken>ABCD...</sessionToken>
</header>
<locale></locale>
<eventTypeIds>
<int>0</int>
</eventTypeIds>
<countries>
<Country></Country>
</countries>
<fromDate></fromDate>
<toDate></toDate>
</ns1:request>
</ns1:getAllMarkets>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As far as i understand, this should give me a response containing every open market?
Here's PHPs version (sorry can't be bothered formatting)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1="http://www.betfair.com/publicapi/types/exchange/v5/"
xmlns:ns2="http://www.betfair.com/publicapi/v5/BFExchangeService/">
<SOAP-ENV:Body>
<ns2:getAllMarkets>
<ns2:request>
<header>
<clientStamp>0</clientStamp>
<sessionToken>laalaa</sessionToken>
</header>
<locale xsi:nil="true"/>
<eventTypeIds xsi:nil="true"/>
<countries xsi:nil="true"/>
<fromDate xsi:nil="true"/>
<toDate xsi:nil="true"/>
</ns2:request>
</ns2:getAllMarkets>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here's my hand-rolled version (not bothered specifying any empty elements which seems to work fine)
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:n="http://www.betfair.com/publicapi/v5/BFExchangeService/">
<s:Body>
<n:getAllMarkets>
<n:request>
<header>
<clientStamp>0</clientStamp>
<sessionToken>doodoo</sessionToken>
</header>
</n:request>
</n:getAllMarkets>
</s:Body>
</s:Envelope>
It turns out that if you include a parameter, it must be set with a value. For instance, <locale></locale> will cause an error, however <locale>en</locale> is fine. Any empty parameters must be completely omitted rather than sent with no values. That's not how i understood it from the documentation but it does explain why Fred's slim version works ok. I decided to write my GetAllMarkets function to allow for any (or none) of the filters to be set.
Incidentally, how strict are the datetime formats accepted by the server? The documentation suggests something like "2009-04-09T19:52:28.972937Z", but i haven't (yet) found a one-hit way to create this in Python. Nearest i've got so far is along these lines:
fromDate = str(datetime.utcnow()).replace(" ", "T") + "Z"
Not very pretty but i suppose it works...although i'm not (yet) sure how i'd go about adding or subtracting to these date values. Does anyone have any suggestions?
Ah well, that explains that then. I guess <locale></locale> actually specifies an (invalid) empty string rather than total absence of value.
I used this date calculation:
future = datetime.datetime.today() + datetime.timedelta(3) #3 days (72 hours) ahead
toDate = future.strftime("%Y-%m-%dT%H:%M:%S.000Z")
There you go fred, 1000th post. try making a frosty piss out of that!
huh? according to what i'm seeing, this forum has 1200 posts in total?
1.01 that alan is a little inebriated. lol
ahaha, I dunno whether I was or wasn't back then, but the General Discussion fora (?) hit 1000 posts with freds.
I have no idea why I noticed that, the number just jumped out at me.
On a slightly different, yet still XML related note, has anyone ever looked into using the twitter API to get hold of live football scores? Its something I've been looking into recently, there are a couple of tags being used on the site which follow matches as they are played, I'm thinking about ways I can hook them into my bot.
I promise, no matter how much it might look like it, I'm not drunk now.
Alan
Hi
I'm new to the Betfair API, but have used the .NET tutorial in the Betfair Developers Forum to generate a working C# bot application (in a rather "paint-by- numbers" fashion).
For no particularly good reason I now want to hand-roll a C# .NET Betfair API application. I have used some of the XML snippets above to try and generate a login, but my requests are returned with a Java Exceception - "MethodNotFound" or somesuch. I suspect it has to do with my XML construction - I just generate a (XML) string, encode it and send it with the .NET WebClient object. Am I missing something about XML creation?
I know this isn't quite on-topic, but I'd be grateful for a pointer or two.
Thanks
Chris
Do you realise that Visual Studio will do all the work for you if you point it at the WSDL uri (https://api.betfair.com/global/v3/BFGlobalService.wsdl)
Do you really find hand-rolling XML fun? Wierd!
Do you really find hand-rolling XML fun? Wierd!
-bennean
It's a performance thing.
Hi
Thanks bennean. Yes I have done the VS wsdl thing, and it all works. The reasons I want to hand-roll is partly for performance, partly to educate myself, and partly to make my code base more language and o/s portable.
Thanks birchy.
I think my first question is: "Is the XML sent as a WebRequest POST merely a byte-encoded string"? Or is there somethong more complex going on?
Thanks
Chris
This Topic Is Locked To Guest Posts
It's been a while since this topic was active, if you'd like to get it going again, please post as a registered member