Betfair Developers


Exchange API
Discussion about the Betfair Sports Application Programming Interface - API NG

Thread Closed
AlgoTrader AlgoTrader is offline
Senior Member
 
Default

Quote:
Originally Posted by shuba View Post
To my mind XML more human eye friendly then JSON hieroglyphs
:-)
Lets compare:
Code:
<n:loginResponse xmlns:n="http://www.betfair.com/publicapi/v3/BFGlobalService/">
    <n:Result xsi:type="n2:LoginResp">
        <header xsi:type="n2:APIResponseHeader">
            <errorCode xsi:type="n2:APIErrorEnum">OK</errorCode>
            <minorErrorCode xsi:nil="1" />
            <sessionToken xsi:type="xsd:string">PKdvAW+ruIAg0s769DeM+vxY=</sessionToken>
            <timestamp xsi:type="xsd:dateTime">2007-08-23T11:25:05.285Z</timestamp>
        </header>
        <currency xsi:type="xsd:string">GBP</currency>
        <errorCode xsi:type="n2:LoginErrorEnum">OK</errorCode>
        <minorErrorCode xsi:nil="1" />
        <validUntil xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</validUntil>
    </n:Result>
</n:loginResponse>
JSON:
Code:
{
    "header": {
        "errorCode": "OK",
        "minorErrorCode": null,
        "sessionToken": "pirdDtkE/8R3LkVHBeTZEnmB31jzZsdC3E6s95inAvI=",
        "timestamp": "2012-08-24T07:13:43.324Z"
    },
    "currency": "USD",
    "errorCode": "OK",
    "minorErrorCode": null,
    "validUntil": "0001-01-01T00:00:00.000Z"
}
And tell me honest which one is easier to read? Please don't try to convince me namespaces, xsi:type attributes, closing tags help you better undertand things. Can you please explain me, how XML's '<' and '>' make things much better than JSON's '{' and '}'?

PS. The session code is not valid one
__________________
Betfair Bots Made Easy
https://github.com/AlgoTrader/betfair
AlgoTrader AlgoTrader is offline
Senior Member
 
Default

Quote:
Originally Posted by shuba View Post
I think JSON shorter, faster and simpler on 10Mb server response. But not on 1-2K Bet fair response. I think JSON lib and "ugly" SOAP lib will parse 1K for identical time.
You have to compare 50kb JSON vs 150kb XML. JSON has no namespaces, xsi attributes, closing tags, SOAP stuff. See the post above, the same response is in times shorter.

In many languages you do not need external libs to parse JSON.
PHP: json_decode function parse json to PHP var
javascript: JSON.parse method parses json into native object
C#: System.Runtime.Serialization.Json

SOAP is legacy now, fortunately, Betfair is smart enough to innovate and make things modern.

JSON response message will be parsed before XML SOAP response is fully received. The only exception is "compressed" calls, for example getAllMarkets has just one tag <marketData>... 100kb of text</marketData>. I would suggest make getAllMarkets exception and have it still text-encoded.
__________________
Betfair Bots Made Easy
https://github.com/AlgoTrader/betfair
shuba shuba is offline
Member
 
Default

Code:
xsi:type="n2:LoginErrorEnum"
This is cost of strict typification which is advantage of SOAP and weakness of Jason where typification is absent
__________________
Betting developers forum (russian speaking) - bettingdeveloper.org

BetOnDroid - ladder interface for Android platform.
shuba shuba is offline
Member
 
Default

Quote:
Originally Posted by AlgoTrader View Post
You have to compare 50kb JSON vs 150kb XML. JSON has no namespaces, xsi attributes, closing tags,
Hm.... 50 and 150K? What kind of Bet fair response you mean ?
__________________
Betting developers forum (russian speaking) - bettingdeveloper.org

BetOnDroid - ladder interface for Android platform.
AlgoTrader AlgoTrader is offline
Senior Member
 
Default

