Comments

  • peteresgate@outlook.com
    11.10.2019 11:54:39

     That is a great explanation thanks :). I have noticed 1 thing with my bot and I see it doesn't seem to do what I think it should (I'm blaming my code) so I just wanted to ask that after it performs an executeOnSelection, mySelection1 and I change status <- goToMyNextTrigger and I have another executeOnSelection mySelection2 (when new conditions are true), it can do multiple executions with different selections right?  It may be because my action happens near the end of the race but I only ever see 1 bet.

  • Stefan
    11.10.2019 10:28:42

    I created ScalpingTradingStrategyBot.fsx bot trigger as a case study for some trading strategy I read about on other forum. Unfortunately I forget to put link to that forum but posted on my blog this article:

    Greyhounds Racing - Scalping Trading Strategy Bot

    Please read it first if you did not do so before.

    So in the bot trigger code I created MyTraderBot taking selection and stake amount as entry parameters, lines from 50 (the bot constructor) to 86.

    As mentioned MyTraderBot orchestrates two “PlaceBetBot”s The parameter setting is created by function createBotParameters, lines from 27 to 38. As you may noticed (have a look at on the line 52) any bfexplorer bot is created as bot type, and uses its parameters, so in this case for PlaceBetBot, there is bot implementation type PlaceBetBot, and parameters the type (class) PlaceBetBotParameters. PlaceBetBot implements all bot logic, and parameters just describer set of parameters the bot can use, for instance BetType and Stake the bot places bet with.

    Bot must be executed on exact market and selection, therefore for instance of the bot object is created (lines 52 and 53), the bot comstructor takes market, selection, botPrameters and bfexplorerService.

    BfexplorerService object implements betfair api and application domain. When you run your bot trigger, actually your code uses BfexplorerService to interact with betfair api.

    The other used bot is: ClosePositionOnMarketBot, and from the name of this bot type, you can judge what this bot does. Therefore the bot constructor does not take any selection as entry value. The bot parameters are implemented by type: ClosePositionOnMarketBotParameters.

    The bot closes bet position when required profit is reached (Profit parameter, the line 102), and well ends execution of all running bots, that is executed before the bet closes selections bet position.

    Finally fot trigger code, the lines from 133 to 159. When bot trigger is executed, on all active selections there is created instance of MyTraderBot and one instance of ClosePositionOnMarketBot, the code line 145. When checking the code in createMyBots function, you can see that starting a bot is done by adding to the market, the line 111, the same in lines 65 and 66.

    When is actually your bot executed?

    Well, it is done by BfexplorerService after market prices have been updated, your bot is actually just object instance, and its execution time is limited only by short time when BfexplorerService updates entire status of market and bets data.

    The bot strategy is to place back and lay bets on selections, and as the bets are placed by PlaceBetBot, we need to update range of allowed odds range, the lines from 68 to 86, the method Update. We need to update this parameters on for running bots, lines from 149 to 153.

    Why bot trigger ScalpingTradingStrategyBot does not implement any logic to ends its execution? It can be simply done by checking if there is still MyTraderBot running on some selection.

    Well, because we orchestrate in this case two types of bots, and one of them closes/ends execution of all other bots before closing bet position on the market.

    This bot trigger code is nice example of advantages of using bfexplorer action bots, as nay strategy can be executed by these action bots. Your trigger strategy should define/implements just entry and exit criteria in time. The rest is executed by action bots.

    Use the code only as inspiration, as there is no logic in entry points implemented by MyTraderBot.

  • peteresgate@outlook.com
    11.10.2019 6:32:39

    I didn't explain properly sorry.  What I mean is I can see it create the bot and it has bot.Start to place the trades.  Then the next part I don't understand.  You run Update, which from what I can see only changes the parameters, so how did the bot place trades again and use the new parameters?  I can't see how it executed new trades based on what is in  the Update()

  • Stefan
    10.10.2019 13:50:57

    I do not understand in what context you want to execute your bots and what method you want to use, because ScalpingTradingStrategyBot.fsx uses direct initialization of PlaceBet bot instances and ClosePositionOnMarketBot bot instance.

    For now you worked only with action bots, changing their parameters.

    Why do you need directly to create your bots?

    In your bot trigger code I already mentioned that you repeat the code, is the question about this issue?

  • peteresgate@outlook.com
    10.10.2019 11:28:39

    I've been looking at the scalping bot and the way it creates the bots, I like it a lot.  Do you have another example of creating a bot with parameters like the scalping bot, but with a method call to execute on mySelection from within member_execute?  For example 1 method call I would have parameters and betType lay for mySelection and another method call would have different parameters for a different mySelection betType back  etc.  From your examples I am learning a lot, but I couldn't find one like this.

  • Stefan
    9.10.2019 9:52:19

    Programming languages use different syntax, and of course set of types. In F# float is C# double, and as F# is .net language you have got access to anything from .net framework.

    https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/literals

  • Stefan
    8.10.2019 15:51:11

    I do not know why you need two other lists to make your new list having only selections with profit and unmatched lay bets.

    Any information you need are in Selection object. I created short console script where you can see how to make different filter functions:

    ShowSelectionsWithProfitAndUnmatchedBets.fsx

    Basically you should orchestrate bot strategy(ies) execution in your trigger code, so the same way you can query for running bots, and running bot on a selection is still indication that your trading session, or bet placing is not yet finished.

    Another hint, please really use Visual Studio InteliSense support, as typing . (dot) in the name of object variable gives you all properties or methods you can use on the object. I mean what I created you could figure out as well.

  • Stefan
    7.10.2019 10:48:02

    For the property BetType, the BetType is not string/text value. It is enumeration value, so you must assign BetType.Back or BetType.Lay

    For “Place Bet and Close Selection Bet Position Bot” you have got OpenBetPosition or CloseBetPosition properties, so exact path to particular parameters, in OpenBetPosition is:

    “OpenBetPosition.Stake”

    “OpenBetPosition.BetType”

    And for “Place Bet” bot the parameter names are simple:

    “Stake”

    “BetType”

    Only you know what action bot you will use, so therefore you must know names of action bot parameters. When you always use just “Place Bet” bot then you do not have to code it naming convention of parameters, but when your bot trigger can execute trading bots, then introduce to your bot trigger parameters for instance parameter: “IsTradingActionBot” and when you set it to True, you must add OpenBetPosition. or CloseBetPosition. prefix to the parameter names you want to change. 

    There are of course different ways to create bot instance and execute them, please have a look at here: ScalpingTradingStrategyBot.fsx

    Or just investigate all options for TriggerResult discriminated union type, there are 10 different options for TriggerResult.Execute..

    You are using the option to edit parameters of set action bot, so what you set in “BotName” parameter of "Execute Trigger Bot".

  • Stefan
    5.10.2019 12:13:52

    Just a hint, you really overcomplicate your code. You should separate logic part/s in your code to function/s. For instance you introduced new parameter and named it strategy.

    From your code I can estimate that your intention was to generate allowedSelectionIndexes when the parameter AllowedSelectionIndexes is not entered.

    So you could take this code out from getMySelections function and create a new function that will return just text representation of your strategy number to text representation of allowed selections, so function:

    val strategyToIndexes : int -> string

    That is function signature. Please, maybe you should read this article:

    https://fsharpforfunandprofit.com/posts/how-types-work-with-functions/

    So simply said everything in F# is function, and returns some value, if nothing is return it is called unit.

    Then even “if else then”, is function and returns value, and it is clear that all blocks of if evaluation must return the same value, but I think you already noticed that, but your coding style did not change because you repeatedly type too much code.

    Ok, that is not a problem for now because bot trigger code will work anyway, but on the other hand your code would be shorter, maybe even more than 50% of current code.

    I do not know why would you need to evaluate what is retuned by getMySelection()  function, that other comment with match expression.

    Just hover with your mouse over getMySelection and read tooltip VS shows, it shows function signature:

    val : getMySelection : (unit -> Selection option)

    So what does it mean?

    getMySelection is function taking no input value/s (unit) and returning option type of Selection

    Option can be Some value or None, so in this context getMySelection returns Some selection on which your want to trigger your action bot. If no qualified selection is evaluated by your trigger code than it returns None.

    When starting to build/develop a new trigger you can create functions so they all describe your entire algorithm, and in Execute function then you should see/read your algorithm just by reading function names, all functions could be declared as empty code, just with correct function signature, so in the first stage of development you would just express your trigger algorithm by pure functions, then later start to implement the code to all functions and when necessary adds new ones.

    As your bot trigger cannot be executed in one market update call, it is good idea to introduce trigger status value like I did with TriggerStatus (discriminated union type):

    https://fsharpforfunandprofit.com/posts/discriminated-unions/

    It is clear that I created domain of that discriminated union in the domain of your horse racing trigger, therefore you can see that I named one status:  WaitForRaceStart (and I could name it more generally)

    Now you want to add a new status to your trigger, as you want to evaluate previous bet results, the question is where in the status queue you add this new one, and it is up to you.

    I already described necessary code in my previous comment, but here is another version:

    HorseRacingAndPreviousResultsBotTrigger.fsx

  • peteresgate@outlook.com
    5.10.2019 7:29:57

    Actually, I think I can work it out thanks, but could you please show me how to get trigger to "get" past strategy results.  Thanks

  • peteresgate@outlook.com
    5.10.2019 4:51:26

    Is there a way to

    match getMySelection() with
    | Some mySortedSelection -> (where mySortedSelection is a list?) 

    instead of having a lot of

     match getMySelection() with
    | Some mySelection1 ->

     match getMySelection() with
    | Some mySelection2 ->

     match getMySelection() with
    | Some mySelection3 ->........................etc

     

  • Stefan
    4.10.2019 16:04:07

    I see you are quick learner, as you managed to learn match expression, my congratulation.

    For allowed selections it is initialized mySelections that is list of MySelection objects.

    When race is started setStartData sets start price and position.

    When is time to start your strategy getMySelection function on the line 185 reevaluates set parametes, so odds difference and horse position difference. In your case you use only position difference, and on the line 187 you have got mySelections sorted by PositionDifference.

    My original code take just first selection with minimal position difference, keep in mind that minus values are less than 0.

    If you want to apply different algorithm for selecting a selection from mySortedSelections, then you can simply apply any filter function on this mySortedSelections, or of course sort mySelections by different property, or sortByDescending.

    You can change the line 208 according to your selection algorithm.

  • peteresgate@outlook.com
    4.10.2019 4:07:02

    Please see Your Code for Part 2 (with some additions and comments)  There is 1 thing that I cannot see in the code (line 187 - 192), and that is when a horse has improved in position, then I don't want it in mySelection.  I only want to lay it if it is in the same position or has worsened in position, (and not in top 3 which is coded on line 194).  Is it somewhere that I cannot see?

    https://github.com/PeterEsgate/BfexplorerTestBots/blob/master/HorseRacingBotTrigger2-3.fsx

  • Stefan
    2.10.2019 14:04:20

    For me it is really hard to help you with understanding a programming language, because I know many programming languages, and all is understandable for me.

    I can read or start programming with any programming language just from seeing code samples or tutorials in minutes.

    I would suggest reading the following post, or entire web site:

    https://fsharpforfunandprofit.com/posts/fsharp-in-60-seconds/

    On the Internet you can find a lot of videos, tutorials, books, and so on. As I mentioned if you have problems to understand F#, and C# is better alternative then you can switch your code to C# or Visual Basic.

  • 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 :)

  • Stefan
    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.

  • Stefan
    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

  • Stefan
    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