Backing and trading out the server in Tennis
This can be considered the classics on tennis betting. You back the current server relying on the player's obvious (though sometimes insignificant) advantage. At the end of the game, you hope to green up the bet. Should the player have lost his/her service, the size of the bet is doubled to try and recoup the loss in the next game.
BetFair provides the current score information for many in-play Tennis matches, so this makes it possible to implement the triggers that will do the above betting automatically.
There will also be situations when the server has indeed won the service, yet the prices do not allow you to green up your bet (for example, for some reason the back price at the start of the game was unrealistically low). In that case the triggers will trade it out anyway, but will not increase the bet for the next game.
You will find two blocks inside the file. The first block is needed to initialise some system variables used in the main set of triggers.
The second block will be repeated after the end of each game. The triggers inside match the current game against the one that was remembered after the initial bet, as well as check whether the backed selection has won the game.
In the constants you can set:
bet_size: Size of the initial back bet;
multiplier: The number by which to multiply the stake after the server loses;
min_price: Minimum price of the back bet. You will need this to stop the betting towards the end of the match when the prices are dangerously low;
max_price: Maximum price of the back bet. For a reason similar to the previous one, you need to limit the odds of your bet to stop from backing on an obvious underdog.
min_vlm: Minimum volume of matched bets. The higher the volume, the more liquidity is in the market and the more chances you have to green up your bet at the end of the game;
max_gap: Maximum gap (in ticks) between the back and lay prices. You would want to check the gap between the prices to establish the liquidity of the market. In a market where back and lay prices are too wide apart, this strategy will most likely fail as there will be too little chance to green up the price that was too low in the first place.
Triggers in Action
The trigger will start backing in the next available set where the server is known. Look for the green dot next to the player's name.
If the dot is missing, this means BetFair does not have data on who is serving, so you will have to skip that match. The triggers will only work in the tennis markets where the score is available!
The first time, the trigger will back when any of the players scores 15 points. This is done because it takes a while (several seconds) for BetFair to update the server information at the start of each game. I.e. it may look as the new game has started, with the point score 0-0, yet the server still takes a few seconds to change (keep this in mind for any other tennis strategy you will choose to pursue). Without having any historical knowledge about the previous games, the program can't risk backing the wrong player. In the subsequent games, it will back as soon as the server is changed.
At the end of the game the trigger will either green up the bet...
Or trade it out to an equal loss...
Or increase the next bet after a break by multiplying it according to the corresponding constant (multiplier):