Forum Article

Using Multiple Bot Parameters

With my bot (still in design and testing stage), when it executes I'd like it to have a different effect on different selections, so I tried something like this: 

| TriggerStatus.StartTradingSessionPick1 

  status <- TriggerStatus.StartTradingSessionPick2
  let mySelection = (mySortedSelections |> List.item 3).Selection

  let myBotParameters = [ { MyBotParameter.Name = "Stake"; MyBotParameter.Value = 2.0 } ;{        MyBotParameter.Name = "BetType"; MyBotParameter.Value = "Lay"}] 
  TriggerResult.ExecuteActionBotOnSelectionWithParameters (mySelection, myBotParameters)

| TriggerStatus.rStartTradingSessionPick2 

status <- TriggerStatus.StartTradingSessionPick3 
let mySelection = (mySortedSelections |> List.item 4).Selection

let myBotParameters = [ { MyBotParameter.Name = "Stake"; MyBotParameter.Value = 3.0 } ;{ MyBotParameter.Name = "BetType"; MyBotParameter.Value = "Back"}]
TriggerResult.ExecuteActionBotOnSelectionWithParameters (mySelection, myBotParameters)

 

....etc

And as an ExecuteTriggerBot it runs Place Bet and Close Bet Position (So I can change the options with myBotParameters)

But it always fails with "Failed to set the bot parameter ________"

The code is here:

https://github.com/PeterEsgate/BfexplorerTestBots/blob/master/BotTrigger.fsx

 

I know the code needs some checks etc but I am only testing it right now.

Why can it not set the bot parameter and make a bet?

Thanks,

 

  • Add Your Comment

    +

    Please login to your bfexplorer account, if you want to add a comment to this article.

Comments ( 7 )


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

  • 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
    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
    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
    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 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 12:13:53

    Peter, post on github your code you want to review, and please add to files extension, then github code preview can highlight the syntax, as from ending .fs, or ,fsx it is known that code is F#.

    You can debug your code in Visual Studio, so you can really test each line of your bot trigger code, and so learn how your code works.