betfaiR

This method still might require some work, especially in parsing the response from Betfair.

Having logged in using the betfair function, the environment contains the marketCatalogue method, which can be used to get market data. You use marketCatalogue to retrieve the name of the market, the names of selections, and other information about the market. Market Data Request Limits apply.

usage

bf$marketCatalogue(filter = marketFilter(),
                   marketProjection = NULL,
                   sort = NULL,
                   maxResults = 1,
                   keepRules = FALSE)

arguments

param details
filter select desired markets, see marketFilter for various parameters to filter by, or the relevant help pages on Betfair.
marketProjection the type and amount of data returned about the market, see section Market Projection in Betting Enums or visit the relevant section in the Betfair help pages for more details. The different options are COMPETITION, EVENT, EVENT_TYPE, MARKET_START_TIME, MARKET_DESCRIPTION, RUNNER_DESCRIPTION, and RUNNER_METADATA, these needn’t be entered in caps, however if any are misspelt they will be discarded.
sort the order of the results, see section sort in Betting Enums or the relevant section in the Betfair help pages
maxResults limit on the number of results returned, default = 1
keepRules when MARKET_DESCRIPTION is entered into the marketProjection paramater it returns a large amount of text containing the rules of the market, by default these are discarded, change keepRules = TRUE to return the rules.

return

A list with at least one dataframe about the market(s) filtered using the filter parameter (and the marketFilter function) and the maxResults paramater. Each market will have at most 4 dataframes in its list, all the variables are explained below, along with the marketProjection option that sees that variable returned. The list returned can be printed, allowing quick glance at markets before users can drill down into selections etc.

variable marketProjection dataframe details
marketId returned by default market id of the market
marketName returned by default market name of the market
totalMatched returned by default market amount of money already traded in the market
startTime MARKET_START_TIME market when the market opened
eventTypeId EVENT_TYPE market event type id (eg. 7 = Horse Racing, 1 = Football, etc)
eventTypeName EVENT_TYPE market event type name (eg. Horse Racing, Football, etc)
persistenceEnabled MARKET_DESCRIPTION description can bets be kept after the market goes in play
bspMarket MARKET_DESCRIPTION description does the market offer BSP
marketTime MARKET_DESCRIPTION description
suspendTime MARKET_DESCRIPTION description
bettingType MARKET_DESCRIPTION description type of bet, eg. ODDS
turnInPlayEnabled MARKET_DESCRIPTION description does the market go in play
marketType MARKET_DESCRIPTION description SPORT or NONSPORT
regulator MARKET_DESCRIPTION description typically “GILBRALTAR REGULATOR”
marketBaseRate MARKET_DESCRIPTION description
discountAllowed MARKET_DESCRIPTION description
wallet MARKET_DESCRIPTION description UK or Aus wallet
rulesHasDate MARKET_DESCRIPTION description
id EVENT event event id
name EVENT event event name
countryCode EVENT event event country code
timezone EVENT event event timezone
openDate EVENT event event opened
selectionId RUNNER_DESCRIPTION or RUNNER_METADATA runners selection id
runnerName RUNNER_DESCRIPTION or RUNNER_METADATA runners runner name
handicap RUNNER_DESCRIPTION or RUNNER_METADATA runners handicap of selection
sortPriority RUNNER_DESCRIPTION or RUNNER_METADATA runners ordered by amount matched
runnerId RUNNER_DESCRIPTION or RUNNER_METADATA runners runner id (same as selection id)

The runners dataframe above will likely include a lot of other data if RUNNER_METADATA is used, for horse racing this will include things like Weight carried, jockey, trainer, owner, etc. The list returned comes with print and summary methods, the print method will run through the markets returned and print basic data including market name, id, and matched. The summary method will run through the markets and print additional data about the market, including the first 6 (or fewer) runners/selections in the market.

examples

library(betfaiR)
# login
bf <- betfair(usr = Sys.getenv("bf_usr"),
              pwd = Sys.getenv("bf_pwd"),
              key = Sys.getenv("bf_key"))
Login successful
# get market data on just one market
tmp <- bf$marketCatalogue()
tmp

Market ID:       1.125398889
Market Name:     Article 50 triggered date
Matched:         230616.1
 ---------------------------------------------------------------------------
# get market data with details about the event and the runners
tmp <- bf$marketCatalogue(marketProjection = c("EVENT", "runner_metadata"))
summary(tmp)

Market ID:      1.125398889
Event ID:       28051207 
Market Name:    Article 50 triggered date
Event Name:     UK - Article 50 
Matched:        230616.15

