-
Notifications
You must be signed in to change notification settings - Fork 1
Custom betting functions
If you are not satisfied with the current betting implementation, you can define your own functions using the code editor in the UI. The scripts are written in javascript and will be executed in an isolated environment.
Only execute safe code, as the isolated environment can be expoloited: CVE-2023-37466, CVE-2023-37903.
The odds read by the program will be stored in a global variable named odds
, pointing to a string array, which may look like this:
["evens", "2/1", "6/1", "9/1", "21/1", "30/1"]
To set your result, use the setResult
function, the odd of the horse to place a bet on as the first parameter, like this:
setResult("2/1");
// or
setResult(odds[0]);
If no bet should be placed, pass null
to setResult
:
setResult(null);
Each invokation of a custom betting function has a time limit of five seconds. If setResult
isn't called within these 5 seconds, the function call will abort and the program will revert the betting function to the default implementation.
On saving, the program will generate random odds to test the functionality of the custom function. The result will be displayed in a snackbar on the bottom of the ui where the inputs to and the outputs from the function can be viewed. If all tests pass, the function can be set as the default one. The tests can also be triggered to run again once the function was saved.
The default implementation, which can also be found in the code editor named "Default", would look like this:
// Convert an odd string such as '2/1'
// to a number, e.g. 2
function toNumber(val) {
return Number(val.split('/')[0]);
}
// Main function
// Returns string, the odd of the horse to bet on,
// or null, if no bet should be placed
function run() {
let containsEvens = odds.includes("evens");
let lowest = null;
for (let i = 0; i < odds.length; i++) {
// Check if one probability >= 5/1 exists multiple times
for (let j = i + 1; j < odds.length; j++) {
// If odds[i] >= 5/1 exists multiple times, do not bet
if ((odds[i] == "evens" || toNumber(odds[i]) <= 5) && odds[i] == odds[j])
return null;
}
// If odds contains 'evens' and does also
// contain another one >= 3/1, do not bet
if (containsEvens && (odds[i] == "2/1" || odds[i] == "3/1"))
return null;
// Set the lowest odd
if (!containsEvens && (lowest == null || toNumber(odds[i]) < toNumber(lowest))) {
lowest = odds[i];
}
}
// If the odds contain evens, this is the lowest
if (containsEvens) {
lowest = "evens";
}
// Return the lowest odd
return lowest;
}
// Set the result.
// Set null if no bet should be placed,
// the odd of the horse to bet on otherwise
setResult(run());
Autobet. © MarkusJx 2022. Licensed under the MIT License.