Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.