Quote:
Originally Posted by shuba View Post
Code:
xsi:type="n2:LoginErrorEnum"
This is cost of strict typification which is advantage of SOAP and weakness of Jason where typification is absent
There is no Jason it JSON.
JSON has types. Everything in "" is string, everything without "" is number, everything in {} is object, everything in [] is array.

That's enough. I code like this
Code:
var response = getAllMarkets();
if(response.errorCode!='OK') {
    // invalid response
    return;
}
// valid response
What we have with XML? DOM parser with ugly API or SAX parser that is not much better? SOAP libs that generates megabytes of complex code by generating hundreds of classes and enums? My current XML parser and serializer is some 7kb:

https://github.com/AlgoTrader/betfai...air_encoder.js
https://github.com/AlgoTrader/betfai...air_decoder.js

SOAP libs generated me megabytes of code

If you do validation of every response in app (I never seen anybody who does such validation by applying WSDL scheme) then I like your way - you increase your processing latency and make things slow.

Quote:
Originally Posted by shuba View Post
Hm.... 50 and 150K? What kind of Bet fair response you mean ?
The part of login XML response in the example above is 756 bytes. The same in JSON is 337 bytes. It is just after removing closing tags, namesapaces, attributes, etc. It includes formatting, after removing spaces XML is 652 bytes, JSON is 281 bytes. JSON is 43% of XML in this case, in more important calls the difference will be bigger.

I faced JSON several years ago and I was wondering why we need it because we already have XML? Three years later most of our modern web apps are JSON based. The benefits are so clear and convincing. I certainly prefer simplicity and speed to namespaces, schemas, WDSL, validation, types, SOAP enverlops and other stuff.
__________________
Betfair Bots Made Easy
https://github.com/AlgoTrader/betfair
wotsisname wotsisname is offline
Senior Member
 
Default

I think the easiest solution is for Betfair to introduce the JSON format API (which is what the majority of developers want) and if some other customer wants XML, she can always use a standard JSON to XML parser.
__________________
http://www.bespokebots.com
AlgoTrader AlgoTrader is offline
Senior Member
 
Default

There is no reasonable JSON->XML converter. I tried several online tools just for fun:

http://jsontoxml.utilities-online.info/
Code:
Json:
{
   "name" : "John Smith",
    "age" : 40,
    "children" : [
        { "name": "Maria" },
        { "name": "Ann" }
    ]
}
XML:
<?xml version="1.0" encoding="UTF-8" ?>
	<name>John Smith</name>
	<age>40</age>
	<children>
		<name>Maria</name>
	</children>
	<children>
		<name>Ann</name>
	</children>
The XML is not valid

