PlaceAtBetterOdds Bot
Posted in Tutorials by StefanBelo Tags: bot programming
In this bot tutorial I will you show how to extend the PlaceBetBot feature. The inspiration to write such kind of betfair bot was found at the betfair forum.
Can anyone tell me the simplest way to lay dogs at a reasonable back to lay ratio. I believe I would have to use triggers to do this, but as the dogs liquidity isn't great, I need to nail this properly.
Also if anyone can tell me the best bot software to use - I have been practicing with marketfeeder pro.
It would be preferable if I could lay at back price if unmatched within 30 secs lay at the higher price.
The bot implementation
My implementation uses the PlaceBet bot, the bot already built-in in any bfexplorer application. Again I will use all what this bot offers adding a new functionality to it. In this case I want to place a bet at better odds, what means when placing a lay bet the bot will ask for lay bet at the best offered back price and vice versa. If the bet is not matched the bot should take what is offered.
All I need to do is override the DoYourJob method and add the required functionaly, as the PlaceBetBot is instructed to place the bet at better odds I need to check if this bet is still unmatched after the preset time for matching the bet, if this time expired, the bot will update the bet or its unmatched parts to the current offered odds, and that is all.
using System;
using System.Collections.Generic;
using BeloSoft.Betfair.Data;
using BeloSoft.Betfair.Data.Betting;
using BeloSoft.Betfair.Trading;
namespace Bfexplorer.Scripting
{
class PlaceAtBetterOddsBot : PlaceBetBot
{
// Const
private const short TakeOfferedAfter = 30;
// Data
private DateTime? betPlacedTime;
public PlaceAtBetterOddsBot(IBetfairService betfairService,
MonitoredMarket monitoredMarket, Runner runner)
: base(betfairService, monitoredMarket, runner)
{
RunnerProperty.PlaceBetAtBetterOdds = true;
}
public override void DoYourJob()
{
base.DoYourJob();
switch (tradingState)
{
case TradingState.BackingInProgress:
case TradingState.LayingInProgress:
if (GetIsTimeToTakeOfferedOdds())
{
UpdateBetToOfferedOdds();
}
break;
default:
break;
}
}
private bool GetIsTimeToTakeOfferedOdds()
{
if (betPlacedTime.HasValue)
{
return (DateTime.Now - betPlacedTime.Value).TotalSeconds >= TakeOfferedAfter;
}
else
{
betPlacedTime = DateTime.Now;
}
return false;
}
private void UpdateBetToOfferedOdds()
{
List unmatchedBets = monitoredMarket.MyBets.GetUnmatchedBetsBySelectionAndOdds(runner.SelectionId, runner.AsianLineId, placedAtOdds);
BetPrice bestPrice = betType == BetType.Back ? runner.BestPriceToBack : runner.BestPriceToLay;
if (unmatchedBets != null && bestPrice != null)
{
double odds = bestPrice.Price;
AddMessage(string.Format("Updating the bet odds to: {0:N}", odds));
List betsToUpdate = new List();
foreach (Bet bet in unmatchedBets)
{
betsToUpdate.Add(new UpdateBet(bet, odds, bet.BetPrice.Amount));
}
UpdateBets(betsToUpdate);
placedAtOdds = odds;
betPlacedTime = DateTime.Now;
}
}
}
}
How to run the bot
You can run this bot with the Bot Executor or with the Trade Opportunity Lookup Service when setting the bot criteria for this bot. Your bot full class name is:
- Bfexplorer.Scripting.PlaceAtBetterOddsBot
The bot parameters you can set are following:
- BetType
- MinimalOdds
- MaximalOdds
- PlaceBetAtBetterOdds
- Stake
- AllowPlacingBetInPlay
- AtInPlayCancelBet
- StartBetPlaceFrom
You can download the source code here and the bot criteria settings to import into the Bot Executor here.
Happy bot coding!
