3

我正在使用 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"

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

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

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

4

1 回答 1

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)
于 2014-12-23T08:40:55.937 回答