Skip to content

Commit

Permalink
Mostly global function definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
phillc73 committed Dec 15, 2014
1 parent 39bf4e2 commit d0f6690
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 29 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: abettor
Title: R bindings to the Betfair API-NG
Version: 0.1
Date: 2014-12-10
Title: R bindings to Betfair API-NG
Version: 0.1.1
Date: 2014-12-15
Authors@R: as.person(c("Phill Clarke <phill@starkingdom.co.uk> [aut, cre]"))
Description: An R package for connecting to the online betting exchange,
Betfair, via their API-NG product using JSON-RPC. The package user can
Expand All @@ -11,6 +11,7 @@ Depends:
License: MIT + file LICENSE
URL: https://github.com/phillc73/abettor
BugReports: http://www.github.com/phillc73/abettor/issues
Maintainer: Phill Clarke <phill@starkingdom.co.uk>
LazyData: true
Imports:
RCurl (>= 1.95-4.3),
Expand Down
4 changes: 2 additions & 2 deletions R/listCountries.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ listCountries <- function(eventTypeIds){

listCountriesOps <- listCountriesOps[c("jsonrpc", "method", "params", "id")]

listCountriesOps <- toJSON(listCountriesOps, pretty = TRUE)
listCountriesOps <- jsonlite::toJSON(listCountriesOps, pretty = TRUE)

listCountries <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listCountriesOps, httpheader=headersPostLogin))))
listCountries <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listCountriesOps, httpheader=headersPostLogin))))

as.data.frame(listCountries$result[1])

Expand Down
4 changes: 2 additions & 2 deletions R/listEventTypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ listEventTypes <- function(){

listEventTypesOps <- listEventTypesOps[c("jsonrpc", "method", "params", "id")]

listEventTypesOps <- toJSON(listEventTypesOps, pretty = TRUE)
listEventTypesOps <- jsonlite::toJSON(listEventTypesOps, pretty = TRUE)

listEventsTypes <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listEventTypesOps, httpheader=headersPostLogin))))
listEventsTypes <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listEventTypesOps, httpheader=headersPostLogin))))

as.data.frame(listEventsTypes$result[1])

Expand Down
9 changes: 6 additions & 3 deletions R/listEvents.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
#' @examples
#' \dontrun{
#' # Return all Horse Racing events, between the current date & time and 11pm on December 10th, 2014
#' listEvents(eventTypeIds = 7, fromDate = format(Sys.time(), "%Y-%m-%dT%TZ"), toDate = "2014-12-15T23:00:00Z")
#' listEvents(eventTypeIds = 7,
#' fromDate = format(Sys.time(), "%Y-%m-%dT%TZ"),
#' toDate = "2014-12-15T23:00:00Z"
#' )
#'
#' # Return all Horse Racing events, using the default from and to datestamps.
#' listEvents(eventTypeIds = 7)
Expand All @@ -57,9 +60,9 @@ listEvents <- function(eventTypeIds, fromDate = (format(Sys.time(), "%Y-%m-%dT%T

listEventsOps <- listEventsOps[c("jsonrpc", "method", "params", "id")]

listEventsOps <- toJSON(listEventsOps, pretty = TRUE)
listEventsOps <- jsonlite::toJSON(listEventsOps, pretty = TRUE)

listEvents <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listEventsOps, httpheader=headersPostLogin))))
listEvents <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listEventsOps, httpheader=headersPostLogin))))

as.data.frame(listEvents$result[1])

Expand Down
4 changes: 2 additions & 2 deletions R/listMarketBook.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ listMarketBook <- function(marketIds, priceData){

listMarketBookOps <- listMarketBookOps[c("jsonrpc", "method", "params", "id")]

listMarketBookOps <- toJSON(listMarketBookOps, pretty = TRUE)
listMarketBookOps <- jsonlite::toJSON(listMarketBookOps, pretty = TRUE)

listMarketBook <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listMarketBookOps, httpheader=headersPostLogin))))
listMarketBook <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listMarketBookOps, httpheader=headersPostLogin))))

as.data.frame(listMarketBook$result[1])

Expand Down
9 changes: 6 additions & 3 deletions R/listMarketCatalogue.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
#'
#' # Return market catalogues for both Horse Racing and Football event types, in
#' Great Britain only and for both Win and Match Odds market types.
#' listMarketCatalogue(eventTypeIds = c("7","1"), marketCountries = "GB", marketTypeCodes = c("WIN", "MATCH_ODDS"))
#' listMarketCatalogue(eventTypeIds = c("7","1"),
#' marketCountries = "GB",
#' marketTypeCodes = c("WIN", "MATCH_ODDS")
#' )
#' }
#'

Expand All @@ -86,9 +89,9 @@ listMarketCatalogue <- function(eventTypeIds, marketCountries, marketTypeCodes,

listMarketCatalogueOps <- listMarketCatalogueOps[c("jsonrpc", "method", "params", "id")]

listMarketCatalogueOps <- toJSON(listMarketCatalogueOps, pretty = TRUE)
listMarketCatalogueOps <- jsonlite::toJSON(listMarketCatalogueOps, pretty = TRUE)

listMarketCatalogue <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listMarketCatalogueOps, httpheader=headersPostLogin))))
listMarketCatalogue <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listMarketCatalogueOps, httpheader=headersPostLogin))))

as.data.frame(listMarketCatalogue$result[1])

Expand Down
4 changes: 2 additions & 2 deletions R/listMarketTypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ listMarketTypes <- function(eventTypeIds){

listMarketTypesOps <- listMarketTypesOps[c("jsonrpc", "method", "params", "id")]

listMarketTypesOps <- toJSON(listMarketTypesOps, pretty = TRUE)
listMarketTypesOps <- jsonlite::toJSON(listMarketTypesOps, pretty = TRUE)

listMarketTypes <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listMarketTypesOps, httpheader=headersPostLogin))))
listMarketTypes <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=listMarketTypesOps, httpheader=headersPostLogin))))

as.data.frame(listMarketTypes$result[1])

Expand Down
11 changes: 8 additions & 3 deletions R/loginBF.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
#'
#' @examples
#' \dontrun{
#' loginBF(username = "YourBetfairUsername", password = "YourBetfairPassword", applicationKey = "YourBetfairAppKey")
#' loginBF(username = "YourBetfairUsername",
#' password = "YourBetfairPassword",
#' applicationKey = "YourBetfairAppKey"
#' )
#' }
#'

Expand All @@ -50,12 +53,14 @@ loginBF <- function(username, password, applicationKey){

headersLogin <- list('Accept' = 'application/json', 'X-Application' = applicationKey)

loginReturn <- postForm("https://identitysso.betfair.com/api/login", .opts=list(postfields=credentials, httpheader=headersLogin))
loginReturn <- RCurl::postForm("https://identitysso.betfair.com/api/login", .opts=list(postfields=credentials, httpheader=headersLogin))

authenticationKey <- fromJSON(loginReturn)
authenticationKey <- jsonlite::fromJSON(loginReturn)

# Assigning a global variable with <<-, I'm giddy with mischievious excitement

headersPostLogin <- NULL

headersPostLogin <<- list('Accept' = 'application/json', 'X-Application' = authenticationKey$product, 'X-Authentication' = authenticationKey$token, 'Content-Type' = 'application/json')

}
13 changes: 11 additions & 2 deletions R/placeOrders.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#' specified. Valid order types are LIMIT, LIMIT_ON_CLOSE and MARKET_ON_CLOSE.
#' Must be upper case. See note below explaining each of these options.
#' Required. no default.
#' @param betSize String. The size of the bet in the currency of your account.
#' Generally the minimum size for GB accounts is 2 Pounds.
#' @param reqPrice String. The lowest price at which you wish to place your bet.
#' If unmatched higher prices are available on the opposite side of the bet,
#' your order will be matched at those higher prices. Required. No default.
Expand Down Expand Up @@ -93,6 +95,13 @@
#'
#' @examples
#' \dontrun{
#' placeOrders(marketId = "yourMarketId",
#' selectionId = "yourSelectionId",
#' betSide = "BACKORLAY",
#' betType = "LIMITORONCLOSE",
#' betSize = "2",
#' reqPrice = "yourRequestedPrice",
#' persistenceType = "LAPSEORPERSIST")
#' }
#'

