Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created July 14, 2020 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanBelo/59b1250075104667c87c85d3a4d7f138 to your computer and use it in GitHub Desktop.
Save StefanBelo/59b1250075104667c87c85d3a4d7f138 to your computer and use it in GitHub Desktop.
// 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 System.Diagnostics
open System.Net
open System.Net.Mail
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
// https://myaccount.google.com/lesssecureapps
let FromEmail = "your@mail.com"
let ToEmail = "your@mail.com"
/// <summary>
/// EmailService
/// </summary>
type EmailService() =
let smtpClient = new SmtpClient("smtp.gmail.com", 587)
do
//smtpClient.DeliveryMethod <- SmtpDeliveryMethod.Network
//smtpClient.UseDefaultCredentials <- true
smtpClient.Credentials <- NetworkCredential("your@mail.com", "yourpassword")
smtpClient.EnableSsl <- true
static let instance = lazy(EmailService())
static member Instance
with get() = instance.Force()
member _this.Send(subject, message) =
try
let mailMessage = new MailMessage(FromEmail, ToEmail, subject, message)
smtpClient.SendMailAsync(mailMessage) |> Async.AwaitTask |> Async.Start
with
| ex -> Debug.WriteLine(ex.Message)
let isMatchedBet (bet : Bet) =
match bet.OrderStatus with
| BetOrderStatus.Matched
| BetOrderStatus.PartiallyMatched -> true
| _ -> false
let toBetHashCode (bet : Bet) =
sprintf "%s%.2f" bet.Id bet.Size
/// <summary>
/// BetMatchedNotificationBot
/// </summary>
type BetMatchedNotificationBot(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let getMatchedBetsHashCode() = maybe {
if market.Bets.HaveMatchedBets
then
return
market.Bets
|> Seq.filter isMatchedBet
|> Seq.map toBetHashCode
|> String.concat "|"
}
let matchedBetsToString() =
let matchedBets =
market.Bets
|> Seq.filter isMatchedBet
|> Seq.map (fun bet -> bet.ToString())
|> String.concat "\n"
sprintf "%s\n\nMatched bets:\n\n%s" market.MarketFullName matchedBets
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let mutable matchedBetsHashCode : string = defaultArg (getMatchedBetsHashCode()) String.Empty
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
getMatchedBetsHashCode()
|> Option.iter (fun hashCode ->
if matchedBetsHashCode <> hashCode
then
matchedBetsHashCode <- hashCode
let message = matchedBetsToString()
EmailService.Instance.Send("Matched bets on betfair", message)
outputMessage message
)
TriggerResult.WaitingForOperation
/// <summary>
/// EndExecution
/// </summary>
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment