phillc73 / abettor Goto Github PK
View Code? Open in Web Editor NEWAn R package for connecting to the online betting exchange Betfair, via their API-NG product, using JSON-RPC.
License: Other
An R package for connecting to the online betting exchange Betfair, via their API-NG product, using JSON-RPC.
License: Other
Error in function (type, msg, asError = TRUE) :
SSL certificate problem: self signed certificate in certificate chain
loginBF wants to verify SSL certificates with path inputs
Fix:
loginBF2 = function(username, password, applicationKey)
{
credentials <- paste("username=", username, "&password=", password, sep = "")
headersLogin <- list(Accept = "application/json", X-Application
= applicationKey)
loginReturn <- RCurl::postForm("https://identitysso.betfair.com/api/login", .opts = list(postfields = credentials, httpheader = headersLogin, ssl.verifypeer = FALSE))
authenticationKey <- jsonlite::fromJSON(loginReturn)
headersPostLogin <- NULL
headersPostLogin <<- list(Accept = "application/json", X-Application
= authenticationKey$product,
X-Authentication
= authenticationKey$token, Content-Type
= "application/json")
}
just added the ssl verification = FALSE in the RCurl options
Hello,
Ive just upgraded toR Version r and when I try to reinstall the abbettpr package it tells me its not available for R version 4. Can this ne fixed as I need R version 4.
The functions checkBalance
and listMarketPandL
should be renamed to match the naming convention used in the Betfair API calls, for consistency with the rest of the library.
Specifically that is:
checkBalance
to getAccountFunds
listMarketPandL
to listMarketProfitAndLoss
Old function names should re-direct to new function names for backwards compatibility.
Hi,
I seem to be getting bet failures when using the limit on close functionality:
Back bet example at BSP which is working well
placeOrders(
marketId=nmarketId,
selectionId=nselectionId,betSide="BACK",
betSize=2,
reqPrice="1.01",
betType="MARKET_ON_CLOSE",
persistenceType="MARKET_ON_CLOSE",
customerRef=nref,
sslVerify=FALSE)
Lay bet example at BSP which is limit on close and is not working - have i got syntax wrong at all?
placeOrders(
marketId=nmarketId,
selectionId=nselectionId,
betSide="LAY",
betSize=nstake,
reqPrice="5.00",
betType="LIMIT_ON_CLOSE",
customerRef=nref,
sslVerify=FALSE)
Many thanks
Jake.
Hi there Phil - great package and I'm loving it's simplicity and ease of use - Thanks!!
I'm building a shiny app that looks for value bets by combining a web-scraper for bookmaker odds and betfair markets.
One thing that repeatedly halts the Shiny app is when I forget to run the Login function upfront.
Is there any opportunity to check for "Logged In" status at Betfair? Or is a better alternative to use a Login and Logout call for every session?
Hi phillc73,
Is there a way to see inplay markets with abettor?
I have a live score scraper that I want to combine with the current live odds of a match to determine if a bet should be placed. Basically, if a bunch of scenarios with the score and the odds happen simultaneously I will get an alert from R through a text or email (in Australia we have to call betfair to place the bet so I can't automate the placing of the order).
Is it possible to get these odds in abettor or is there another way to get this?
thanks,
Nick
There is a minor change being introduced to listCurrentOrders - see https://forum.developer.betfair.com/forum/developer-program/announcements/35152-new-api-release-w-c-9th-august-listcurrentorders-includeitemdescription
This is a simple addition of an optional parameter. Once the change is rolled out I will add the parameter and submit a pull request.
I'm a bit new to this but with the function:
listMarketBook(marketIds = racetemp, priceData = "EX_ALL_OFFERS", sslVerify = FALSE)
is it possible to list a vector of marketIds to create a dataframe or can it only handle one marketid at a time?
thanks,
In listevents
There are no markets for Australian horse racing.
The httr provides a much nicer and easier to user interface than RCurl. I'd like to change this package to use httr rather than RCurl.
See backblazer
package for example:
https://github.com/phillc73/backblazer/blob/master/R/b2AuthorizeAccount.R
Passing in a string for customerOrderRef or customerStrategyRef in the placeOrder function executes fine, but if i try to find it when calling listClearedOrders at a later stage, I cant find it.
Hi
I am an Italian user of Betfair and I just installed abettor to access Betfair's API. I am currently able to log in to the API using the Italian API Endpoint but then every time I run a command I get always the same error :
code message data.APINGException.requestUUID data.APINGException.errorCode data.APINGException.errorDetails data.exceptionname 1 -32099 ANGX-0007 prdang036-11151112-0006a5fb53 INVALID_APP_KEY APINGException Warning message: In listEventTypes() : Error- See output for details
I really don't know what to do to fix it, I hope you can help me with this issue.
Thank you for your time and consideration
When using Roxygen, listRunnerBook
fails with the following error:
r$> roxygen2::roxygenise()
Loading abettor
Warning: [/home/phillc/Development/Horse Racing/abettor/R/listRunnerBook.R:1] @title Missing name
Warning: The existing 'NAMESPACE' file was not generated by roxygen2, and will not be overwritten.
Warning messages:
1: roxygen2 requires Encoding: UTF-8
2: In readLines(con, warn = FALSE, n = n, ok = ok, skipNul = skipNul) :
invalid input found on input connection '/home/phillc/Development/Horse Racing/abettor/R/listRunnerBook.R'
Hi, I am sometimes getting an 'Expectation Failed' error when I try to submit bets using the placeOrder function. Is this a known issue? Is it to do with this?
https://forum.bdp.betfair.com/showthread.php?t=2901
Is there any known way to prevent this error when using abettor?
Many thanks.
Chris
The current placeOrders function is not working correctly for customerOrderRef and handicap fields. Fix is straightforward and will put in a pull request with updated code.
Laying on a horse with starting price like this
placeOrders(
marketId = market_id,
selectionId = runners[1,]$selectionId,
betSide = "LAY",
betSize = "2",
betType = "MARKET_ON_CLOSE"
)
throws the error "INVALID_BET_SIZE". Backing the horse runs normally. I read that another person in 2017 had the same problem, but I already updated the newest version...
The current implementation of the placeOrders function covers the required elements and some others but there are more fields that are not currently implemented. Adding each field into the function definition would be messy and deviates from Betfair's definition in the API docs. I'm developing an alternative methodology where the instruction list is passed in as a dataframe which seems to work after a lot of experimentation. The order list is built using some simple rules and only required fields need to be supplied.
What is the best way to share this? Give it a new name like placeOrdersDF and add it to my fork? (Sorry I'm still a github noob).
The following Betting API calls are not yet supported by abettor
and probably could/should be:
I rewrote this function a few months ago to allow the retrieval of more than 100 records. It works but the code uses the legacyData fields rather than the itemClassData
json field. This was my first contribution to abettor and it shows - the code is messy, difficult to read and this may make it more error prone.
I've been trying to work out how to unpack the json in a more efficient manner but it is proving difficult. Seeking the help of some experts on this. If anybody reading this can help with unpacking a dataframe of elements, each of which is in a json (key/value pair) format that would be greatly appreciated.
My attempts have been along these lines and have all ended in a similar place, none of them with the clean dataframe structure that is required as an output from the function. I put the json field into a dataframe using
accItem <- accOrder$result$accountStatement$itemClassData
Then have tried using
accDF <- map(accItem[,1], jsonlite::fromJSON(simplifyDataFrame = simplifyDataFrame))
which appears to give a dataframe with 100 eelements, each of which is a list with 21 elements - the 21 fields from within itemClassData
.
Betfair provides API access to historic pricing data. abettor
does not yet support this part of the API and probably could/should.
https://historicdata.betfair.com/#/home
https://historicdata.betfair.com/#/apidocs
Only five functions to consider:
This question was raised in another forum:
Has the output of the getAccountStatement() function in the R abettor library changed recently? I haven't run this function in awhile as I've been paper trading, but ran it today to find my code crashing due to missing columns/new columns.
When I looked at the code and output it seems that only the legacy data is being returned correctly. I'm working on a solution which looks obvious but untangling the structure into a clean dataframe is proving challenging.
The following Accounts API calls exist, but are not yet supported by abettor
. Package should be updated to include them.
The listCurrentOrders function does not currently include the customerOrderRefs and customerStrategyRefs parameters. These are optional parameters which can be used to restrict the results to particular customer order/strategy refs.
It was mentioned in another forum recently that the handicap field isn't being passed to the API. The solution is simple so I'll combine this with a fix for issue #64.
The maximum number of records that can be returned from an API call is 100. This means users of this function have to use the function repetitively to get their full account statement. It would be preferable if the function handled this and returned all available records as the default.
I have written some code to address this and will do a pull request in the next day or so.
Hello all,
I've used the library to find the eventTypeIDs and competitionID I need, which are 2378961 and 11339499 respectively. But I can't seem to get historical data for them. I would have thought that Betfair would provide this under 'Other Sports' but I guess that isn't the case.
Ideally, I'd like historical data for them going back to the beginning of this year.
If anyone has any pointers that would be really appreciated. Thank you!
For some reason, I just cannot login?? betfairlightweight in python works with the same credentials (username, pwd and applicationkey), but I keep getting the error: "FAIL:INVALID_USERNAME_OR_PASSWORD" in R? Maybe it is an issue with the 2FA? Any advice?
Hi team - apologies in advance for logging an issue if this is not the right place to put it - but I wasn't sure how else to ask for help.
I'm attempting to build a betting bot and I'm keen to try and find market value amongst bookies, using the betfair lay markets as a guide close to jump time.
Abettor is magical in granting rapid, reliable access to the Betfair API - thanks so much for building it! My troubles start in the data-wrangling after executing a "listMarketBook" call. Essentially, I'm really struggling using any of the base or tidyverse methods to be able to pull the "availableToLay" list up to a level that also includes the marketId and SelectionId variables. ie - what I'd like to end up with is a long list of selectionId's (runner name would be even better, but let's start with what we've got first!) and prices - but I have to traverse through the "ex" list and that seems to be breaking every single time.
I've tried unnest(), unnest_longer() and unnest_wider(), hoist(), pluck() and flatten() but nothing seems to run without error!
Any tips or pointers that might help push me in the right direction?
I've tried all sorts of documentation for the tidyverse and this doesn't seem to be something that anyone on StackOverrflow has face either!
Again - apologies if this isn't the right forum - but I'm running out of ideas to get help!
Cheers,
Sam
Some new functions added and help content updated for others. Need to regenerate all the package documentation.
Hi Phill
When trying to use logoutBF(), I get this message returned:
Error in function (type, msg, asError = TRUE) :
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Am able login successfully. Error message is returned when sslVerify is set to F or T.
Thanks
Chris
abettor
does not currently support the Race Status API, but probably should.
Looks like one API call. - listRaceDetails
From the Betfair website:
The listRaceDetails operation is provided to allow customers to establish the status of a horse or greyhound race market both prior to and after the start of the race. This information is available for UK, Ireland and South African races only and is provided for information purposes only
Betfair customers from Spain, Italy and Sweden need to use a separate end point to access the API.
Spain info
Italy info
Sweden info
Not sure how to go about effectively testing this. Would need some testers in those countries.
Hi @phillc73 ,
I am currently trying to build a betfair app and have come across your package. I am trying to download install the package according to the README file.
I am running Windows 7 64-bit and have installed Rtools v3.1
The code I am looking to run and the response is as follows
> devtools::install_github('phillc73/abbetor')
Downloading github repo phillc73/abbetor@master
Error in download(dest, src, auth) : client error: (404) Not Found
Are you able to help me to download the package?
Many thanks!
This previously worked but does not seem to be working now. listCurrentOrders still works correctly - although that is coded slightly differently.
Recently updated to R 4.1.0 and not sure if this has created the issue.
Hi, I've read the documentation on the listMarketBook function but I'm not sure where I'm going wrong.
I'd like to create a dataframe which, for a particular marketId, shows the total volume traded at each price. (Anyone can find this through the betfair website if you click the little graph icon next to each runner in a market.) I've used the listMarketBook function and tried each permutation of orderProjection, matchProjection, rollupModel and priceData. Each time the same identical information comes back, which is the current prices availableToBack, availableToLay; but not the information on what's been matched already. Can anyone advise what arguments I should be using in the function?
Hi,
Yesterday I started getting this error at login:
> loginBF(username = user, password = pass, applicationKey = appKey)
<SSL_CONNECT_ERROR in function (type, msg, asError = TRUE) { if (!is.character(type)) { i = match(type, CURLcodeValues) typeName = if (is.na(i)) character() else names(CURLcodeValues)[i] } typeName = gsub("^CURLE_", "", typeName) fun = (if (asError) stop else warning) fun(structure(list(message = msg, call = sys.call()), class = c(typeName, "GenericCurlError", "error", "condition")))}(35L, "error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol", TRUE): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol>
Error in function (type, msg, asError = TRUE) :
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Is this related with Betfair's recent change in communications security settings, allowing only TLS 1.2 protocols?
This is the email I got from Betfair, on 01/02/2019.
Subject: Betfair API - TLS 1.2 - from 7th February 2019
(...)
Please be aware that from 7th February, the only protocol for securing the communication between Betfair servers and web browsers at login will be TLS 1.2. Older versions (TLS.1.0, TLS.1.1 or SSLv3) will no longer work.
Although we don't expect this to have an impact on API clients we'd recommend that you refer to the following resources depending on your programming language/framework to confirm that your using TLS 1.2 or above:
(...)
My current version of RCurl appears to be using an older protocol
> RCurl::curlVersion()$ssl_version
[1] "OpenSSL/1.0.0o"
Is there a quick fix to this?
Thank you!
Hi there.
I'm getting a strange result when I try listMarketCatalogue for the politics market through the api. This is the code I am running:
event.Types <- listEventTypes()
politics.ID <- event.Types$eventType$id[grep("Politics",event.Types$eventType$name)]
listCountries(eventTypeIds=politicsID)
market.Type <- listMarketTypes(eventTypeIds=politics.ID)$marketType
listMarketCatalogue(eventTypeIds=politics.ID, marketCountries="GB", marketTypeCodes = market.Type)
But it seems to return:
> listMarketCatalogue(eventTypeIds=politics.ID, marketCountries="GB", marketTypeCodes = market.Type)
data frame with 0 columns and 0 rows
Any idea what I might be doing wrong?
Thanks for the nice package, btw!
J
abettor
does not currently support the Betfair Heartbeat API, but probably should.
Looks like one API call, with three endpoints for UK (global?), Italian and Spanish exchange.
Hi Phill,
It would nice to be able to access your betfair balance so that I could instruct the automated program to bet a proportion of bank rather than flat stakes.
It would also be great if it were possible to access profit and loss (or just simple account bet result data) in order to produce daily/weekly betting reports relevant to selections.
Many thanks,
Jake.
Hi
getAccountStatement crashes at the line
accNewOrders[, fixColNames]
with the error
Error in `[.data.frame`(accNewOrders, , fixColNames) :
undefined columns selected
...if the first page of results contained the column deadHeatPriceDivisor
but the current page doesn't contain this column. Looks like fixColNames only gets set the first time through the main loop so whatever columns are present on that page, it expects to see on subsequent pages -- but appears the API doesn't include at least that specific column unless statement items on the current page require it -- hence the error.
A simple hack is to add deadHeatPriceDivisor
to the list of columns excluded when the data is pulled in.
accNewOrders[, "legacyData"] <- NULL
is already executed... just add
accNewOrders[, "deadHeatPriceDivisor"] <- NULL
I'm not sure if there would be knock-on effects from implementing this as a fix, but it works for me for this specific issue. I would imagine there are other 'special case' columns which would create the same problem so a more general solution would be preferable.
Hi,
The function placeOrders() doesn't seem to allow for more than 2 simultaneous back/lay orders, returning "Error: Expectation Failed".
placeOrders(
marketId = "1.130459350",
selectionId = as.character(c(10463405, 10463405, 11160430)),
betSide = rep("LAY", 3),
betType = "LIMIT",
betSize = rep(as.character(2), 3),
reqPrice = rep(as.character(1.2), 3),
persistenceType = rep("LAPSE", 3)
)
Error: Expectation Failed
Am I wrongly specifying any of the arguments? Or is there a limit on the number of bets per request imposed by the betfair API?
Looking at the betfair's API documentation on placing orders, it reads: "The limit of place instructions per request is 200 for the UK/AUS Exchange (...)"
In any case, I must also add that the package works a treat - you've than an excellent job!
Many thanks in advance,
Bruno
Received this on another forum:
I've been messing about with the getAccountStatement
function lately trying to work out why it always goes back 90 days when I just want the last 24 hrs worth of activity. It seems that the function isn't passing the date range I specify as the correct variable. In the function there are these two lines to set the date range:
getAccStatOps$params$daterange$from <- fromDate
getAccStatOps$params$daterange$to <- toDate
But according to the API docs the parameter should be called itemDateRange
not daterange.
Changing the parameter name speeds up the call by a lot!
Hi, I've received this error when running any of the 'list' commands. Any ideas what the bug might be?
listCompetitions(eventTypeIds=1,
toDate = (format(Sys.time() + 86400 * 365, "%Y-%m-%dT%TZ"))
)
Error in function (type, msg, asError = TRUE) :
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Hi Phil,
I can't seem to get the horseracing place bet at SP working. I'm using either of these lines:
placeOrders(marketId="1.122275822",selectionId="9414882",betSide="BACK",betType="LIMIT_ON_CLOSE",betSize="2",reqPrice ="1.01",persistenceType="MARKET_ON_CLOSE", sslVerify = FALSE)
or
placeOrders(marketId="1.122275822",selectionId="9414882",betSide="BACK",betType="MARKET_ON_CLOSE",betSize="2",reqPrice ="1.01",persistenceType="MARKET_ON_CLOSE", sslVerify = FALSE)
And checking my betfair account afterwards but nothing appears to be happening. It works find in normal back immediate markets but not SP - Is there a setting that i have wrong?
thanks,
Jake.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.