Skip to content

Instantly share code, notes, and snippets.

@yanping
Created December 6, 2012 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanping/4224218 to your computer and use it in GitHub Desktop.
Save yanping/4224218 to your computer and use it in GitHub Desktop.
读取郑州商品交易所数据
# 读取郑州商品交易所数据
# 接口举例
# (1) http://www.czce.com.cn/portal/exchange/2012/datadaily/20121205.htm
# (2) http://www.czce.com.cn/portal/exchange/2012/datadaily/20121205.txt
zceDatabase <- NULL
for(date in c("20121202","20121206")){
str <- "http://www.czce.com.cn/portal/exchange/2012/datadaily/"
url <- paste(str,date,".txt",sep="")
if(!url.exists(url)){
next
}else{
colnames <- c("品种月份","昨结算","今开盘","最高价","最低价","今收盘","今结算","涨跌1","涨跌2","成交量","空盘量","增减量","成交额","交割结算价")
fileName <- paste("zce",date,".txt",sep="")
download.file(url,fileName,quiet=T)
zceData <- read.table(fileName, header = F,skip = 1,sep = ",", col.names = colnames)
zceData <- zceData[(zceData[,1]!="小计")&(zceData[,1]!="总计"),]
zceData$date <- date
if(is.null(zceDatabase)){
zceDatabase <- zceData
}else{
zceDatabase <- rbind(zceDatabase,zceData)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment