Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. // Bfexplorer cannot be held responsible for any losses or damages incurred during the use of this betfair bot.
  2. // It is up to you to determine the level of risk you wish to trade under.
  3. // Do not gamble with money you cannot afford to lose.
  4.  
  5. module FootballReportGoalsScoredBotTrigger
  6.  
  7. //#I @"D:\Projects\Bfexplorer\Development\Applications\BeloSoft.Bfexplorer.App\bin\Debug\"
  8. #I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
  9.  
  10. #r "BeloSoft.Data.dll"
  11. #r "BeloSoft.Betfair.API.dll"
  12. #r "BeloSoft.Bfexplorer.Domain.dll"
  13. #r "BeloSoft.Bfexplorer.FootballScoreProvider.dll"
  14. #r "BeloSoft.Bfexplorer.Trading.dll"
  15. #r "BeloSoft.Bfexplorer.Service.Core.dll"
  16.  
  17. open System.Text
  18.  
  19. open BeloSoft.Data
  20. open BeloSoft.Bfexplorer.Domain
  21. open BeloSoft.Bfexplorer.Trading
  22. open BeloSoft.Bfexplorer.FootballScoreProvider
  23. open BeloSoft.Bfexplorer.FootballScoreProvider.API.Models
  24. open BeloSoft.Bfexplorer.FootballScoreProvider.Models
  25.  
  26. /// <summary>
  27. /// TriggerStatus
  28. /// </summary>
  29. type TriggerStatus =
  30. | Initialize
  31. | UpdateMatchScore
  32. | FailedToUpdateMatchScore
  33. | WaitToGetMatchDetails
  34. | ReportGoalScored
  35.  
  36. /// <summary>
  37. /// FootballReportGoalsScoredBotTrigger
  38. /// </summary>
  39. type FootballReportGoalsScoredBotTrigger(market : Market, selection : Selection, botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
  40.  
  41. let mutable status = TriggerStatus.Initialize
  42. let mutable footballMatch = nil<FootballMatch>
  43. let mutable matchDetailData = nil<MatchDetailData>
  44.  
  45. let footballMatchScoreUpdated(result : bool) =
  46. status <-
  47. if result
  48. then
  49. Async.StartWithContinuations(
  50. computation = FootballScoreProvider.GetMatchDetails(footballMatch),
  51. continuation = (fun result ->
  52. status <-
  53. if result.IsSuccessResult
  54. then
  55. matchDetailData <- result.SuccessResult
  56. TriggerStatus.ReportGoalScored
  57. else
  58. TriggerStatus.FailedToUpdateMatchScore
  59. ),
  60. exceptionContinuation = (fun _ -> status <- TriggerStatus.FailedToUpdateMatchScore),
  61. cancellationContinuation = (fun _ -> status <- TriggerStatus.FailedToUpdateMatchScore)
  62. )
  63.  
  64. TriggerStatus.WaitToGetMatchDetails
  65. else
  66. TriggerStatus.FailedToUpdateMatchScore
  67.  
  68. let initialize() =
  69. if market.MarketInfo.BetEventType.Id = 1 && market.MarketDescription.MarketType = "MATCH_ODDS"
  70. then
  71. footballMatch <- CreateFootballMatch market
  72.  
  73. TriggerResult.UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated)
  74. else
  75. TriggerResult.EndExecutionWithMessage "You can execute this bot only on a football market."
  76.  
  77. let getGoals(updateDetails : UpdateDetailData[]) =
  78. if updateDetails.Length > 0
  79. then
  80. updateDetails |> Array.map (fun updateDetail -> sprintf "%d' %s" updateDetail.MatchTime updateDetail.Team) |> String.concat ", "
  81. else
  82. "no goals scored"
  83.  
  84. let reportGoalScored() =
  85. let sb = StringBuilder()
  86.  
  87. sb.AppendLine(footballMatch.ToString()) |> ignore
  88.  
  89. let goals = matchDetailData.UpdateDetails |> Array.filter (fun updateDetail -> updateDetail.UpdateType = "Goal")
  90.  
  91. let message =
  92. if goals.Length > 0
  93. then
  94. let firstHalfGoals, secondHalfGoals = goals |> Array.partition (fun updateDetail -> updateDetail.MatchTime <= 45)
  95.  
  96. sb
  97. .AppendLine(sprintf "The first half goals: %s" (getGoals(firstHalfGoals)))
  98. .AppendLine(sprintf "The second half goals: %s" (getGoals(secondHalfGoals)))
  99. .ToString()
  100. else
  101. sb
  102. .AppendLine("No goals scored.")
  103. .ToString()
  104.  
  105. myBfexplorer.BfexplorerService.OutputMessage(message)
  106. TriggerResult.EndExecution
  107.  
  108. interface IBotTrigger with
  109.  
  110. /// <summary>
  111. /// Execute
  112. /// </summary>
  113. member this.Execute() =
  114. match status with
  115. | TriggerStatus.Initialize -> initialize()
  116. | TriggerStatus.UpdateMatchScore -> UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated)
  117. | TriggerStatus.FailedToUpdateMatchScore -> EndExecutionWithMessage "Failed to update the match score."
  118. | TriggerStatus.WaitToGetMatchDetails -> WaitingForOperation
  119. | TriggerStatus.ReportGoalScored -> reportGoalScored()
  120.  
  121. /// <summary>
  122. /// EndExecution
  123. /// </summary>
  124. member this.EndExecution() =
  125. ()
Add Comment
Please, Sign In to add comment