I didnt change anything on my keyboard or computer. And i tried 2 dif computers. I´m in Portugal, guess its a country thing.
cheers
I dont usually alert to the watchlist so hopefully someone else will chime in.mongo wrote: ↑Tue May 18, 2021 12:01 pmHi,
New to stored values and automation so in need a bit of assistance as it's doing my head in (probably overthinking it)!
I've managed to get this installed and running fine in the background, I can see the inplay scores being generated in the csv file and in the log for each game in guardian.
How do I know get them in the watchlist to show up as alerts on each selection?
Thanks
Unfortunately it's a limitation of the current pattern matching within BA. You can only use wildcards at the beginning and end of a string in the CSVmongo wrote: ↑Wed May 19, 2021 1:23 amMust say this is an excellent script.sniffer66 wrote: ↑Tue May 18, 2021 1:07 pm
I dont usually alert to the watchlist so hopefully someone else will chime in.
Just be careful with using this automated, I only put it up as a quick POC and it's not foolproof as far as the pattern matching on the team names. Pattern matching via the CSV could do with a little enhancement to ensure it's 100% on the matching i.e use of multiple wildcards "*Man*City* etc
After a bit of head scratching and some trial and error I've got it working to show the scores on the watchlist.
But I see what you mean about matching the team names, not all are being caught from the csv file into guardian, just one example would be Leicester City tonight, guardian only had the team name 'Leicester' and it wouldn't store the score as the csv had the team name down as 'Leicester City'.
What can I do to add the multiple wildcards? I presume I'd just need to edit the Football.au3 file? or can it be done in the csv file?
Great work againsniffer66 wrote: ↑Tue May 25, 2021 4:47 pmLittle bit more playing around with the script and have current score, In-play time (inc ET), 5m/10m/Match - Average Attack Momentum Graph, SOT and Shots Off T set up for Watch List Alerts and Guardian Automation
Just a shame SS don't provide them for every match
Capture.JPG
Can you please provide the new code?sniffer66 wrote: ↑Tue May 25, 2021 4:47 pmLittle bit more playing around with the script and have current score, In-play time (inc ET), 5m/10m/Match - Average Attack Momentum Graph, SOT and Shots Off T set up for Watch List Alerts and Guardian Automation
Just a shame SS don't provide them for every match
Capture.JPG
Thanks sniffer66! This really helped! I had created a page for asking about SV from a file; but then bumped into this page.sniffer66 wrote: ↑Fri Jan 29, 2021 9:27 amFor anyone using the new beta you'll be aware that it is now possible to pass stored values to Guardian using a local CSV file. I don't trade football automated but I know getting accurate scoring into Guardian is problematic and involves workarounds based on price moves in various markets etc
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
Football_Scores.baf
Glad it helped zippuszippus wrote: ↑Tue Aug 10, 2021 11:50 amJust to echo previous replies - this is an excellent thread and thanks to all - in particular sniffer - for this. I've been really struggling with the loading a csv file and having the 'scores.csv' has enabled me to see what is required. I then revisited the standard BA csv templates and have been able to pull in some horse racing stored values and am now automating off them. It's saved me a tonne of time and the uses for this are endless...
Great work guys.
Code: Select all
1
*,12:30,*Manchester*,1,S,Score,0
*,12:30,*Leeds*,2,S,Score,0
*,12:30,*Peterborough*,1,S,Score,0
*,12:30,*Derby*,2,S,Score,0
Code: Select all
#include <Inet.au3>
#include <json.au3>
#include <Array.au3>
#include <String.au3>
#include <File.au3>
#include <UnixTime.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
Local $NameArray[1]
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
$HomeTeam = _StringReplaceAccent(Strip(Json_Get($object, '.events' & '[' & $i & '].homeTeam.name')))
$AwayTeam = _StringReplaceAccent(Strip(Json_Get($object, '.events' & '[' & $i & '].awayTeam.name')))
; Get kick off time and format to HH:MM
$StartTimestamp = Json_Get($object, '.events' & '[' & $i & '].startTimestamp')
$MarketTime = _StringFormatTime("%H:%M", $StartTimestamp)
;$HomeString = "*,*," & "*" & $HomeTeam & "*,1,"
;$AwayString = "*,*," & "*" & $AwayTeam & "*,2,"
$HomeString = "*," & $MarketTime & ",*" & $HomeTeam & "*,1,"
$AwayString = "*," & $MarketTime & ",*" & $AwayTeam & "*,2,"
$HomeString = $HomeString & "S,Score," & Json_Get($object, '.events' & '[' & $i & '].homeScore.current')
$AwayString = $AwayString & "S,Score," & Json_Get($object, '.events' & '[' & $i & '].awayScore.current')
;$URL = "https://api.sofascore.com/api/v1/event/" & Json_Get($object, '.events' & '[' & $i & '].id') & "/statistics"
;MsgBox("", "", $URL)
;$data1 = _INetGetSource($URL)
;If $data1 <> "" Then
;Json_Dump($data1)
;MsgBox("", "", $data1)
;EndIf
; Available data
;If $data <> "" Then
; Json_Dump($data)
; MsgBox("", "", $data)
;EndIf
;MsgBox($MB_SYSTEMMODAL, "Score", $HomeString & @CRLF & $AwayString)
FileWriteLine($File, $HomeString)
FileWriteLine($File, $AwayString)
;_ArrayAdd($NameArray, $HomeTeam)
;_ArrayAdd($NameArray, $AwayTeam)
;_ArrayDisplay($NameArray)
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
Func Strip($Param)
$f = "NotFound"
$e = StringSplit($Param, " ")
;_ArrayDisplay($e)
For $z = 1 To UBound($e) - 1
_ArraySearch($NameArray, $e[$z])
If @error Then
If StringLen($e[$z]) > 3 Then
$f = $e[$z]
ExitLoop
EndIf
EndIf
Next
;MsgBox($MB_SYSTEMMODAL, "Result", $f )
Return $f
EndFunc ;==>Strip
Func _StringReplaceAccent($sString)
Local $exp, $rep
Local $Pattern[28][2] = [ _
["[ÀÁÂÃÅÆ]", "A"], ["[àáâãåa]", "a"], ["Ä", "Ae"], ["[æä]", "ae"], _
["Þ", "B"], ["þ", "b"], _
["ÇC", "C"], ["[çcc]", "c"], _
["[ÈÉÊË]", "E"], ["[èéêë]", "e"], _
["[ÌÍÎÏ]", "I"], ["[ìíîï]", "i"], _
["Ñ", "N"], ["ñ", "n"], _
["[ÒÓÔÕÖØ]", "O"], ["[ðòóôõöø]", "o"], _
["r", "r"], _
["[ŠS]", "S"], ["[š]", "s"], _
["ß", "Ss"], _
["[ÙÚÛ]", "U"], ["[ùúû]", "u"], ["Ü", "Ue"], ["ü", "ue"], _
["Ý", "Y"], ["[ýýÿ]", "y"], _
["Ž", "Z"], ["ž", "z"]]
For $i = 0 To (UBound($Pattern) - 1)
$exp = $Pattern[$i][0]
If $exp = "" Then ContinueLoop
$rep = $Pattern[$i][1]
$sString = StringRegExpReplace($sString, $exp, $rep)
If @error == 0 And @extended > 0 Then
;ConsoleWrite($sString & @LF & "--> " & $exp & @LF)
EndIf
Next
Return $sString
EndFunc ;==>_StringReplaceAccent
Code: Select all
#include-once
;===============================================================================
;
; AutoIt Version: 3.2.3.0
; Language: English
; Description: Dll wrapper functions for dealing with Unix timestamps.
; Requirement(s): msvcrt.dll
; Notes: If msvcrt.dll is not available then functions will return false
; and set @error = 99.
;
;===============================================================================
;===============================================================================
;
; Description: _TimeGetStamp - Get current time as Unix timestamp value.
; Parameter(s): None
; Return Value(s): On Success - Returns Unix timestamp
; On Failure - Returns False, sets @error = 99
; Author(s): Rob Saunders ([email protected])
; User Calltip: _TimeGetStamp() - Get current time as Unix timestamp value. (required: <_UnixTime.au3>)
;
;===============================================================================
Func _TimeGetStamp()
Local $av_Time
$av_Time = DllCall('msvcrt.dll', 'long:cdecl', 'time', 'ptr', 0)
If @error Then
SetError(99)
Return False
EndIf
Return $av_Time[0]
EndFunc
;===============================================================================
;
; Description: _TimeMakeStamp - Create Unix timestamp from input values.
; Syntax: _TimeMakeStamp( [ second [, minute [, hour [, day [, month [, year [, isDST ]]]]]]] )
; Parameter(s): Second - Second for timestamp (0 - 59)
; Minute - Minute for timestamp (0 - 59)
; Hour - Hour for timestamp (0 - 23)
; Day - Day for timestamp (1 - 31)
; Month - Month for timestamp (1 - 12)
; Year - Year for timestamp (1970 - 2038)
; * All the above values default to the 'Default' keyword, where the current
; time/date value will be used.
; IsDST - Set to 1 during Daylight Saving Time (DST)
; - Set to 0 not during DST
; - Set to -1 if unknown, function will try to figure it out
; - Default is -1
; Return Value(s): On Success - Returns Unix timestamp
; On Failure - Parameter error, returns -1
; - Dll error, returns False, sets @error = 99
; Notes: The function will try and calculate dates for numbers outside of the
; usual range.
; For example: _TimeMakeStamp(0, 0, 0, 32, 1, 1995)
; 32nd day of January? Obviously that's not a valid date, but the function
; automatically calculates this to be February 1st. A date of 0 will return
; the last day of the previous month.
; User CallTip: _TimeMakeStamp($i_Sec = Default, $i_Min = Default, $i_Hour = Default, $i_Day = Default, $i_Mon = Default, $i_Year = Default, $i_IsDST = -1) - Create a UNIX timestamp from input values. (required: <_UnixTime.au3>)
; Author(s): Rob Saunders ([email protected])
;
;===============================================================================
Func _TimeMakeStamp($i_Sec = Default, $i_Min = Default, $i_Hour = Default, $i_Day = Default, $i_Mon = Default, $i_Year = Default, $i_IsDST = -1)
Local $struct_Time, $ptr_Time, $av_Time
$struct_Time = DllStructCreate('uint;uint;uint;uint;uint;uint;uint;uint;uint')
Select
Case $i_Sec = Default
$i_Sec = @SEC
ContinueCase
Case $i_Min = Default
$i_Min = @MIN
ContinueCase
Case $i_Hour = Default
$i_Hour = @HOUR
ContinueCase
Case $i_Day = Default
$i_Day = @MDAY
ContinueCase
Case $i_IsDST = Default
$i_IsDST = -1
EndSelect
; The following is done because the mktime function demands
; that the month be in 0-11 (Jan = 0) format instead of 1-12.
Select
Case $i_Mon = Default
$i_Mon = (@MON - 1)
Case $i_Mon <> Default
$i_Mon -= 1
EndSelect
; The following is done because the mktime function expects the year in format
; (full year - 1900), thus 99 = 1999 and 100 = 2005. The function will try
; to figure out what year the user is trying to use. Thus if the function recieves
; 70, it's untouched, but if the user gives 1970, 1900 is subtracted automatically.
; Any year above 99 has 1900 automatically subtracted.
Select
Case $i_Year = Default
$i_Year = (@YEAR - 1900)
Case $i_Year < 70
$i_Year += 100
Case $i_Year > 99
$i_Year -= 1900
EndSelect
DllStructSetData($struct_Time, 1, $i_Sec)
DllStructSetData($struct_Time, 2, $i_Min)
DllStructSetData($struct_Time, 3, $i_Hour)
DllStructSetData($struct_Time, 4, $i_Day)
DllStructSetData($struct_Time, 5, $i_Mon)
DllStructSetData($struct_Time, 6, $i_Year)
DllStructSetData($struct_Time, 9, $i_IsDST)
$ptr_Time = DllStructGetPtr($struct_Time)
$av_Time = DllCall('msvcrt.dll', 'long:cdecl', 'mktime', 'ptr', $ptr_Time)
If @error Then
SetError(99)
Return False
EndIf
Return $av_Time[0]
EndFunc
;===============================================================================
;
; Description: _StringFormatTime - Get a string representation of a timestamp
; according to the format string given to the function.
; Syntax: _StringFormatTime( "format" [, timestamp [, max length ]] )
; Parameter(s): Format String - A format string to convert the timestamp to.
; See notes for some of the values that can be
; used in this string.
; Timestamp - A timestamp to format, possibly returned from
; _TimeMakeStamp. If left empty, default, or less
; than 0, the current time is used. (default is -1)
; Max Length - Maximum length of the string to be returned.
; Default is 255.
; Return Value(s): On Success - Returns string formatted timestamp.
; On Failure - Returns False, sets @error = 99
; Requirement(s): _TimeGetStamp
; Notes: The date/time specifiers for the Format String:
; %a - Abbreviated weekday name (Fri)
; %A - Full weekday name (Friday)
; %b - Abbreviated month name (Jul)
; %B - Full month name (July)
; %c - Date and time representation (MM/DD/YY hh:mm:ss)
; %d - Day of the month (01-31)
; %H - Hour in 24hr format (00-23)
; %I - Hour in 12hr format (01-12)
; %j - Day of the year (001-366)
; %m - Month number (01-12)
; %M - Minute (00-59)
; %p - Ante meridiem or Post Meridiem (AM / PM)
; %S - Second (00-59)
; %U - Week of the year, with Sunday as the first day of the week (00 - 53)
; %w - Day of the week as a number (0-6; Sunday = 0)
; %W - Week of the year, with Monday as the first day of the week (00 - 53)
; %x - Date representation (MM/DD/YY)
; %X - Time representation (hh:mm:ss)
; %y - 2 digit year (99)
; %Y - 4 digit year (1999)
; %z, %Z - Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
; %% - Literal percent character
; The # character can be used as a flag to specify extra settings:
; %#c - Long date and time representation appropriate for current locale. (ex: "Tuesday, March 14, 1995, 12:41:29")
; %#x - Long date representation, appropriate to current locale. (ex: "Tuesday, March 14, 1995")
; %#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y - Remove leading zeros (if any).
;
; User CallTip: _StringFormatTime($s_Format, $i_Timestamp = -1, $i_MaxLen = 255) - Get a string representation of a timestamp according to the format string given to the function. (required: <_UnixTime.au3>)
; Author(s): Rob Saunders ([email protected])
;
;===============================================================================
Func _StringFormatTime($s_Format, $i_Timestamp = -1, $i_MaxLen = 255)
Local $struct_Time, $ptr_Time, $av_Time, $av_StrfTime
If $i_Timestamp = default OR $i_Timestamp < 0 Then
$i_Timestamp = _TimeGetStamp()
EndIf
$ptr_Time = DllCall('msvcrt.dll', 'ptr:cdecl', 'localtime', 'long*', $i_Timestamp)
If @error Then
SetError(99)
Return False
EndIf
$av_StrfTime = DllCall('msvcrt.dll', 'int:cdecl', 'strftime', _
'str', '', _
'int', $i_MaxLen, _
'str', $s_Format, _
'ptr', $ptr_Time[0])
Return $av_StrfTime[1]
EndFunc