http://json.online-toolz.com/tools/x...-convertor.php
Code:
JSON:
{
   "name" : "John Smith",
    "age" : 40,
    "children" : [
        { "name": "Maria" },
        { "name": "Ann" }
    ]
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<json>
<name>John Smith</name>
<age>40</age>
<children>
<name>Maria</name>
</children>
<children>
<name>Ann</name>
</children>
</json>
The XML is valid but is complete shit.

The XML->JSON converters exist and work good, although JSON contains lots of garbage - attributes, namespaces, xsi:types are still in JSON with weird encoding rules. The approach is proved to be very poor (I used it in my lib)

The JSON->XML is just complete nonsense. JSON arrays are completely destroyed while encoded in XML, XML has no "array" concept.

I will forget about XML as soon as JSON API is in usable state
__________________
Betfair Bots Made Easy
https://github.com/AlgoTrader/betfair
Fred77 Fred77 is offline
Senior Member
 
Default

I too am happy enough with SOAP/XML - JSON is fine too, but I don't see JSON as some massive leap forward, though I do welcome an overhaul of the API.

I was hoping the new API might feature something more exciting such as streaming / push technology, e.g. the client subscribes to markets of interest and live updates (price changes/bet matchings etc) are sent to the client as they happen, rather than the client having to poll for changes. Something like what Smarkets are attempting - but done properly!
AlgoTrader AlgoTrader is offline
Senior Member
 
Default

Quote:
Originally Posted by Fred77 View Post
I too am happy enough with SOAP/XML - JSON is fine too, but I don't see JSON as some massive leap forward, though I do welcome an overhaul of the API.
Let's compare:
xml:
Code:
<request>
  <header>
  <clientStamp>0</clientStamp>
    <sessionToken>eA6cUxo+2IC7BYKZFOMqomfaPwVSZfT+1tQn66q15zM=</sessionToken>
    </header>
    <bets xsi:type="n2:ArrayOfCancelBets">
      <CancelBets  xsi:type="n2:CancelBets">
        <betId xsi:type="xsd:long">21772814452</betId>
      </CancelBets>
      <CancelBets xsi:type="n2:CancelBets">
        <betId xsi:type="xsd:long">21772814453</betId>
      </CancelBets>
      <CancelBets  xsi:type="n2:CancelBets">
        <betId xsi:type="xsd:long">21772814454</betId>
    </CancelBets>
  </bets>
</request>
json:
Code:
{
    "header": {
        "sessionToken": "eA6cUxo+2IC7BYKZFOMqomfaPwVSZfT+1tQn66q15zM=",
        "clientStamp": 0
    },
    bets: [ "21772814452", "21772814453", "21772814454",]   
}
It's not the secret Betfair heavily uses arrays but there is no "array" concept in XML. Array of ints in JSON is just "[1, 2, 3]", the same in XML:

Code:
<array xsi:type="ns:ArrayOfInts">
  <int xsi:type="xsd:integer">1</int>
  <int xsi:type="xsd:integer">2</int>
  <int xsi:type="xsd:integer">3</int>
</array>
ns:ArrayOfInts cannot be omited, the parser needs to know "array" tag is array container. Then every <int> is element container. In fact, int's tag type can be omited but BF never drops types in responses.

Closing tags, attributes, namespaces, weird array encodings - everything makes SOAP XML so garbaged, so Betfair decided to implement "compressed" calls for the most critical things. getAllMarkets has smart text encoding, otherwise responses can easily reach multiple megabytes. We need to use complex SOAP libs or make our own intellectual parsers, after that, we need to decode "compression" by applying post-SOAP processing. Why so much complexity to do quite simple things?

Decoding JSON is rarely something more complex than
Code:
response = json_parse(data);
JSON is easily mapped into native types of most of languages, for example in C++/Qt

Code:
// create a parser instance
QJson::Parser parser;
bool ok;

// json is a QString containing the data to convert
QVariant result = parser.parse (json, &ok);
Saying farewell to DOM or SAX XML parsers or mutimegabytes SOAP generated stuff, parsing "compression" and other woodoo stuff is really majour leap forward
__________________
Betfair Bots Made Easy
https://github.com/AlgoTrader/betfair
Regi Keyz's Avatar
Regi Keyz Regi Keyz is offline
Junior Member
 
Default To BetFair Team:

Hi,

I'm looking forward to your new API, to be released soon hopefully

May I say something?

I've studied the rise of Japan from broke to becoming a major economic power over the last half century.
One of the many 'secrets' of their success, was because at lunch times in 60's, in the major manufacturing plants, the blue collar workers would eat at the same table as the white collar managers/directors (in UK and US, the white collars didnt want to sit with the blue collars). The white collar Japs knew the guys at the bottom often had essential real life infomation that could massively improve their production process.. information usually ignored by the people at the top.. history tells us the result, their manufacturing overtook USA to become ultimately the best in the world. Of course there were other factors at play too, but..
..with this in mind, please would you develop this API in close association with some of the more experienced guys on this forum eg wotsisname and co.. the last API had lots of issues, it would be a shame to put in all this work and not get full benefits from it!
Especially now other competition is on the rise, if you can get your API spanking, it will part a part in keeping you at pole position as the top exchange out there.

Just my thought
Thanks for listening!
Thread Closed

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump