IBrokers - 我如何向IBrokers发送100000 :::。placeOrder?

时间:2014-12-22 01:46:27

标签: java r ibrokers

我正在使用IBrokers在IDEALPRO上打开AUD-USD的订单

这里的语法对我来说很适合卖出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)

接下来,我尝试通过此API调用下订单100,000:

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

订单失败。

我在日志中看到了这一点:

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

一个简单的解决方法是为50000下2个订单。

我正在寻找其他解决方法的线索。

我怀疑这个错误是IBrokers正在向API发送1e + 05而不是100000。

1 个答案:

答案 0 :(得分: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)