Article

Bot Trigger Building Part 1

When designing a bot, we need to have clearly defined rules before we start. 

Bfexplorer already has a suite of ready to use functions and strategies.  One of the exciting things with Bfexplorer is that it's possibilities are virtually limitless, so much so that if your idea/rule is not currently an offered option,  it can be "added". 

I am currently in the first stage of where I have a strategy in mind with 7 rules, some of which are already available, and some of which need to be added.  Now I would really like a step by step tutorial on building new triggers and how to build on those triggers to effectively build my strategy. 

Stefan has kindly offered to do a tutorial series on building triggers and to build on those triggers to benefit the knowledgebase of the Bfexplorer community.  I trade horseracing.

With the first part, I'd like the bot to only execute on when there are more then X selections (already an option in Bfexplorer), but I would like the bot to ONLY apply to selections from specific starting lanes.  So this is the first trigger that would need to be built and added to the already available:

NumberOfSelections is greater than "x"

 

Comments ( 1 )


  • Stefan
    27.9.2019 17:15:04

    Yes, one of your requirements for horse racing strategy is to execute only if allowed number of horses will run in the race.

    This can be set in Entry Criteria: NumberOfSelections and for operator you can apply one of 5 relevant options, so this could be removed from the bot trigger code.

    Here is my bot trigger code:

    https://gist.github.com/StefanBelo/71b025e6a4c687fe98f99a258ddb6cb5

    It is 67 lines of code but actual code starts from line 19. The main bot trigger code is executed by Execute function, so algorithm for this bot code is on 11 lines.

    The bot trigger code contains one general functions  getActiveSelections (lines 35-36) as for some markets like horse racing, greyhounds, golf and so on, selections could be withdraw, we must use this function to get only active selections, in our case horses.

    One of requirements is to apply any further evaluation only on specific selections defined by order index in which betfair displays market selections. Peter named that “starting lanes”.  

    In bot trigger, bfexplorer inputs any data to bot trigger through object botTriggerParameters, so any data entered through parameter: TriggerParameters.

    On the line 18 we retrieved such parameter named: AllowedSelectionIndexes. Keep in mind that you must enter exactly this name in the parameter list, it is case sensitive. When no parameter is entered, the bot trigger code implements default value, it is set to: "1,2,3,10,11,12"  

    So horses order indexes separated by comma. As the indexes are enter as text value, the helper method “toIndexes” transforms this text to list of integers.

    The function “getMySelectionsData” (lines 38 – 48) checks whether bot trigger has valid indexes for evaluated race, and returns list of selections, and number of selections, otherwise returns nothing, to be exact in F# programming terms it returns Option.None value.

    And that is all for our first bot trigger, as mentioned before the code is executed by Execute function, and code execution can be described:

    If it is horse racing market and we can get my selections data, then it is displayed message: \nMy selections: name 1, name 2\nNumber of runners: 15”.

    If it is not horse racing market it is displayed message: "You can run this bot on a horse racing market only!".

    If there is any error in getting my selections data, then error message is displayed:

    And bot trigger execution is ended.