This is more like what you asked for...

> eWrapper.data.Last <- function(n) {
+   eW <- eWrapper(NULL)  # use basic template
+   eW$assign.Data("data",
rep(list(structure(.xts(matrix(rep(NA_real_,1),nc=1),0),
+                                       .Dimnames=list(NULL,"Last"))),n))
+
+   eW$tickPrice <- function(curMsg, msg, timestamp, file, ...)
+   {
+     tickType = msg[3]
+     msg <- as.numeric(msg)
+     id <- msg[2] #as.numeric(msg[2])
+     data <- eW$get.Data("data") #[[1]]  # list position of symbol (by id
== msg[2])
+     attr(data[[id]],"index") <- as.numeric(Sys.time())
+     nr.data <- NROW(data[[id]])
+     if(tickType == .twsTickType$LAST) {
+       data[[id]][nr.data,1] <- msg[4]
+     }
+     eW$assign.Data("data", data)
+     c(curMsg, msg)
+   }
+   return(eW)
+ }
> reqMktData(tws, twsSTK("DIA"), eventWrapper=eWrapper.data.Last(1),
CALLBACK=snapShot)
    Last
DIA  113
> reqMktData(tws, twsSTK("DIA"), eventWrapper=eWrapper.data.Last(1),
CALLBACK=snapShot)
      Last
DIA 112.97
>

-Garrett

On Wed, Sep 21, 2011 at 1:28 PM, G See <gsee000@gmail.com> wrote:

> Sorry, I got the column names backwards, but you should be able to figure
> out how to fix that.
>
>
> On Wed, Sep 21, 2011 at 1:27 PM, G See <gsee000@gmail.com> wrote:
>
>> See attached file "eWrapper.data.Last.R"
>>
>> > source("eWrapper.data.Last.R")
>> > reqMktData(tws, twsSTK("SPY"),
>> eventWrapper=eWrapper.data.Last(1),CALLBACK=snapShot)
>> 2 -1 2104 Market data farm connection is OK:cusfuture
>> 2 -1 2104 Market data farm connection is OK:usfuture
>> 2 -1 2104 Market data farm connection is OK:eurofarm
>> 2 -1 2104 Market data farm connection is OK:usopt
>> 2 -1 2104 Market data farm connection is OK:usfarm
>> 2 -1 2106 HMDS data farm connection is OK:ushmds2a
>>     Last LastSize
>> SPY    1   119.18
>>
>> Here's a couple of other variations...
>>
>>
>> https://r-forge.r-project.org/scm/viewvc.php/pkg/twsInstrument/R/eWrapper.data.BID_ASK_OHLCV.R?view=markup&revision=101&root=twsinstrument
>>
>>
>> https://r-forge.r-project.org/scm/viewvc.php/pkg/twsInstrument/R/eWrapper.FXdata.R?view=markup&revision=90&root=twsinstrument
>>
>> -Garrett
>>
>>
>> On Wed, Sep 21, 2011 at 11:10 AM, Johnny Paulo <johnny.jp.22@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I am using IBrokers to get RT prices thanks to Jeff Ryan's package,
>>> IBrokers.
>>>
>>> In order to deal with stocks having potentially low liquidity, without
>>> being
>>> penalized by long turnaround time, I would like to focus on getting the
>>> last
>>> price only.
>>> Can someone pls give me some pointers to what I should change in the
>>> traditional code provided by Jeff (see below)?
>>>
>>> Thanks
>>>
>>> Johnny
>>>
>>> reqMktData(tws,
>>> twsEquity(u),eventWrapper=eWrapper.data(1),CALLBACK=snapShot)
>>>
>>> with
>>> snapShot <- function (twsCon, eWrapper, timestamp, file, playback = 1,
>>> ...)
>>> {
>>>    if (missing(eWrapper))
>>>        eWrapper <- eWrapper()
>>>    names(eWrapper$.Data$data) <- eWrapper$.Data$symbols
>>>    con <- twsCon[[1]]
>>>    if (inherits(twsCon, "twsPlayback")) {
>>>        sys.time <- NULL
>>>        while (TRUE) {
>>>            if (!is.null(timestamp)) {
>>>                last.time <- sys.time
>>>                sys.time <- as.POSIXct(strptime(paste(readBin(con,
>>>                  character(), 2), collapse = " "), timestamp))
>>>                if (!is.null(last.time)) {
>>>                  Sys.sleep((sys.time - last.time) * playback)
>>>                }
>>>                curMsg <- .Internal(readBin(con, "character",
>>>                  1L, NA_integer_, TRUE, FALSE))
>>>                if (length(curMsg) < 1)
>>>                  next
>>>                processMsg(curMsg, con, eWrapper, format(sys.time,
>>>                  timestamp), file, ...)
>>>            }
>>>            else {
>>>                curMsg <- readBin(con, character(), 1)
>>>                if (length(curMsg) < 1)
>>>                  next
>>>                processMsg(curMsg, con, eWrapper, timestamp,
>>>                  file, ...)
>>>                if (curMsg == .twsIncomingMSG$REAL_TIME_BARS)
>>>                  Sys.sleep(5 * playback)
>>>            }
>>>        }
>>>    }
>>>    else {
>>>        while (TRUE) {
>>>            socketSelect(list(con), FALSE, NULL)
>>>            curMsg <- .Internal(readBin(con, "character", 1L,
>>>                NA_integer_, TRUE, FALSE))
>>>            if (!is.null(timestamp)) {
>>>                processMsg(curMsg, con, eWrapper, format(Sys.time(),
>>>                  timestamp), file, ...)
>>>            }
>>>            else {
>>>                processMsg(curMsg, con, eWrapper, timestamp,
>>>                  file, ...)
>>>            }
>>>            if (!any(sapply(eWrapper$.Data$data, is.na)))
>>>                return(do.call(rbind, lapply(eWrapper$.Data$data,
>>>                  as.data.frame)))
>>>        }
>>>    }
>>> }
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-SIG-Finance@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>> -- Also note that this is not the r-help list where general R questions
>>> should go.
>>>
>>
>>
>

	[[alternative HTML version deleted]]

