Reputation: 665
Im trying to query trades from IB by using function reqExecutions:
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")))
although trades are executed in IB, it always returns NULL.
Upvotes: 4
Views: 1639
Reputation: 49820
Can't you just use reqOpenOrders?
Warning: The following will execute a trade. Make sure you are connected to a paper trading account before running this code!
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
Upvotes: 4