User Comments

  • Stefan
    22.10.2019 13:29:38

    Full market data are available in the active market, so in the only market open in Bet Event View or in Bet Event Trader View.

    Why is it so?

    Bfexplorer can monitor hundreds of markets so this way it is reasonably lower amount of data loaded from betfair servers.

    Yes you can get matched volume only through PriceGridData, of course you must iterate through prices with traded volume, not all of 399 prices are traded.

    If you run your bot in Bot Executor, then you can simply use the bot: “Execute at Time” and set the parameter: UseSetMarketInactive to True. So when executed in bot executes your action bot and set MonitoringStatus to Inactive, Bot Executor then removes such market from monitoring and opens it in Bet Event view, so your bot have them full market data available.

    Of course there are other betfair api methods you can use to get traded data betfair uses in charts. You can see that in my post:

    Lay the Field Strategy – Analyzing Data

  • Stefan
    20.10.2019 15:27:07

    Here is my bot trigger showing on ladders near BSP and after the race is turned at in-play the actual BSP:


  • Stefan
    20.10.2019 10:38:19

    Actually, there are such bot triggers:



    As an example you could create a bot trigger showing for active selections near BSP and actual BSP after race is turned at in-play. You can show prices on ladder, like in this example:

    Horse Racing - Oddschecker Favourite Trigger

  • Stefan
    20.10.2019 10:24:09

    Yes, placing betfair sp bet returns matched bet with matched amount zero, as SP bet is fully matched only after race is turned at in-play and all betfair start price bets are processed.  This be cannot be cancelled I believe, well have never try that.

    You can place normal bet with Take SP, such bet can be cancelled and unmatched part of bet is turned to SP at the moment race is turned at in-play.

    Have a look at UpdateSpPricesMarketBot.fs if you want to update sp prices, but that is bot assembly, not bot trigger code. You have got access to betfair api in bot trigger code, so you need to study betfair documentation and then you can replicated code working with sp prices in bot trigger as well.


  • Stefan
    17.10.2019 9:41:41

    That is great Peter.

    I would really suggest you to set breakpoint in your code and then debug it and browse available data offered by bfexplorer.

    You must know what data you have got, visualize them in your head, and then you know what you can do with data.

    Your approach for now is browsing existing code, so when you did not find similar one you cannot make progress, but data you have got, so working with data is the way to go.

  • Stefan
    16.10.2019 20:38:18

    On the line 3 of your code, there are set three values: startIndex, nextIndex, findFun

    The findFun is function used to evaluate the place with empty offer. So when you want to place back bet, it must be checked lay offer and wise versa.

    You change that code, therefore your findFun function returns true on offer with available offer. Actually in your code I cannot see logical problem because you start iterating through data on the best offer, so price must be set.

    If you code does not go to the line 23, as you say price returned is always 0.0

    Peter, how/where you execute your bot trigger?

    The full market depth is updated only for active market, so for the market that is currently open in Bet Event/Trader.

    It means that if you run your bot by Bot Executor tool you will get updates only for 3 best offered prices.

    I would suggest you to debug code, only this way you can find your problem in the code.

    Hint: There is function selection.PriceGridData.GetOfferedPriceData()

    You can use to get all offered prices. I do not know what you want to make in your code, so this function: GetOfferedPriceData returns all offered prices, and you can filter whatever criteria you use.

    Here is bot trigger code:


    Peter, please use VS debugger when testing your code.

  • Stefan
    14.10.2019 13:04:41

    I have just updated Bfexplorer BOT SDK source code adding MyFootballStrategy projects showing how to use Bfexplorer Plugin integration.

    The MyFootballStrategy.App is working example. If you trade football matches on betfair you can use it to monitor all matches live score and match statistics.

    If anyone wants to collaborate on this project adding new features, and is able to program, then of course you can clone entire Bfexplorer BOT SDK solution.

    Those of you who just want to use this app, and are not able to build plugin from the source code, just contact me through support page and I will send you app/plugin files.

  • Stefan
    14.10.2019 10:29:39

    One of TriggerResult discriminated unions entry is:

    TriggerResult.OpenAssociatedMarkets of string[] * (DataResult<Market list> -> unit)

    Allowing requesting associated markets to the market you are running your bot on.

    Every market is open as bet event on betfair, and you have got access to this information:


    So bfexplorer when you request TriggerResult.OpenAssociatedMarkets knows for which bet event id the associated markets should be queried.

    Please have a look at on this bot trigger script:


    Basically your bot has access to all betfair api methods:


    So you could be able to write any code against betfair api. The question is, is this approach practical?

    Your bot is executed on exact type of market, for instance on horse racing win market, so what markets would you like to open in Bet Event view? Tennis match odds market, or football match odds market?

    In any such scenario common sense dictates that you want to open associated market for bet event on which your bot is running, for instance place horse racing market, when your bot runs on win horse racing market and so on.

    If you want to build your bespoke app on bfexplorer app, you can do so like I present in this article:

    Bfexplorer Plugin Support

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

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

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

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

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


    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:



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



    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:

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

    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:


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

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

    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.

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

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

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