Rcode Sample, Try Catch

##
##read shorts info for TD
#http://regsho.finra.org/FNSQshvol20181212.txt
#http://regsho.finra.org/FNYXshvol20181212.txt
#http://regsho.finra.org/FORFshvol20181212.txt
library(RODBC)
dbconn<-odbcDriverConnect(“driver={SQL Server};server=localhost\\AMT2016;database=Test;trusted_connection=true”)

read_shorts <- function(conn, dtstring){

###Third page
url = paste(“http://regsho.finra.org/FORFshvol”, dtstring, “.txt”, sep = “”)
print(paste(“now reading”, url))

dtZ = read.csv(url, header = TRUE, sep = “|”)
dt2 <- head(dtZ, -1)
sqlSave(dbconn, dt2, “TShort5”, rownames =NULL, append= TRUE )

##print(paste(toString(Sys.time), “finished reading for date “,dtstring))
}

dtstring = “20180724”
try(read_shorts(dbconn, dtstring))
print(“non-stop”)
close(dbconn)

Leave a Reply

Your email address will not be published. Required fields are marked *