[R-SIG-Finance] IBroker: Attempt to call placeOrder() gives socket i/o error?

spy sixoneone ispy611 at yahoo.com
Thu Oct 30 15:12:59 CET 2014


I debugged it.

This works okay for me:

# myscript.r

.libPaths("rpackages")
library(IBrokers)
tws2 = twsConnect(2)
mytkr     = twsFuture("ES","GLOBEX","201412")
Sys.sleep(2)
myorderid = as.integer(reqIds(tws2))
print(myorderid)
Sys.sleep(2)
myorderid = as.integer(difftime(Sys.time(), "2014-10-30", units = "secs"))

IBrokers:::.placeOrder(tws2, mytkr, twsOrder(myorderid,"SELL", "1", "MKT"))
Sys.sleep(2)
twsDisconnect(tws2)

Dan
--------------------------------------------


 Subject: IBroker: Attempt to call placeOrder() gives socket i/o error?
 To: r-sig-finance at r-project.org
 Date: Thursday, October 30, 2014, 7:27 AM

 Hello IBworld.

 I am having trouble entering orders via the API.

 Sometimes it works but usually it fails.

 So far I've tried 2 types of connection api-wrappers:

 R IBrokers package
 python ibpy package

 I can use R IBrokers package to call reqHistoricalData().
 That seems to work well on my laptop.
 In fact I've been doing that for months from cron.

 So, I have tws setup okay and I know how to debug a variety
 of problems now.

 I first tried entering an order using a script like this in
 R:

 .libPaths("rpackages")
 library(IBrokers)
 tws2 = twsConnect(2)
 print('Attempting BUY')
 mytkr     =
 twsFuture("ES","GLOBEX","201412")
 myorderid = sample(1001:3001, 1)
 IBrokers:::.placeOrder(tws2, mytkr, twsOrder(myorderid,
 "BUY", "1", "MKT"))
 twsDisconnect(tws2)

 Sometimes it works but usually it fails.

 When it fails I see this in my tws console:

 06:01:21:676 JTS-EServerSocket-160: [2:47:71:1:0:0:0:ERR]
 Message type -1.  Socket I/O error - 
 06:01:21:676 JTS-EServerSocket-160: Anticipated error
 jextend.d: Socket I/O error - 
     at jextend.sc.b(sc.java:364)
     at jextend.ch.sb(ch.java:1534)
     at jextend.ch.run(ch.java:1390)
     at java.lang.Thread.run(Thread.java:745)
 Caused by: java.net.SocketException: Connection reset
     at
 java.net.SocketInputStream.read(SocketInputStream.java:196)
     at
 java.net.SocketInputStream.read(SocketInputStream.java:122)
     at
 java.net.SocketInputStream.read(SocketInputStream.java:210)
     at jextend.xh.d(xh.java:45)
     at jextend.sc.c(sc.java:579)
     at jextend.sc.r(sc.java:227)
     at jextend.af.a(af.java:232)
     at jextend.sc.f(sc.java:650)
     at jextend.pd.a(pd.java:822)
     at jextend.sc.b(sc.java:358)
     ... 3 more
 06:01:21:678 JTS-EServerSocket-160: [2:47:71:1:0:0:0:ERR]
 Socket connection for client{2} has closed. 
 06:01:21:678 JTS-EWriter5-161: [2:47:71:1:0:0:0:ERR] Unable
 write to socket client{2} - 
 06:01:21:678 JTS-EServerSocketNotifier-158: Terminating

 At first I thought the problem might be R.

 But I get a similar error if I try to enter an order using
 python ibpy.

 Also I tried making a call to reqAccountUpdates(tws) and
 that works well always.

 I've done a bit of searching on google and SOF and have
 found no clues yet.

 Please shout-out if you have any ideas on how to debug
 this.

 Thanks,

 Dan



More information about the R-SIG-Finance mailing list