Skip to content
Prev 4719 / 15274 Next

IBrokers- how to keep target file from being re-written?

For now, using reqHistoricalData() vs. the new wrapper reqHistory(),
setting endDateTime array and then looping thru writing to same file.
Func overwrites and attempt to add 'a'ppend qualifiers doesn't work.

dfile='/home/foo/'

now<- Sys.Date()-1

tp<- seq(now, length=6, by=paste(-5, 'days'))

# reformat dates to conform with IB needs YYYYMMDD

now2<- as.Date(tp, format="%Y%m%d")

reqHistoricalData(tws,
		    contract,
		    endDateTime=now2,
		    barSize = "5 mins",
		    duration = "5 D",
		    useRTH = "0",
		    whatToShow = "TRADES",
		    time.format = "1",
		    verbose = TRUE,
		    tickerId = "1",
		    #eventHistoricalData,
                    # this line fails
                    #file=paste(dfile,'EStest.dat',sep=''),open='a')
		    file=paste(dfile,'EStest.dat',sep=''))

* Would prefer to work from one file but could write out to numerous
and then merge.

Snippet from reqHistoricalData() suggests write.table would need to be
extended with 'append=TRUE' but sure there is something more
obvious...

#
if (!missing(file)) {
            cm[, 1] <- dts
            write.table(cm, file = file, quote = FALSE, row.names = FALSE,
                col.names = FALSE, sep = ",")
            invisible(return())
#


TIA, Vince