Blog Article

Close position with hedging Immediately

Hi Stefan

I have written my first bot and it seems to be working ok, the bot carries out the following

* Waits for a Horse race to go inplay

* Backs the favorate using a call to a standard place back bet bot

* Monitors the race and if the favorate changes it then closes the position and lays the old favorate

The problem is in test mode the lay bet often takes several attempts to get matched and by the time it does the race is nearly over and I lose all my stake. The only way I could find to close my position was to use 2 bots one to execute on all and one to close my position.

Is there a command I can use from within the script to close my position on the previuos favorate ?

Also is there a list of BFexplorer commands for use in scripts that would be a great referance

 

Mike

  • Add Your Comment

    +

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

Comments ( 5 )


  • Stefan
    17.8.2018 20:18:53

    Mike, shortly to your last question, do you know what spellchecker is?

  • kinghobo
    19.8.2018 17:34:51

     Yes I do know what a spellchecker is, I'm starting to wonder if you know what customer service is , I'm paying £30 a month for this product on which you offer support but seem only to find the time to write sarcastic messages 

  • Stefan
    19.8.2018 19:34:28

    Mike, this is not a joke, but I wanted to start with something you, and I believe everyone working with computer knows.

    So in text editor app, the spellchecker checks your grammar underlying misspelled or wrong words by red line. If there are more options to correct wrong word a list of options is presented.

    It is the same when you write code in IDE, any wrong construction of your code is underlined by red line, and error icon with possible solutions is presented. In IDE it is called Intelisense, and option to present properties or methods available for object types your code interacts with.

    In trigger code, you can interact only with objects offered by bfexplorer app when trigger is instantiated, so that is your world of objects the intelisense offers properties and methods to you, so there is no need to make a list of offered objects your trigger can interact with, you already have this option in your IDE (Visual Studio, Visual Code, Atom, or whatever you use).

    That is answer to your last question! Do we understand each other?

    Watch video in my article: Betfair Bot Programming for Non-Developers

    Where you can see what I am talking about, intelisense support, method description, for instance when hovering over code, or functions descriptions, like for Execute method there is description: unit -> TriggerResult, so you know that function takes no arguments (unit) and returns TriggerResult

    What is TriggerResult and what options it offers is again offered to you by intelisense, when typing TriggerResult following . intelisense offers you list of all options you can use.

    So basically any written code is checked against any error, and options are offered like spellchecker offers you correcting your bad spelling.

    Keep in mind that using bfexplorer you agreed with T&C and I suggest to read it again if you did not do so.

  • Stefan
    20.8.2018 11:36:24

    IntelliSense in action:

  • Stefan
    23.8.2018 9:56:52

    In-play horse racing markets are very volatile. I made short video showing situation on such in-play horse racing win market, you can see that in many cases back book value goes from 101 up to 135% what means there is big gap between best offered back/lay prices.

    On in-play markets there is applied bet placement delay (1 second for horse racing markets), therefore placed bet calculated at current best offer price can be unmatched, when it appears on the market after bet placement delay expires. Close selection bet position offers the parameter: BetMatchingTimeout, so when you bet is not fully matched bot waits for set bet matching timeout, so for chance the unmatched bet be matched, and when bet is not fully matched it is cancelled and bot tries again to close your bet position at set parameters.

    Keep in mind that betfair applies so called best execution rule when bet is placed, it means when there is better bet price then price you asked for in your offer, your bet is matched at this better price. This rule can introduced some problems when closing your bet position, or when hedging, as the hedging bet stake is calculated to exact priced.

    When this best execution rule is applied your bet position is not equally hedged, therefore is such in-play scenarios is a good idea to use “Close Market Bet Position”, this bot closes bet position on all selections where is possible to close bet position, and checks if position evenly closed, if not bot tries again to close bet position trying to level profit/loss on all applicable selections.

    This bot (“Close Market Bet Position”) offers the parameter: ClosePositionAtTime, when set to unrealist value, for instance to -1.00:00:00 (minus one day), bot immediately closes bet position on market, not checking whether Profit/Loss were reached.

    In your trading scenario is better to use trading bot: “Place Bet and Close Selection Bet Position” setting the parameter: CloseBetPosition/ClosePositionImmediately what means that after your opening bet is fully matched bet to close your trading position in Profit is calculated and immediately placed on market offering it.

    If you want to execute your strategy with two bots: “Place Bet” and “Close Selection Bet Position” then first evaluate all offered parameters to get the best execution of your bot, switch off parameter: CheckingLastPriceTraded, try different values for BetMatchingTimeout, OfferMyBet.

    You can program your own Close Bet Position bot of course, for instance checking gap between bets offered back/lay prices, you can place your bet in the middle of the offered prices, or just calculating latest price trend you can place your bet at most probable matched price.

    The last possibility is to change your trading strategy to place dutch bets on potential winners.