I think I got it. The functionality needs to be implemented into a few files of the IBrokers package. In processMsg.R
we need to add the following to the part if(curMsg == .twsIncomingMSG$OPEN_ORDER)
:
if(curMsg == .twsIncomingMSG$OPEN_ORDER) {
msg <- readBin(con, "character", 84)
x = eWrapper$openOrder(curMsg, msg, timestamp, file, ...)
return(x)
Next, implement the function openOrder
in eWrapper.R
as follows:
openOrder <- function(curMsg, msg, timestamp, file, ...) {
x = e_open_order(msg)
return(x)
}
Then in eventHandlers.R
, alter the e_open_order
as follows:
`e_open_order` <- function(msg) {
contents = msg
...
return(eoo)
}
This event handler nicely bootstraps the data from the TWS returning message into the appropriate structures, twsContract, twsOrder and twsOrderState. Then, I created the following function:
gs_GetOpenOrders = function(twscon){
# Check if connected to TWS
if(!is.twsConnection(twscon))
stop('requires twsConnection object')
else
con = twscon[[1]]
# Send message requesting open orders
ver = "1"
writeBin(c(.twsOutgoingMSG$REQ_OPEN_ORDERS,ver),con)
# Receive message with content of open orders
ewr = eWrapper()
socketSelect(list(con),FALSE,NULL)
msg = list()
k = 0
while(TRUE) {
curmsg = readBin(con, character(), 1)
if(length(curmsg)==0)
break
if (curmsg==.twsIncomingMSG$OPEN_ORDER){
k = k+1
msg[[k]] = processMsg(curmsg,con,ewr)
}
else
processMsg(curmsg,con,ewr)
}
return(msg)
}
The result is the list variable msg
. Each element of the list in turn is a list containing the open orders data into the structures twsContract, twsOrder and twsOrderState. From there one can simply get, display and use the data in any way desired. It looks like the same is true for pretty much all the other functionality in IBrokers, it's just that some of it is already implemented.