R/getwsi.R

#
#   extraTechInds: extra Technical Indicators of TTR and quantmod
#
#   Copyright (C) 2016  Chen Chaozong
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

#' Retrieve Wind inter-day data
#'
#' @aliases getwsi
#' @param windcodes wind codes in w.wsi
#' @param windfields fields in w.wsi
#' @param starttime starttime in w.wsi
#' @param endtime endtime in w.wsi
#' @param options options in w.wsi, use w.menu to get more help
#' @param index.class index class of xts
#' @export

getwsi <- function(windcodes,windfields,starttime, endtime = Sys.time(), options = "",index.class=c("POSIXct","POSIXt"),timezone=Sys.timezone()){
  if(checkwindr()!=0) return(NULL)
  tmpdata <- w.wsi(windcodes,windfields,starttime,endtime,options)
  if(!tmpdata$ErrorCode==0) {
    message(paste("Can not get wind data, error code:",tmpdata$ErrorCode))
    return(NULL)
  }
  out <- xts(tmpdata$Data[,-1],tmpdata$Data[,1],src='wind',updated=Sys.time())
  names(out) <- tolower(names(tmpdata$Data)[-1])
  if(is.xts(out)) {
    indexClass(out) <- index.class
    indexTZ(out) <- timezone
  }
  return(out)
}
Chen-Chaozong/getwinddata documentation built on May 6, 2019, 10:10 a.m.