[R-SIG-Finance] IBroker: Attempt to call placeOrder() gives socket i/o error?
Joshua Ulrich
josh.m.ulrich at gmail.com
Thu Oct 30 22:38:38 CET 2014
Hi Dan,
For future reference, please don't cross post (here and SO:
http://stackoverflow.com/q/26644845/271616). If you do cross-post,
please at least say you did, so people don't spend time answering a
question that was already answered in another forum.
Best,
Josh
On Thu, Oct 30, 2014 at 9:12 AM, spy sixoneone <ispy611 at yahoo.com> wrote:
> 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
>
> _______________________________________________
> R-SIG-Finance at 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.
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
More information about the R-SIG-Finance
mailing list