[R-SIG-Finance] IBrokers
Stephen Choularton
stephen at organicfoodmarkets.com.au
Mon Dec 6 20:46:30 CET 2010
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
More information about the R-SIG-Finance
mailing list