[R-SIG-Finance] IBrokers- how to keep target file from being re-written?

Jeff Ryan jeff.a.ryan at gmail.com
Tue Aug 11 19:07:02 CEST 2009


Hi Vince,

I should probably let a ... arg pass to write.table, but I'll have to
check that doesn't cause issues.

If you pass in an *open* file handle, you will likely get the output you want.

something like:

fh <- file("EStest.dat", open="a")
reqHistoricalData(tws, twsSTK("AAPL"), file=fh)


Alternatively, with reqHistory you can just let the function merge in
memory, and then use write.zoo to save to a csv file.

write.zoo(reqHistory(tws, twsSTK("AAPL")), file="AAPL.csv")
system("head AAPL.csv")
system("wc -l AAPL.csv")

HTH
Jeff

On Tue, Aug 11, 2009 at 11:25 AM, Vince Fulco<vfulco1 at gmail.com> wrote:
> 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
>
>
> --
> Vince Fulco, CFA, CAIA
> 612.424.5477 (universal)
> vfulco1 at gmail.com
>
>  A posse ad esse non valet consequentia
>
> “the possibility does not necessarily lead to materialization”
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list