Comments

  • peteresgate@outlook.com
    2.10.2019 12:38:50

    Thanks Stefan, Yes I would really appreciate if you could design the bot that works on past results, and I will endeavour to thoroughly understand the code and learn f# so that I can do this myself in the future from what you have taught and shown in this tutorial series :)

  • Betfair Bot
    2.10.2019 12:21:02

    Peter, I will really suggest you to read error messages when you build your bot trigger.

    First error reports:

    This function takes too many arguments, or is used in a context where a function is not expected.

    It is where you put HorseRacingBotTrigger2, so constructor of your bot trigger, constructor is function as input to the function:

    MyStrategyOperations.GetMyStrategyResults expects as input strategy name, so string/text value.

    Ok, when you correct input value, so incorrect context you type:

    let myStrategyResults = MyStrategyOperations.GetMyStrategyResults(botName)

    Then there is no other error in this line, but you must understand what is actually returned by GetMyStrategyResults, and how you will use it.

    When you hover your mouse over GetMyStrategyResults, tooltip shows you what you will get, and this data must be used in correct context as well.

    Please read about programming at least couple pages of text, because code is not just text.

    It is like you misspell a sentence the way no one is able to understand what you wanted to say.

    You can develop your bot trigger in C# programming language as well, but as script you can use only code written in F#.

    I can prepare simple bot trigger working with previous results, but I do not think you will manage to use such code yourself.

  • peteresgate@outlook.com
    2.10.2019 10:59:40

     Oh ok.  I sort of grabbed your code from My Staking Plan . Could you please explain the mechanism of how to run the console script and also have MyBotTrigger "get" the information from it?  And 1 other question- with my C sharp bot or my f sharp bot, would they require the console script as well for past bot results?

    Thanks.

  • Betfair Bot
    2.10.2019 10:21:05

    You cannot use console script code in your bot trigger code. It was created in other context and for other purpose.

    If you would read error message in Visual Studio or Visual Code (I do not know which IDE you are using.), then errors would suggest problems in your code.

    Please, just read what IDE suggests.

  • peteresgate@outlook.com
    2.10.2019 10:09:05

    Please see my attempt at Part 4. I added lines 75, 76, and 178 to 184.

    I basically wanted to have parameter maxLossesInRow and if the number of losses in row is less or equal to this parameter, then continue to execute bot, or else exit. Unfortunately it has some errors that hopefully can be corrected thanks?

    https://github.com/PeterEsgate/BfexplorerTestBots/blob/master/HorseRacingBotTrigger2

  • Betfair Bot
    1.10.2019 14:20:51

    We have got your strategy for horse racing programmed as bot trigger:

    Bot Trigger Building Part 2

    Bot trigger code is executed by bot called: “Execute Trigger Bot”, and trigger executes the action bot, so bot strategy that places bets or starts trading session. In my test I used: “Lay trade 4 ticks”. I named this strategy: “Horse Racing Bot Trigger”.

    So you have got your strategy that can be executed manually from My Strategies /Bots to Execute, on the market you open in Bet Event view, just selecting your strategy “Horse Racing Bot Trigger” and clicking on the Execute toolbar button.

    If you want to execute your strategy automatically on all races, then you can use “Bot Executor” tool.

    Bfexplorer app offer more general purpose bot strategies, one them is bot strategy named: “Execute Till Target Profit”, and that is what you need, to stop the execution of your strategy when it is executed automatically, when target profit or loss is reached. Again, the bot uses action bot to be executed, set by parameter BotName, in our case we want to execute: “Horse Racing Bot Trigger” and that is all. Just name your strategy (I named it: “My Horse Racing Strategy”) and execute it at set time relative to the race time (market start time).

    When programming your strategy using Bfexplorer BOT SDK, you have got access to all bfexplorer generated data with public interface, so you can access your betting results, or create your own version of “Execute Till Target Profit”.

    For instance Bfexplorer Console, the tool executing a script code to automate bfexplorer UI interaction, or querying data. The similar script can be programmed to read your strategy results and process data.

    For instance here is script opening Match Odds and Over/Under 2.5 Goals markets that met required parameters:

    SearchFootballMarkets.fsx

  • peteresgate@outlook.com
    1.10.2019 11:48:55

    That's great to hear Stefan.  Bfexplorer truly is the best- no other software can do what Bfexplorer can.  For my non programming brain I wonder "how", but with your knowledge you always "know".  I very much look forward to the final solution :)

  • Betfair Bot
    1.10.2019 11:17:49

    With anything you do, you need at least base understanding of what you do.

    If you go with Excel automation to place your bets on betfair, then you need to learn how to use Excel, formulas, and of course VBA programming, because you cannot make running your strategy just by using formulas, or bet angel rules.

    To part 4 of your tutorial, without saying anything about coding, just use common sense to understand what should be done.

    If your strategy depends on previous results, then of course something in bfexplorer should be able to retrieve your bet results, and process this information. Your bot trigger must be able to work with such information.

  • peteresgate@outlook.com
    1.10.2019 10:24:50

    Thanks Stefan.  I do have more understanding now, but have a long long way to go.  Thanks for your help.  With Part 4 in which the bot "counts" it's losses before shutting down, is this possible?  I question it because I see in the console bot started and bot ended, so I don't understand the mechanism of how it stores the losses if the bot ends.

  • Betfair Bot
    1.10.2019 10:16:13

    Peter, it is up to you what homework you do, or what different bot trigger you could offer for other readers, as your bot trigger can evaluate different selection values, and as well evaluation process could be programmed by many different ways.

    I actually separated storing of selection trigger values to different type/class, so code is prepared for different scenarios.

    If you really are able to read the trigger bot code you have to see it, so you can describe those different scenarios to others, but that is up to you.

    I asked for “homework” because you reported problems with compiling bot trigger code, what means you did not understand what were you doing, I hope you do now.

  • peteresgate@outlook.com
    1.10.2019 10:01:51

    'F' grade for me this time.  Thanks for the solution to Part 2 :)    What homework would you like me to submit before the final reveal in Part 4? - I hope to redeem myself

  • Betfair Bot
    1.10.2019 9:21:15

    Ok, it seems you managed to understand the concept of F# programming.

    On the other hand I see you have actually no understanding of betting terminology, as book value is not calculated as you did in your code. The book value in betting is sum of selection’s probabilities.

    Here is my bot trigger code for part 2: HorseRacingBotTrigger2.fs

  • peteresgate@outlook.com
    1.10.2019 8:59:15

    I am not a programmer, but this is the part 1 with the Last Price Traded added to output

    https://github.com/PeterEsgate/BfexplorerTestBots/blob/master/HorseRacingBotTrigger1-1

    I am looking forward to viewing Stefan's code with Part 2 combined into Part 1 :)

  • Betfair Bot
    30.9.2019 16:21:59

    Here is my first test that actually triggered some trading session. When testing it is really important how you set all trigger parameters, for testing it is good to set them without limits, so not parameters are tested but code

    I set the fallowing parameters as default ones:

    allowedSelectionIndexes: 1,2,3,4,5,6

    timeToStart: 40.0

    favouritesPrice: 50.0

    When the race started, bot trigger saved position of allowed horses. When timeToStart expired, all allowed horses were evaluated again

    positionDifference <- startPosition – position

    So trigger selected Bianca Minola as nominated selection on which Bot Trigger started lay/back trading session for 4 ticks of profit.

  • peteresgate@outlook.com
    30.9.2019 13:51:49

    Sorry about the formatting.  I copied and pasted the working code and it looked good on my side with the correct indentations etc,, but the website changed it to the posted result that is there now.  I'll look at setting up GitHub and reposting the link to the code so others who are following/learning can view and get it.

  • Betfair Bot
    30.9.2019 9:56:56

    Peter, I do not want to patronize you, but I have got very simple question?

    Are you satisfied with what you did?

    Why did I ask?

    Because any written source code must be formatted to be readable by other programmers.

    Yes, some programming languages that use for instance { } to separate block of code, could be stripped to one line and compiler successfully build such code, but not F# where code block must be formatted by text/code indentation and you cannot used tabs:

    https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting

    I mentioned that, because during weekend you posted video showing you edited bot trigger in Notepad text editor. So anyone who would like to use your code you posted in your comment, must copy and paste your text, reformat it correctly, and then will find out that your code does not do what you claim you did.

    So you waste maybe 10 minutes or more, to someone who wants to test your code. English is foreign language for me so is very hard for me to find politically correct words for your behavior.

    Please, install either Visual Code, like I show here:

    Betfair Bot Programming for Non-Developers

    Or Visual Studio Community version:

    Bfexplorer - Betfair BOT SDK

    Both IDE (Integrated Developer Environment) applications are free, unlike Microsoft Excel other betfair app use, where you must buy licenses of Microsoft Excel. Using Bfexplorer BOT SDK all applications or tools helping you to create bot trigger are for free.

    Why is using right programs/applications important when developing/writing code?

    Because like text editors with spellchecking, such IDE checks your code when writing, so any mistake in misspelling anything in code is reported. Visual Studio, or Visual Studio code offer you as well, so called IntelliSense/IntelliCode technology when writing code, so helping you to write the code:

    https://visualstudio.microsoft.com/services/intellicode/

    And finally why did I ask you to make some changes in the code?

    To force you learn something, because bot trigger code in other parts of our tutorial will be more difficult.

    I know you are not software developer, but in part 1 the source code is really readable even by non programmer, it contains plain English words like if, then, else, match, let, try, with, and some words you would maybe need to think about, like open, type, interface, member and map  

    https://en.wikipedia.org/wiki/Map_(higher-order_function)

    Please, when you want to use source code, and want to share it with others, do them favor and share it on http://github.com through Github Gist, like I do:

    https://gist.github.com/StefanBelo

    Again, you can register on github.com for free. Or just use any of other code sharing services on the Internet:

    https://www.google.com/search?q=code+sharing+service&oq=code+sharing+service

  • peteresgate@outlook.com
    30.9.2019 2:52:29
    The following is the Part 1 code with the last price traded added. In Part 2, we will build triggers into this that react to our selection position change from starting point (x seconds in play) to trigger point (The number 1 and 2 position horses both have back odds less then X (and our selection is not position 1,2 or 3) module BfexplorerBot //(* #I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\" #r "BeloSoft.Data.dll" #r "BeloSoft.Betfair.API.dll" #r "BeloSoft.Bfexplorer.Domain.dll" #r "BeloSoft.Bfexplorer.Trading.dll" #r "BeloSoft.Bfexplorer.Service.Core.dll" //*) open System open BeloSoft.Data open BeloSoft.Bfexplorer.Domain open BeloSoft.Bfexplorer.Trading let toIndexes (value : string) = try value.Split(',') |> Array.map Int32.Parse |> List.ofArray with | _ -> List.empty /// /// HorseRacingBotTrigger /// type HorseRacingBotTrigger(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, _myBfexplorer : IMyBfexplorer) = let allowedSelectionIndexes = toIndexes (defaultArg (botTriggerParameters.GetParameter("AllowedSelectionIndexes")) "1,2,3") let isHorseRacingMarket() = market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN" let getActiveSelections() = market.Selections |> Seq.filter isActiveSelection |> Seq.toList let getMySelectionsData() = maybe { if allowedSelectionIndexes.Length > 0 then let selections = getActiveSelections() let mumberOfSelections = selections.Length let maximalIndex = allowedSelectionIndexes |> List.max if mumberOfSelections >= maximalIndex then return allowedSelectionIndexes |> List.map (fun index -> selections.[index - 1]), mumberOfSelections } interface IBotTrigger with member __.Execute() = if isHorseRacingMarket() then match getMySelectionsData() with | Some (selections, mumberOfSelections) -> let mySelectionNames = selections |> List.map (fun mySelection -> mySelection.Name) |> String.concat ", " let mySelectionBookValue = selections |> List.map (fun mySelection -> mySelection.LastPriceTraded) |> List.sum TriggerResult.EndExecutionWithMessage (sprintf "\nMy selections: %s %f\nNumber of runners: %d" mySelectionNames mySelectionBookValue mumberOfSelections) | None -> TriggerResult.EndExecutionWithMessage "Failed to make my selections!" else TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!" member __.EndExecution() = ()
  • Betfair Bot
    28.9.2019 0:46:54

    Ok, but you did not specify that you want to check horse's positions in two different times. My first implementation was that bot waits till market is turned at in-play, then saves information about all allowed selections, so horse's positions is saved as well.

    At set time in race, bot checks your conditions, so favourites must be traded at that moment of checking under set price/odds.

    Then allowed selections are sorted by position change difference, so biggest position change is the first one, if this selection is not among the first three favourites, it is nominated as the selection your strategy will be executed on.

    The bot trigger again similar like I explained to you in the part 3, does not have to know anything about your criteria for entry point, so if you allow starting lay/back trading session only when the selection/horse is traded from 10.0 to 20.0, then you can simply set that to Entry Criteria for this lay trading bot.

    Now think a little bit. I hope you already know that Entry Criteria could be evaluated just once, or could be evaluated till all set Entry Criteria are met. This feature gives you two different options for your bot placing a lay bet.

    If you think more, then you will find that bfexplorer offers more bots placing a bet, or starting trading session, namely:

    Place Bet

    Be the First in Queue

    Fill or Kill

    Place Bet and Close Selection Bet Position

    Scratch Trading

    This gives you really big flexibility for different ways your bet is placed on the market selection, and closes your bet position for loss when needed.

    Of course not all of above bot strategies to place a bet are suitable for in-play markets where odds changes so rapidly as on the horse racing, therefore I would suggest to use:

    Place Bet and Close Selection Bet Position

    But of course you can test them all, or other combinations for instance:

    Place Bet, and Trailing Stop Loss

    What is very good news for you is that bot trigger code does not have to implement anything to place a bet and manage its status, so you will get simpler trigger code.

    I really cannot imagine how people could manage such strategies just in Excel spreadsheets, so traders using Bet Angel, Cymatic or Gruss software. I think they cannot run such strategies, am I right?

    Your tutorial in the part 1 is ready, I will post bot trigger code for the part 2, but first test your bot trigger for part 1, and as the simple coding exercise, change the bot trigger code to report not only horse name, but the last traded price as well.

    Here is the hint:

    https://gist.github.com/StefanBelo/a85ee8b9959b841ea423eade056cc762

  • peteresgate@outlook.com
    27.9.2019 23:57:23

    That is a great explanation :)

    Thanks for clearing that up for me.  

  • peteresgate@outlook.com
    27.9.2019 23:57:02

    After for example 20 seconds in play, I would like to check the position of the horse (using it's odds). When (if) 2 horses achieve odds less then x ( 2 for example), then re-check the position of our selection and compare it to the position it was at at 20 seconds. So if at 20 seconds, it is at position 2 and then when trigger is 2 horses are at odds below 2, it re-checks the selection and sees that it is at position 5, the selection has dropped in position.