[R-SIG-Finance] IBrokers

Jeff Ryan jeff.a.ryan at gmail.com
Mon Dec 6 21:35:33 CET 2010


The data object is an xts object, but only if you are using the
appropriate eWrapper that contains it.

reqMktData(con, twsEquity("GOOG"), event=eWrapper.data(1), CALLBACK=myCALLBACK)

And you'll need to change the appropriate line to this:

curBID <- as.numeric(eWrapper$.Data$data[[1]][,3])

(Note the [,3] instead of [3] .. we want the 3rd column)

[1] "inside the trading logic "
[1] "the cur bid is " "578.98"          "end"
[1] "inside the trading logic "
[1] "the cur bid is " "578.98"          "end"

HTH
Jeff

On Mon, Dec 6, 2010 at 1:46 PM, Stephen Choularton
<stephen at organicfoodmarkets.com.au> wrote:
> Well I was wrong. I have simplified the code:
>
> myCALLBACK <-
> function(twsCon, eWrapper, timestamp, file, playback = 1, ...) {
>
>    con <- twsCon[[1]]
>    traded <- FALSE
>    while (TRUE) {
>        socketSelect(list(con), FALSE, NULL)
>        #data
>    curMsg <- readBin(con, character(), 1)
>    if (!is.null(timestamp)) {
>        processMsg(curMsg, con, eWrapper, format(Sys.time(), timestamp),
> file, ...)
>    } else {
>        processMsg(curMsg, con, eWrapper, timestamp, file, ...)
>    }
>
>    # TRADE LOGIC HERE
>    curBID <- as.numeric(eWrapper$.Data$data[[1]][3])
>    print(c("the cur bid is ", curBID, "end"))
>    if(!traded  ) { # add back on open: && !is.na(curBID) && curBID > 141.00
>
>        print(c("inside the trading logic "))
>        # IBrokers:::.placeOrder(twsCon, twsEquity("CBA","ASX","AUD"),
> twsOrder(1053, "BUY", "0", "MKT"))
>        # traded <- TRUE
>    }
>    }
> }
>
>
>
> con = twsConnect()
>
> # contracts <-  list(twsSTK("MSFT"),twsSTK("AAPL")))
>
>
> reqMktData(con, twsEquity("GOOG"), CALLBACK=myCALLBACK)
>
> # reqMktData(con, twsEquity("CBA","ASX","AUD"), CALLBACK=myCALLBACK)
>
> closeAllConnections()
>
> but when I run it 'curBID <- as.numeric(eWrapper$.Data$data[[1]][3])' does
> not get me the current bid even though the callback is seeing it as this
> line from the output shows:
>
> <20101207 06:40:35.844000> id=1 symbol=GOOG bidPrice: 579.31  bidSize: 3
>
> Does any one know how to reference the data?   I have tried all sorts of
>  combinations of indices, etc but I'm not going to find it by chance and I
> cannot find anything in the lit.
>
>
> --
> Stephen Choularton Ph.D., FIoD
>
> _______________________________________________
> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at lemnica.com

www.lemnica.com



More information about the R-SIG-Finance mailing list