Runners:     3 
 selectionId                     runnerName handicap sortPriority
    11379705                 Jan - Jun 2017        0            1
    11379706 Not triggered before July 2017        0            2
    11379700                    During 2016        0            3

 ---------------------------------------------------------------------------
# to access the runners data
tmp[[1]]$runners
  selectionId                     runnerName handicap sortPriority
1    11379705                 Jan - Jun 2017        0            1
2    11379706 Not triggered before July 2017        0            2
3    11379700                    During 2016        0            3
# horse racing data
tmp <- bf$marketCatalogue(filter = marketFilter(eventTypeIds = 7,
                                                marketCountries = "GB",
                                                marketTypeCodes = "WIN"),
                          marketProjection = c("event", "runner_metadata"))
summary(tmp)

Market ID:      1.129307035
Event ID:       28087305 
Market Name:    1m Hcap
Event Name:     Ling 25th Jan 
Matched:        3745.83

Runners:     8 
 selectionId      runnerName handicap sortPriority
    11374273   Sky Ballerina        0            1
    11990284    African Beat        0            2
    11333925    Tisbutadream        0            3
    11799692         Pobbles        0            4
    11511589 Washington Blue        0            5
    12162507        Touch Me        0            6

 ---------------------------------------------------------------------------
str(tmp[[1]]$metadata)
'data.frame':   8 obs. of  32 variables:
 $ sire_name                : chr  "Makfi" "Cape Cross" "Dream Ahead" "Medicean" ...
 $ cloth_number_alpha       : chr  "4" "1" "3" "6" ...
 $ official_rating          : chr  "72" "75" "74" "68" ...
 $ colours_description      : chr  "White, dark blue star, dark blue sleeves, white stars, white cap, dark blue star" "Royal blue" "White and yellow (halved), sleeves reversed, red and white striped cap" "Royal blue and white diamonds, white sleeves, royal blue armlets, quartered cap" ...
 $ colours_filename         : chr  "c20170125lin/00830679.jpg" "c20170125lin/00012133.jpg" "c20170125lin/00842067.jpg" "c20170125lin/00001908.jpg" ...
 $ forecastprice_denominator: chr  "2" "2" "2" "2" ...
 $ damsire_name             : chr  "Clodovil" "Dubai Destination" "Choisir" "Averti" ...
 $ weight_value             : chr  "130" "133" "132" "126" ...
 $ sex_type                 : chr  "f" "f" "f" "f" ...
 $ days_since_last_run      : chr  "15" "36" "12" "7" ...
 $ owner_name               : chr  "Mr Saeed H. Altayer" "Godolphin" "Mrs Anne Coughlan & Ten Green Bottles" "Mr D. J. Deer" ...
 $ dam_year_born            : chr  "2007" "2009" "2006" "2004" ...
 $ sire_bred                : chr  "UK" "IRE" "USA" "UK" ...
 $ jockey_name              : chr  "Martin Lane" "Robert Tart" "Shane Kelly" "Kieran Shoemark" ...
 $ dam_bred                 : chr  "IRE" "UK" "IRE" "UK" ...
 $ adjusted_rating          : chr  "0" "0" "0" "0" ...
 $ runnerid                 : chr  "11374273" "11990284" "11333925" "11799692" ...
 $ cloth_number             : chr  "4" "1" "3" "6" ...
 $ sire_year_born           : chr  "2007" "1994" "2008" "1997" ...
 $ trainer_name             : chr  "Simon Crisford" "John Gosden" "David Elsworth" "Roger Charlton" ...
 $ colour_type              : chr  "b" "b" "ch" "b" ...
 $ age                      : chr  "3" "3" "3" "3" ...
 $ damsire_bred             : chr  "IRE" "USA" "AUS" "IRE" ...
 $ form                     : chr  "404-1" "4144-" "627-1" "97569-2" ...
 $ forecastprice_numerator  : chr  "7" "7" "11" "15" ...
 $ bred                     : chr  "GB" "IRE" "IRE" "GB" ...
 $ dam_name                 : chr  "Maid In Heaven" "Rythmic" "Choose Me" "Oystermouth" ...
 $ damsire_year_born        : chr  "2000" "1999" "1999" "1991" ...
 $ stall_draw               : chr  "7" "3" "6" "5" ...
 $ weight_units             : chr  "pounds" "pounds" "pounds" "pounds" ...
 $ wearing                  : chr  NA NA NA "cheekpieces" ...
 $ jockey_claim             : chr  NA NA NA "3" ...