4

我尝试使用函数 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。

4

1 回答 1

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
于 2012-03-26T14:00:10.900 回答