I was reading a few threads this morning and had a quick play with my script that pulls tennis in play data to a CSV. A few edits and I was able to grab the current teams\scores from the Sofascore API and save a to a CSV to import regularly into Guardian (every 30s)
Posting up here and hopefully this may help a few of you
Script:
This runs in a language called Auto-It. It's a fork of AutoHotKey and is pretty powerful.
To run the script you will need to download the program and Scite Editor from here:
https://www.autoitscript.com/site/autoit/downloads/
Once installed, paste the code below into the Scite Editor and save to a local folder as Football.au3 (or whatever name you wish)
Then, in Scite do "Tools - Go" and the script will start
The script will run in a 30s timed loop, pulling down the team names and current scores for all currently LIVE games in Sofascore. It will then save those results to a file called "score.csv"
I've attached a sample baf file that is then configured to pull the data from the CSV into Guardian on a timed 5s cycle. It will match the wildcarded team name to each selection name and create a stored value for each Selection called "Score"
I've left the log updates in place for the SV score values but you may want to turn those off when you are confident, as they will fill your log up
Just browse in the baf parameters tab to the folder you saved the script in and select score.csv
Once you have the SV's in Guardian you can use them in rules in any way you like i.e S1 Score + S2 Score > 0 (first time) is 1 goal scored, hardcoded score of 2-1, 1-3 etc etc Using a signal on either SV changing in x seconds to wait for the market to settle post goal. Lots of possibilities....
NOTES:
Be careful adjusting the speed of the script loop ( line 54). Lower than 10s and you risk your IP being blocked by SofaScore for too many accesses per minute.
Its possible to compile the script as an exe in Scite so you can just double click it whenever you have footy automation running. Scite - Tools - Compile. Just go with the defaults. Remmber to kill (in the Task bar) when trading is over.
There is a tiny CPU overhead for the running script and shouldn't cause any performance issues, runs in a split second every 30s
****************
Because of the way this is designed, there may be the odd file lockout where both Guardian and the script are trying to read/write the CSV file at the same time. BetAngel Support have confirmed (further down the thread) that in this case Guardian will only read and use the entire file when unlocked. There is no chance of partial reads of the data and a problem with the SV's. In this case, the SV's will just update when the file is unlocked again i.e the script has finished writing. If this happens you will see a corresponding log entry in Guardian
*******
Using the same API query process and a little work it's possible to pull down all the in play stats available on SofaScore and pass those as SV's in the same CSV. Which would make Guardian footbal automation pretty powerful
Shout if you need any help
Stu
Code: Select all
#include <Inet.au3>
#include <json.au3>
#include <Array.au3>
#include <String.au3>
#include <File.au3>
$TitleString = "Team|Score"
;File to connect Guardian to. Will save in same location as script
$File = "score.csv"
While 1
$URL = "https://api.sofascore.com/api/v1/sport/football/events/live"
$data = _INetGetSource($URL)
$object = json_decode($data)
Local $Count = Json_Get($object, '.events')
FileDelete($File)
FileOpen($File)
$z = 0
For $i = 0 To UBound($Count) - 1
;Writing "1" to first line of the CSV. Required by Guardian
If $z = 0 Then
FileWriteLine($File, "1")
EndIf
$z = 1
$HomeString = "*,*," & "*" & Json_Get($object, '.events' & '[' & $i & '].homeTeam.name') & "*,*,"
$AwayString = "*,*," & "*" & Json_Get($object, '.events' & '[' & $i & '].awayTeam.name') & "*,*,"
$HomeString = $HomeString & "S,Score," & Json_Get($object, '.events' & '[' & $i & '].homeScore.current')
$AwayString = $AwayString & "S,Score," & Json_Get($object, '.events' & '[' & $i & '].awayScore.current')
;MsgBox($MB_SYSTEMMODAL, "Score", $HomeString & @CRLF & $AwayString)
FileWriteLine($File,$HomeString)
FileWriteLine($File,$AwayString)
Next
FileClose($File)
;Wait time between score refresh in milliseconds
;#######DO NOT SET SHORTER THAN 10S AS YOUR IP MAY BE BLOCKED#####
Sleep(30000) ;30 seconds
WEnd
Sample BAF File