DSWS R API - run into some problems using R code to get data for 300 companies listed under ASX300

Hi There,

We put together a rough sketch of the code that could be used to access prices and market capitalisation of the 300 companies each day. I run into some problems using this code for all 300 companies, but could you please see if it works in this environment?

#  Retrieve tickers  ------------------------------------------------------
function_ds <- function(x) {use_dsws$listRequest(instrument = x, 
                                                  datatype = c("NAME", 
                                                               "MNEM"),
                                                  requestDate = "0D") %>% 
                                mutate(mmyy = x)
}
tickers_300 <- function_ds("LASX300I")
# Retrieve price data for tickers -----------------------------------------
ts_req <- function(x) {use_dsws$timeSeriesListRequest(instrument = x,
                                                      datatype = c("P", "MV"),
                                                      startDate = "-0D",
                                                      endDate = "-0D",
                                                      frequency = "D")}
# the following line works properly - get price data for first 20 tickers but I cannot get price data for 30 tickers
# following results in error: Error requesting data.  HTTP message was: Server error : Internal Server Error : Server error: (500) Internal Server Error

Can you recommend us on how to do this for larger quantity?

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @patelj

    I got the same error.

    To solve the problem, you need to reduce the chunkLimit. For example:

    use_dsws$chunkLimit <- 20L

    Then, use one datatype in the request.

    ts_req <- function(x) {use_dsws$timeSeriesListRequest(instrument = x,
                                                          datatype = "P",
                                                          startDate = "-0D",
                                                          endDate = "-0D",
                                                          frequency = "D")}

    If you use more than one datatype, you will get this error "subscription out of bound". This issue has been fixed in 1.7.10 available on GitHub, as mentioned on this thread.


    install_github("CharlesCara/DatastreamDSWS2R")require(devtools) 

    In conclusion, you need to upgrade the package to 1.7.10, and set the chunkLimit.