Betfair bot: Stop Monitor This Market

I see the method called StopMonitorThisMarket(MonitoredMarket monitoredMarket)

I also see a method you wrote to Remove a Market from the list yet this function does not seem to work. I also tried to write my own with no success.

I am able to stop monitoring a Market while the software is running. But when I try to remove a market from the list it does not work. It does not seem to want to remote the Market from your serialized file called MonitoredMarketsData.

Therefore my question is how do I programmatically remove a Market so that it removes itself from your MonitoredMarketsData file?

Pascal was right, the market monitoring was stopped but market was not removed from the monitored market list, the latest version fixes this problem.

To shed more lights on this feature of Bfexplorer BOT SDK I have prepared two bots scripts showing how to stop market monitoring. The first version is simple Bot script you can use with the Bot Executor. The bot uses to parameters:

  • ClosePositionAfter
  • ClosePositionAt
#define UseBotExecutorSettings

using BeloSoft.Betfair.Data;
using BeloSoft.Betfair.Trading;
using System;

namespace Bfexplorer.Scripting
{
  class StopMonitoringThisMarketBot : Bot
  {
    public StopMonitoringThisMarketBot(IBetfairService betfairService, 
          MonitoredMarket monitoredMarket, Runner runner)
      : base(betfairService, monitoredMarket, runner)
    {
    }

    public override void DoYourJob()
    {
      base.DoYourJob();

      if (GetCanStopMarketMonitoring())
      {
        betfairService.StopMonitorThisMarket(monitoredMarket);

        Stop();
      }
    }

    private bool GetCanStopMarketMonitoring()
    {
      #if UseBotExecutorSettings
      return RunnerProperty.ClosePositionAt != DateTime.MinValue ? 
               DateTime.Now >= RunnerProperty.ClosePositionAt : true;
      #else
      if (RunnerProperty.ClosePositionAt != DateTime.MinValue)
      {
          DateTime time = monitoredMarket.MarketDetails.MarketTime;
          TimeSpan closeAt = RunnerProperty.ClosePositionAt.TimeOfDay;

          return DateTime.Now >= (RunnerProperty.ClosePositionAfter ? 
                   time.Add(closeAt) : time.Subtract(closeAt));
      }

      return true;
      #endif
    }
  }
}

The second bot is LookUpBot script. When working with the Trade Opportunity Lookup Service (TOLS) you should realise that Bfexplorer uses two market monitoring services, so you can monitor the same market in the main service and also with TOLS. Therefore you have to check in the LookUpBot script if the same market is not already monitored.

You maybe noticed that LookUpBot script method DoYourJob returns false if you want to stop market monitoring in the TOLS, but you can also return true and even start market monitoring in the main service and running your action bot script. This concept enables to monitor and so to run bot scripts and LookUpBot script on the same betfair market.

using System;
using BeloSoft.Betfair.Data;
using BeloSoft.Betfair.Trading;
using BeloSoft.Betfair.Data.Betting;

namespace Bfexplorer.Scripting
{
  class StopMonitoringThisMarketLookUpBot : LookUpBot
  {
    // Const
    private const double StopMonitoring = 10;

    public StopMonitoringThisMarketLookUpBot(IBetfairService betfairService)
      : base(betfairService)
    {
    }

    public override bool DoYourJob(MonitoredMarket monitoredMarket)
    {
      if (GetCanStopMonitoring(monitoredMarket))
      {
        MonitoredMarket myMonitoredMarket = 
                 betfairService.GetMonitoredMarket(monitoredMarket.MarketId);

        if (myMonitoredMarket != null)
        {
          betfairService.StopMonitorThisMarket(myMonitoredMarket);
        }

        return false;
      }

      return true;
    }

    private bool GetCanStopMonitoring(MonitoredMarket monitoredMarket)
    {
      MarketDetails marketDetails = monitoredMarket.MarketDetails;

      return DateTime.Now >= marketDetails.MarketTime.AddSeconds(StopMonitoring);
    }
  }
}


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

User Menu