Search code examples
javaribrokers

IBrokers - How I send 100000 to IBrokers:::.placeOrder?


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.


Solution

  • # 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)