[R-SIG-Finance] IBrokers: reqMktData, but for LastPrice only
G See
gsee000 at gmail.com
Wed Sep 21 20:27:16 CEST 2011
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 at 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 at 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110921/dbba9c25/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eWrapper.data.Last.R
Type: text/x-r-source
Size: 3176 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110921/dbba9c25/attachment.bin>
More information about the R-SIG-Finance
mailing list