ClosePosition bot with NET stake

On some selections (usually favs) I "close position" manually by NET stake (without hedging). Is it possible add this feature to any ClosePos bot?

Comments (10)

  1. StefanBelo Says:
    Tuesday, January 12, 2010

    Bot Executor: Close Position on the Outcome

    I have just updated the latest version of Bfexplorer PRO adding the NET stake feature for the bot: Close Position on the Outcome

    This bot script offers two parameters now:

    • UseNetStake
    • MinReturnOnInvestment

    If you set the UseNetStake parameter to True the bot will close your position by NET stake, otherwise the bot hedge your position with equal profit or loss when the parameter MinReturnOnInvestment is set to 0.

    You can level your profit by setting the parameter MinReturnOnInvestment to number different from 0, if the number is bigger than 0 more profit is taken to the back side otherwise to the lay side.

    You can notice that setting the parameter MinReturnOnInvestment to 100 would close your position by NET stake if your current position is profitable, but if your current position is in loss then +100 would mean closing position by adding more on the back side.

    You can prepare different settings and test them first in the practice mode to understand how it works in different situations.

    This bot just having two parameters but giving you many opportunities for use. I have got 5 different settings for this bot in my Bot Executor.

  2. Mir. Says:
    Tuesday, January 12, 2010

    Is it possible set   runnerProperty.UseNetStake = truein for example ClosePositionOnAllSelections bot ?

  3. StefanBelo Says:
    Tuesday, January 12, 2010

    Yes it is possible, when I implemented the Bot Executor My Bot setting parameters I added just set of parameters and name them according to functionality they execute.

    Well those parameters were named according to the most used bot parameters in my bot scripts at that time and is clear as more different bot scripts were added later more parameters were added, I had to stop at some number of parameters, so with the new bot script I mapped new parameters to the existing ones, if not all parameters were used of course.

    The bot script: Close Position on the Outcome maps two parameters:

    /*
     * Used parameters:
     * 
     * StakeIsMyLiability (Place the NET stake)
     * MinReturnOnInvestment
     */
    

    So if you want to use the bot script: Bfexplorer.Scripting.SetupBotOnRunners to run ClosePositionOnOutcomeBot bot on all runners use the mentioned parameter:

    StakeIsMyLiability to True

    and the rest of parameters as discribed here: How to run a bot on each market selection

    • BotType MyBot
    • ExtraBotType ClosePositionOnOutcome
    • MyBotClassName Bfexplorer.Scripting.SetupBotOnRunners
    • PlaceBetOnProbableWinner True
    • PlaceBetOnRunners 1000 (This is just fake number of runners so the bot will check real number of runners)

    With this setting all your opened positions will be closed with NET stake.

  4. Mir. Says:
    Wednesday, January 13, 2010

    Well done. Works fine. Thx.

    And what can I do with unmatched bets after (before) "ClosePosition"? I dont know how Cancel bets on all selections  (I use ClosePositionOnAllSelections bot)

  5. StefanBelo Says:
    Thursday, January 14, 2010

    Betfair bot: Bfexplorer.Scripting.ClosePositionOnAllSelections

    I updated the bot script: ClosePositionOnAllSelections to cancel all umantched bet on a market before closing your position.

    class ClosePositionOnAllSelections : Bot
    {
      private bool unmatchedBetsCancelled;
    
      public ClosePositionOnAllSelections(IBetfairService betfairService, 
                     MonitoredMarket monitoredMarket, Runner runner)
        : base(betfairService, monitoredMarket, runner)
      {
      }
    
      public override void DoYourJob()
      {
        base.DoYourJob();
    
        if (GetIsTimeToClosePosition())
        {
          if (unmatchedBetsCancelled)
          {
            Stop();
            ClosePosition();
          }
          else
          {
            CancelAllUnmatchedBets();
            unmatchedBetsCancelled = true;
          }
        }
      }
    
      private bool GetIsTimeToClosePosition()
      {
        return RunnerProperty.ClosePositionAt != DateTime.MinValue && 
                  DateTime.Now >= RunnerProperty.ClosePositionAt;
      }
    
      private void CancelAllUnmatchedBets()
      {
        MyBets myBets = monitoredMarket.MyBets;
    
        if (myBets.HaveUnmatchedBets)
        {
          betfairService.CancelBetsByMarket(monitoredMarket, RunnerId);
        }
      }
    
      private void ClosePosition()
      {
        Runner[] runners = monitoredMarket.MarketDetails.Runners;
    
        foreach (Runner runner in runners)
        {
          RunnerProperty runnerProperty = runner.RunnerProperty;
    
          runnerProperty.BotType = BotType.ClosePositionOnOutcome;
          runnerProperty.ExecuteBot = true;
    
          // If you want to close position by NET stake uncomment the line below.
          //runnerProperty.StakeIsMyLiability = true;
          runnerProperty.MinReturnOnInvestment = 0;
        }
    
        betfairService.StartBots(monitoredMarket);
      }
    }
    

    You can download the source code here, unzip the file and copy the betfair bot script to MyBots folder.

  6. Mir. Says:
    Friday, January 15, 2010

    Thank you for your help.

  7. bookmakers55 Says:
    Friday, February 26, 2010

    MyBotClassName

    Good evening

    I want to know what this category and is located T'on or files to download would be a topic on this subject.

    example: Bfexplorer.Scripting.ClosePositionForMarket.cs

    What use to specify it in my bot and what function is ca.

    Thank you

  8. StefanBelo Says:
    Monday, March 01, 2010

    Please read following article: Close Position for whole Market

  9. machdesign Says:
    Wednesday, August 11, 2010

    Close Position with NET Stake

    Hello Stefan,

    How can I setup a bot, which will close position with NET stake exactly on the selection when previous bot (for example PlaceBet) is/was running? For example if chaining two bots, the first one stops in time 20 sec. before the event starts and then i want to close (with NET stake) the position on which the first bot was running.

    Thank you

  10. StefanBelo Says:
    Wednesday, August 11, 2010

    ExecuteBotCriteriaDataFile and ExecuteConcurrentlyBotCriteriaDataFile

    The bot: close position on the outcome is the only bot able to close position by placing a bet with the NET stake. On the other hand, this bot has no parameter you could use to define at what profit/loss the bot should close position.

    If you want to create a chaining bot script using the bot: ExecuteBotCriteriaDataFile then you will have to create two bot settings, in the first bot setting you will use Place bet bot and in the second setting the Close position on the outcome and you will set selection criteria to execute this bot only when offered odds on the selection are higher than MaxOdds you set for Place bet bot, when placing lay bet to open your position, and vice-versa.

    Alternatively, when placing bet on better odds (the parameter: PlaceBetAtBetterOdds is set to True), you could use the Close position on the outcome bot without any means to postpone bot execution by selection criteria, as in most cases the bot will close position with 1 tick difference, but as well couple ticks in loss in the worst case!

    When your two bot settings are created and for instance you named those two bot settings: Place lay bet Close by NET stake

    As you first added Place lay bet, and then Close by NET stake, they are listed at the end of your bots in the Bot Executor window.

    If those two settings are not in the correct order, for instance you created them before, then use drag and drop operation to change the order of those two bot settings, so the Place lay bot is before Close by NET stake.

    Now you can export those two bot settings and save them into a file. The last step is to create ExecuteBotCriteriaDataFile bot so you can execute your new bots combining two different bots. Read more about it in these forum articles.


Do you want to comment this article? Sign up here or login.

User Menu