Hi Stephen,

I think you are missing some code. I don't know this example but based on
what I see here I would say that adding something like this could make it
work:

con = twsConnect(1)
reqMktData(twsSTK("AAPL"))
....

Give it a try.

Regards,

-Mark-

2010/12/2 Stephen Choularton <stephen@organicfoodmarkets.com.au>

> I'm trying to work through Jeff's example for a new callback from his
> presentation Real Time Trading in R at R/Rmetrics 2009:
>
> twsOC <- twsConnect(2) # our order connection
> ocWrapper <- eWrapper(TRUE)
> traded <- FALSE
> while (TRUE) {
>    cons <- socketSelect(list(con, twsOC[[1]]), FALSE, 0.01)
>    if(cons[1]) { #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, ...)
>        }
>    } else if(cons[2]) {
>        curMsg <- readBin(twsOC[[1]], character(), 1)
>        if (!is.null(timestamp)) {
>            processMsg(curMsg, twsOC[[1]], ocWrapper, format(Sys.time(),
> timestamp), file, ...)
>        } else {
>            processMsg(curMsg, twsOC[[1]], ocWrapper, timestamp, file, ...)
>        }
>    } #TRADE LOGIC HERE
>    curBID <- as.numeric(eWrapper$.Data$data[[1]][3])
>    if(!traded && !is.na(curBID) && curBID > 141.00) {
>        c("this is the order line")
>        # IBrokers:::.placeOrder(twsOC, twsSTK("AAPL"), twsOrder(1053,
> "BUY", "10", "MKT"))
>        traded <- TRUE
>    }
> }
>
> First, I think that there was a missing } at the end of the loop on the
> slide, so I added one.  However, when I run it I get:
>
> Error in socketSelect(list(con, twsOC[[1]]), FALSE, 0.01) :
>  object 'con' not found
>
>
> I know I have a connection:
>
> twsOC
> <twsConnection,2 @ 20101203 06:16:05 Eastern Standard Time (New South
> Wales), nextId=-1>
> >
>
>
>  Can anyone advise me what's wrong?
>
>  Incidentally, I don't see how this code gets info on AAPL.  The first time
> its mentioned is down in the TRADE LOGIC HERE section.  Can anyone clarify?
>
>
>
> --
> Stephen Choularton Ph.D., FIoD
>
> _______________________________________________
> 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]]

