4

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
SilverSpoon
  • 655
  • 4
  • 8
  • 17
  • Your command doesn't work for me. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Roman Luštrik Mar 26 '12 at 07:42
  • what is the error you are getting? do you have trades executed by function placeOrder? – SilverSpoon Mar 26 '12 at 08:38
  • library(IBrokers) con <- twsConnect(clientId=1) id <- reqIds(con) Order <- twsOrder(orderId=id, action="BUY", totalQuantity = 1, orderType="LMT", lmtPrice = 500, tif="GTC") placeOrder(twsCon, twsSTK("AAPL", Order) – SilverSpoon Mar 26 '12 at 08:40

1 Answers1

4

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
GSee
  • 48,880
  • 13
  • 125
  • 145