Expand All @@ -108,9 +117,9 @@ placeOrders <- function(marketId, selectionId, betSide, betType, betSize, reqPri

placeOrdersOps <- placeOrdersOps[c("jsonrpc", "method", "params", "id")]

placeOrdersOps <- toJSON(placeOrdersOps, pretty = TRUE)
placeOrdersOps <- jsonlite::toJSON(placeOrdersOps, pretty = TRUE)

placeOrders <- as.list(fromJSON(postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=placeOrdersOps, httpheader=headersPostLogin))))
placeOrders <- as.list(jsonlite::fromJSON(RCurl::postForm("https://api.betfair.com/exchange/betting/json-rpc/v1", .opts=list(postfields=placeOrdersOps, httpheader=headersPostLogin))))

as.data.frame(placeOrders$result[1])

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Each function contains documented descriptions for their use and all supported a

This package is under active development.

Current Version: 0.1
Current Version: 0.1.1

### Issues

Expand Down
5 changes: 4 additions & 1 deletion man/listEvents.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ opening date and market count.
\examples{
\dontrun{
# Return all Horse Racing events, between the current date & time and 11pm on December 10th, 2014
listEvents(eventTypeIds = 7, fromDate = format(Sys.time(), "\%Y-\%m-\%dT\%TZ"), toDate = "2014-12-15T23:00:00Z")
listEvents(eventTypeIds = 7,
fromDate = format(Sys.time(), "\%Y-\%m-\%dT\%TZ"),
toDate = "2014-12-15T23:00:00Z"
)

# Return all Horse Racing events, using the default from and to datestamps.
listEvents(eventTypeIds = 7)
Expand Down
5 changes: 4 additions & 1 deletion man/listMarketCatalogue.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ listMarketCatalogue(eventTypeIds = "7", marketCountries = "GB", marketTypeCodes

# Return market catalogues for both Horse Racing and Football event types, in
Great Britain only and for both Win and Match Odds market types.
listMarketCatalogue(eventTypeIds = c("7","1"), marketCountries = "GB", marketTypeCodes = c("WIN", "MATCH_ODDS"))
listMarketCatalogue(eventTypeIds = c("7","1"),
marketCountries = "GB",
marketTypeCodes = c("WIN", "MATCH_ODDS")
)
}
}
\seealso{
Expand Down
5 changes: 4 additions & 1 deletion man/loginBF.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ login more than is necessary.
}
\examples{
\dontrun{
loginBF(username = "YourBetfairUsername", password = "YourBetfairPassword", applicationKey = "YourBetfairAppKey")
loginBF(username = "YourBetfairUsername",
password = "YourBetfairPassword",
applicationKey = "YourBetfairAppKey"
)
}
}
10 changes: 10 additions & 0 deletions man/placeOrders.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ specified. Valid order types are LIMIT, LIMIT_ON_CLOSE and MARKET_ON_CLOSE.
Must be upper case. See note below explaining each of these options.
Required. no default.}

\item{betSize}{String. The size of the bet in the currency of your account.
Generally the minimum size for GB accounts is 2 Pounds.}

\item{reqPrice}{String. The lowest price at which you wish to place your bet.
If unmatched higher prices are available on the opposite side of the bet,
your order will be matched at those higher prices. Required. No default.}
Expand Down Expand Up @@ -114,6 +117,13 @@ correct argument options are used.
}
\examples{
\dontrun{
placeOrders(marketId = "yourMarketId",
selectionId = "yourSelectionId",
betSide = "BACKORLAY",
betType = "LIMITORONCLOSE",
betSize = "2",
reqPrice = "yourRequestedPrice",
persistenceType = "LAPSEORPERSIST")
}
}
\seealso{
Expand Down
4 changes: 1 addition & 3 deletions vignettes/abettor-placeBet.Rmd
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<!--
---
title: "How to Place a Bet with abettor"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{How to Place a Bet with abettor}
%\VignetteEngine{knitr::rmarkdown}
%\usepackage[utf8]{inputenc}
\usepackage[utf8]{inputenc}
---
-->

# How to Place a Bet with abettor

Expand Down

0 comments on commit d0f6690

Please sign in to comment.