我试图通过使用函数reqExecutions来查询来自IB的交易:
library(IBrokers)
con <- twsConnect(clientId=1)
id <- reqIds(con)
Order <- twsOrder(orderId=id, action="BUY", totalQuantity = 1, orderType="LMT", lmtPrice = 600, tif="GTC")
placeOrder(con, twsSTK("AAPL", Order)
print(reqExecutions(con, reqId = as.character(.Last.orderId), ExecutionFilter = twsExecutionFilter(clientId="1")))
虽然交易在IB中执行,但它总是返回NULL。
答案 0 :(得分:4)
你不能只使用reqOpenOrders吗?
警告:以下内容将执行交易。在运行此代码之前,请确保您已连接到纸质交易帐户!
library(IBrokers)
#con <- twsConnect(clientId=1)
con <- ibgConnect(clientId=1)
id <- reqIds(con)
Order <- twsOrder(orderId=id, action="BUY", totalQuantity = 1, orderType="LMT",
lmtPrice = 600, tif="GTC")
placeOrder(con, twsSTK("AAPL"), Order)
> reqOpenOrders(twsconn=con)
TWS Message: 2 -1 2100 New account data requested. API client has been unsubscribed from account data.
TWS Execution: orderId=1 time=2012-03-26 08:47:29 side=BOT shares=1 symbol=AAPL conId=265598 price=597.91