Bfexplorer Console allows you to use scripting programming language to query and process betfair market data retrieved by bfexplorer. Here there is short introduction to the scripting language. You can test following scripts just by opening Bfexplorer Console and copy and paste the script code to the console input, and then exec uting the code by clicking on Execute button.
Accessing the active market open in Bet Event Trader:
printf "Active market %A" bfexplorer.ActiveMarket
The function printf prints formatted string to the Output view. In this case the name of the market.
Showing runners with the last price traded and non runners:
let market = bfexplorer.ActiveMarket
let getSelections status =
market.Selections
|> Seq.filter (fun selection -> selection.Status = status)
|> Seq.toArray
let runners = getSelections SelectionStatus.Active
let nonRunners = getSelections SelectionStatus.Removed
printfn "Active market %A" market
runners
|> Array.iter (fun selection -> printfn "%s, %.2f" selection.Name selection.LastPriceTraded)
let numberOfNonRunners = nonRunners.Length
if numberOfNonRunners > 0
then
printfn "\n%d non runner/s:" numberOfNonRunners
nonRunners
|> Array.iter (fun selection -> printfn "%s" selection.Name)
else
printfn "\n%s" "No non runners"
You can see that you can declare variables and functions.
Showing the winners:
let market = bfexplorer.ActiveMarket
let getSelections status =
market.Selections
|> Seq.filter (fun selection -> selection.Status = status)
|> Seq.toArray
let winners = getSelections SelectionStatus.Winner
if Seq.isEmpty winners
then
printfn "No winner/s known for the market: %A" market
else
printfn "The winner/s for the market: %A" market
winners
|> Seq.iter (fun selection -> printfn "%s" selection.Name)
After a market is closed the winner/s is/are set on the market selection/s.
If you use Execute Till Target Profit bot, then you can ask for your strategy results:
#r "BeloSoft.Bfexplorer.Trading.dll"
open BeloSoft.Bfexplorer.Trading
MyStrategyOperations.GetMyStrategyResults("My strategy - lay favourite")
|> Option.iter (fun myStrategyResults ->
printf "%A, Winning bets: %d, Losing bets: %d"
myStrategyResults
myStrategyResults.TotalWinningBets
myStrategyResults.TotalLosingBets
)
And in more details:
#r "BeloSoft.Bfexplorer.Trading.dll"
open BeloSoft.Bfexplorer.Trading
let getThreeFavourites (market : Market) =
market.Selections
|> Seq.filter (fun selection -> selection.Status <> SelectionStatus.Removed)
|> Seq.sortBy (fun selection -> selection.LastPriceTraded)
|> Seq.take 3
|> Seq.toArray
let getMySelection (market : Market) =
market.Selections
|> Seq.find (fun selection -> selection.Bets.HaveBets)
MyStrategyOperations.GetMyStrategyResults("My strategy - lay favourite")
|> Option.iter (fun myStrategyResults ->
printfn "%A, Winning bets: %d, Losing bets: %d" myStrategyResults myStrategyResults.TotalWinningBets myStrategyResults.TotalLosingBets
myStrategyResults.SettledMarkets |> Seq.iter (fun market ->
if market.SettledProfit.HasValue
then
let mySelection = getMySelection(market)
let threeFavourites = getThreeFavourites(market)
let threeFavouritesBookValue = threeFavourites |> Array.sumBy (fun selection -> 100.0 / selection.LastPriceTraded)
printfn "%A, Profit: %.2f, My selection: %s, %.2f, Book value: %.2f, Prices: %s"
market market.SettledProfit.Value
mySelection.Name mySelection.LastPriceTraded
threeFavouritesBookValue
(threeFavourites |> Array.map (fun selection -> (sprintf "%.2f" selection.LastPriceTraded)) |> String.concat ", ")
)
)
To add all open market favourites to the Watched Selections view:
let GetFavourite(market : Market) =
market.Selections
|> Seq.filter (fun selection -> selection.Status = SelectionStatus.Active)
|> Seq.sortBy (fun selection -> selection.LastPriceTraded)
|> Seq.head
let marketSelections =
bfexplorer.OpenMarkets
|> Seq.sortBy (fun market -> market.MarketInfo.StartTime)
|> Seq.map (fun market ->
{
MarketSelection.Market = market
MarketSelection.Selection = GetFavourite(market)
})
bfexplorer.WatchMarketSelections(marketSelections)
To close all open markets:
bfexplorer.CloseAllMarkets()
Show horses form:
let GetHorseForm(horse : Selection) =
match horse.MetaData with
| Some metaData -> Some metaData.Form
| None -> None
bfexplorer.ActiveMarket.Selections |> Seq.iter (fun horse ->
let form = GetHorseForm(horse)
if form.IsSome
then
printfn "%s: %s" horse.Name form.Value
)