Comments (1)
Sam,
I don't think tidyverse handles these complex structures well. My code (which was written a while ago and may not be optimal) looks a bit like this. It catches some errors and empty fields but probably not all. Let me know if you are having trouble getting it to work:
eventWins <- listMarketCatalogue(eventTypeIds = "7", marketTypeCodes = "WIN", marketIds = yourMarketId, marketProjection = c("COMPETITION", "EVENT", "EVENT_TYPE", "RUNNER_DESCRIPTION",
"MARKET_START_TIME", "MARKET_DESCRIPTION"))
runnerData <- data.frame()
winOdds <- listMarketBook(marketId = yourMarketId, priceData = "EX_BEST_OFFERS")
numRunners <- nrow(winOdds$runners[[1]])
for(j in 1:numRunners){
runnerData[j,"runnerName"] <- eventWins$runners[[1]][[j,"runnerName"]]
runnerData[j,"runnerNumber"] <- substr(runnerData[j,"runnerName"],1,str_locate(runnerData[j,"runnerName"]," ")[[1]]-2)
if(placeOdds$status == "OPEN"){
if(winOdds$runners[[1]]$status[[j]]=="ACTIVE"){
runnerData[j,"selectionId"] <- placeOdds$runners[[1]]$selectionId[[j]]
if(nrow(winOdds$runners[[1]]$ex[[1]][[j]])>0){
runnerData[j,"bestLay"] <- winOdds$runners[[1]]$ex[[1]][[j]][[1,"price"]]
runnerData[j,"layAmount"] <- winOdds$runners[[1]]$ex[[1]][[j]][[1,"size"]]
} else {
runnerData[j,"bestLay"] <- 1.01
runnerData[j,"layAmount"] <- 5
}
if(nrow(winOdds$runners[[1]]$ex[[2]][[j]])>0){
runnerData[j,"bestBack"] <- winOdds$runners[[1]]$ex[[2]][[j]][[1,"price"]]
runnerData[j,"backAmount"] <- winOdds$runners[[1]]$ex[[2]][[j]][[1,"size"]]
} else {
runnerData[j,"bestBack"] <- 1000
runnerData[j,"backAmount"] <- 1
}
if(nrow(placeOdds$runners[[1]]$ex[[1]][[j]])>0){
runnerData[j,"bestLayPlaceOdds"] <- placeOdds$runners[[1]]$ex[[1]][[j]][[1,"price"]]
} else {
runnerData[j,"bestLayPlaceOdds"] <- 1.01
}
if(nrow(placeOdds$runners[[1]]$ex[[2]][[j]])>0){
runnerData[j,"bestBackPlaceOdds"] <- placeOdds$runners[[1]]$ex[[2]][[j]][[1,"price"]]
} else {
runnerData[j,"bestBackPlaceOdds"] <- 1000
}
numActiveRunners <- numActiveRunners + 1
} else {
runnerData[j,"bestLay"] <- 0
runnerData[j,"layAmount"] <- 0
runnerData[j,"bestBack"] <- 0
runnerData[j,"backAmount"] <- 0
}
} else {
runnerData[j,"bestLay"] <- 0
runnerData[j,"layAmount"] <- 0
runnerData[j,"bestBack"] <- 0
runnerData[j,"backAmount"] <- 0
}
}
from abettor.
Related Issues (20)
- Additional Accounts API Calls HOT 4
- Regenerate Package Documentation HOT 1
- Support Spanish, Italian and Swedish end points HOT 1
- listRunnerBook Fails to Generate Documentation HOT 1
- placeOrders function does not include all fields HOT 10
- Rename checkBalance and listMarketPandL Functions HOT 2
- placeOrders not working correctly for some optional fields HOT 2
- getAccountStatement uses legacyData fields and code is messy HOT 1
- listCurrentOrders does not include all parameters HOT 1
- listClearedOrders is not correctly putting results into a dataframe and is instead providing one very long row. HOT 2
- Minor API change to listCurrentOrders - week commencing 9 August HOT 1
- Check valid login status HOT 5
- placeOrder function seems to not pass customerOrderRef on MARKET_ON_CLOSE bets HOT 1
- Minor issue when trying to cancel individual betIds. Simple code fix has been proposed. HOT 3
- getAccountStatement crash with dead heat HOT 4
- getAccountStatement not returning all columns
- listMarketBook function returning identical results HOT 8
- The placeOrders function doesn't pass the handicap field to the API HOT 1
- date range in getAccountStatement not working correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abettor.