Last active
November 28, 2018 11:56
-
-
Save StefanBelo/1cc72df4908a04f3b50c43eb3259b4ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bfexplorer cannot be held responsible for any losses or damages incurred during the use of this betfair bot. | |
// It is up to you to determine the level of risk you wish to trade under. | |
// Do not gamble with money you cannot afford to lose. | |
module BfexplorerBot | |
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\" | |
#r "BeloSoft.Data.dll" | |
#r "BeloSoft.Betfair.API.dll" | |
#r "BeloSoft.Bfexplorer.Domain.dll" | |
#r "BeloSoft.Bfexplorer.Trading.dll" | |
#r "BeloSoft.Bfexplorer.Service.Core.dll" | |
open System | |
open BeloSoft.Data | |
open BeloSoft.Bfexplorer.Domain | |
open BeloSoft.Bfexplorer.Trading | |
/// <summary> | |
/// TriggerStatus | |
/// </summary> | |
type TriggerStatus = | |
| PlaceBet | |
| WaitToPlaceNextBet | |
| AllBetsPlaced | |
/// <summary> | |
/// PlaceBetsAtTicksDifferenceBot | |
/// </summary> | |
type PlaceBetsAtTicksDifferenceBot(market : Market, selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) = | |
let betType = defaultArg (botTriggerParameters.GetEnumParameter<BetType>("BetType")) BetType.Back | |
let stake = defaultArg (botTriggerParameters.GetParameter<float>("Stake")) 10.0 | |
let oddsDifference = defaultArg (botTriggerParameters.GetParameter<int>("OddsDifference")) 20 | |
let numberOfBets = defaultArg (botTriggerParameters.GetParameter<int>("NumberOfBets")) 4 | |
let mutable status = TriggerStatus.PlaceBet | |
let mutable nextBetPrice = 0.0 | |
let mutable numberOfBetsPlaced = 0 | |
let outputMessage message = | |
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id) | |
let reportPlacingBets (bets : SelectionBetOrder list) = | |
let betReports = | |
bets | |
|> List.map (fun bet -> sprintf "%s: %A bet %.2f @ %.2f" bet.Selection.Name bet.BetType bet.Size bet.Price) | |
sprintf "Placing bet%s:\n%s" (if betReports.Length = 1 then String.Empty else "s") (betReports |> String.concat "\n") | |
|> outputMessage | |
let onBetsPlaced (_status : bool) = | |
numberOfBetsPlaced <- numberOfBetsPlaced + 1 | |
if numberOfBetsPlaced >= numberOfBets | |
then | |
status <- TriggerStatus.AllBetsPlaced | |
let canPlaceNextBet() = | |
let price = selection.GetBestPrice(betType) | |
if betType = BetType.Back | |
then | |
price >= nextBetPrice | |
else | |
price <= nextBetPrice | |
interface IBotTrigger with | |
/// <summary> | |
/// Execute | |
/// </summary> | |
member __.Execute() = | |
match status with | |
| TriggerStatus.PlaceBet -> | |
let price = selection.GetBestPrice(betType) | |
let bets = [ SelectionBetOrder.Create(selection, betType, price, stake) ] | |
nextBetPrice <- selection.OddsContext.GetNextOdds(price, oddsDifference, (betType = BetType.Back)) | |
status <- TriggerStatus.WaitToPlaceNextBet | |
reportPlacingBets bets | |
TriggerResult.PlaceBets (bets, PersistenceType.Lapse, onBetsPlaced) | |
| TriggerStatus.WaitToPlaceNextBet -> | |
if canPlaceNextBet() | |
then | |
status <- TriggerStatus.PlaceBet | |
TriggerResult.WaitingForOperation | |
| TriggerStatus.AllBetsPlaced -> TriggerResult.EndExecutionWithMessage "All bets has been placed." | |
/// <summary> | |
/// EndExecution | |
/// </summary> | |
member __.EndExecution() = | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment