[R-SIG-Finance] Question for IB TWS users

mel mel at altk.com
Fri May 4 19:00:50 CEST 2007


Hello,

I tried to wrote a little function establishing a socketConnection
to IB TWS. (aping c code from TWS API)
I'm newbie with R connection functions ... and it does not go very far.
I tried many combinations ... but not the good ones !
If a TWS user here has already done something like that,
could you please push me a bit in the right direction.
Thanks
Vincent (on windowsXP, R 2.4.1 (yes I'll upgrade)).

#==============================================
# TWS has to be running

connectToTWS = function()
{
TWS_PORT_NUMBER = 7496;
CLIENT_VERSION  = '30';
HOST            = '127.0.0.1';

con  = socketConnection(HOST, port=TWS_PORT_NUMBER, server=FALSE,
       blocking = TRUE, open = "w+", encoding = getOption("encoding"));

print(isOpen(con));     # TRUE : seems to work up to here

#write(CLIENT_VERSION, con, sep='');
#writeLines(CLIENT_VERSION, con, sep='')
cat(CLIENT_VERSION, file=con, sep='');

res = readLines(con, 1);    # would like to get something here !
print(res);                 # but always character(0)

close(con);
return(TRUE);
}



More information about the R-SIG-Finance mailing list