Betfair Exchange API : Read Betfair JSON in C# into human readable form

Post Reply
Posts: 10
Joined: Fri May 11, 2018 11:31 am

Fri Jun 08, 2018 3:18 pm

I'm at early stages with this, I also find this webpage useful, bit more readable. Let me know if you find it useful so far, you should get the gist if you have some programming knowledge.

Please ask if anything below seems scary. It really isn't.

If anyone has classes set up to deserialise to, do please let me know, please feel free to augment. Make it a bit more human friendly, plus not used dynamic objects in anger much as yet still playing.

1) Download the football sample, and unzip using 7zip, I think winzip works too.
2) Download Linqpad it is free - and awesome.
3) Download Newtonsoft dll. The below code needs a reference to it. In Linqpad press F4, click browse, and where you downloaded this to and add the dll, it is in a subfolder called Json110r2\Bin\net45\Newtonsoft.Json.dll
4) Paste the following into the window. It will complain, and ask you to add a reference. If not look on Linqpad website on how to do all that.
and press F5 to run.

This should output
Middlesbrough v Man City
Over/Under 0.5 Goals
30/04/2017 13:05:00

string[] file = File.ReadAllLines(@"C:\temp\football-basic-sample");

//read the first record
foreach(var line in file.Take(1))
dynamic stuff = JsonConvert.DeserializeObject(line);




Posts: 10
Joined: Fri May 11, 2018 11:31 am

Fri Jun 08, 2018 5:53 pm

Ok this isn't pretty but I have run out of time for today.

The below lists all home win prices and the time. Might have bugs.

Change to run C# program if running in Linqpad.

void Main()
string[] file = File.ReadAllLines(@"C:\temp\football-basic-sample");

string homeWinID = string.Empty;

//read the first record
foreach(var line in file.Take(1))
dynamic stuff = JsonConvert.DeserializeObject(line);

int market = 2; // match odds

Console.WriteLine("Event id " +[market].marketDefinition.eventId);
Console.WriteLine("Market id " +[market].id);
homeWinID =[market].marketDefinition.runners[0].id;
Console.WriteLine("Home Win id " +[market].marketDefinition.runners[0].id);
Console.WriteLine("Away Win id " +[market].marketDefinition.runners[1].id);
Console.WriteLine("Draw id " +[market].marketDefinition.runners[2].id);



//read data lines
foreach(var line in file.Skip(1))
dynamic stuff = JsonConvert.DeserializeObject(line);


if (line.Contains(homeWinID) && !line.Contains("marketDefinition"))
//string time = JavaTimeStampToDateTime(double.Parse(;

string javDt =;
DateTime dt = JavaTimeStampToDateTime(double.Parse(javDt));
string time =;
Console.WriteLine(dt.ToString() + "," +[0].rc[0].ltp);



// Define other methods and classes here
public static DateTime JavaTimeStampToDateTime( double javaTimeStamp )
// Java timestamp is milliseconds past epoch
System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddMilliseconds( javaTimeStamp ).ToLocalTime();
return dtDateTime;

Posts: 11
Joined: Wed Aug 22, 2018 4:12 pm

Wed Aug 22, 2018 4:32 pm

Great work, although I am new to this.

I got a spreadsheet made with macros that imports the csv files from

Posts: 10
Joined: Fri May 11, 2018 11:31 am

Fri Sep 28, 2018 5:23 pm

Cheers doug, are you a programmer, i made a full c# program to read it, about as far as i got though. Set up classes for the JSON too.

The JSON files are about the only place i can find in play data, they used to do CSV, but no more....unless someone knows otherwise?

If there is anyone out there looking to help for mutual benefit, let me know.

I have another program on that, i loaded quite a lot of those into a database, and back tested a basic strategy, which is my main one right now, more simple than i thought really.

Just got to avoid betting on scottish tennis players though. (When he wins, he's British!). Sorry guys north of the border, just kidding.

Posts: 13
Joined: Sun Nov 18, 2018 11:12 am

Tue Jan 08, 2019 6:43 pm

Hi All,

I downloaded some free soccer data from betfair, but it arrives in 597 folders, with files to be extracted in each folder. Is there a way to extract all the files in these 597 folders to one location?



Post Reply

Return to “Betfair Exchange API”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest