3

I'm using IBrokers to open orders for AUD-USD on IDEALPRO

Here is syntax which works well for me to SELL 90,000:

# myscript.r

.libPaths("rpackages")
library(IBrokers)
myconid = 3
twsobj  = twsConnect(myconid)
myaud = twsCurrency("AUD",currency="USD",exch="IDEALPRO",primary="",strike="0.0",right="",local="",multiplier="",include_expired="0",conId=myconid)
Sys.sleep(2)
myorderid = as.integer(reqIds(twsobj))
print(myorderid)
Sys.sleep(2)
myorderid = as.integer(difftime(Sys.time(), "2014-10-30", units = "secs"))
Sys.sleep(2)
IBrokers:::.placeOrder(twsobj, myaud, twsOrder(myorderid,"SELL", 90000, "MKT"))
Sys.sleep(4)
twsDisconnect(twsobj)

Next, I try to place an order for 100,000 with this API call:

IBrokers:::.placeOrder(twsobj, myaud, twsOrder(myorderid,"SELL", 100000, "MKT"))

The order fails.

I see this in my log:

java.lang.NumberFormatException: For input string: "1e+05"

A simple workaround is to place 2 orders for 50000.

I'm looking for clues on other workarounds.

I suspect that the bug is that IBrokers is sending 1e+05 to the API instead of 100000.

user3676943
  • 913
  • 1
  • 13
  • 27
  • I just found the answer via google 'disable scientific notation in R'. The answer is, I insert this line of syntax before I make the call `options("scipen"=4)` I will answer correctly once SO allows me. – user3676943 Dec 22 '14 at 02:06
  • Try passing a string instead of a number. i.e. `"100000"` instead of `100000` – GSee Dec 22 '14 at 02:34

1 Answers1

1
# myscript.r

.libPaths("rpackages")
library(IBrokers)
myconid = 3
twsobj  = twsConnect(myconid)
myaud = twsCurrency("AUD",currency="USD",exch="IDEALPRO",primary="",strike="0.0",right="",local="",multiplier="",include_expired="0",conId=myconid)
Sys.sleep(2)
myorderid = as.integer(reqIds(twsobj))
print(myorderid)
Sys.sleep(2)
myorderid = as.integer(difftime(Sys.time(), "2014-10-30", units = "secs"))
Sys.sleep(2)

# my workaround:
options("scipen"=4)

IBrokers:::.placeOrder(twsobj, myaud, twsOrder(myorderid,"SELL", 190000, "MKT"))
Sys.sleep(4)
twsDisconnect(twsobj)
user3676943
  • 913
  • 1
  • 13
  • 27