0

Using the Ibrokers account I know how to place a trade with one ticker which , in the example below I place a trade with "DAL"

library(IBrokers)
tws=twsConnect(clientId = 1,host = "localhost", port = 7497 )
contract=twsEquity(symbol = "DAL", exch = "SMART" )
order=twsOrder(action = "BUY", totalQuantity ="10", tif = "OPG" )
placeOrder(twsconn = tws, Contract = contract, Order = order)

However I am interested in trading multiple tickers at once for example how can I place an order to buy "DAL" and "AAL". How can I put multiple orders into IBrokers in R?

pelumi obasa
  • 127
  • 5
  • Hey guys I Could really use some help here is there any way I can clarify the question over here . – pelumi obasa Jun 28 '20 at 19:07
  • Have you tried just running the last 3 lines again(with new values)? You may want to switch to a newer API. The R package is no longer updated. – brian Jun 28 '20 at 19:29
  • @Brian thank you for responding I know how to place an order for one stock using Brokers package the example I gave here was the DAL ticker however I would like to know how to trade multiple tickers at once – pelumi obasa Jun 28 '20 at 20:15

1 Answers1

0

I doubt your code even works now. To place another order just place another order. Note that they must have separate ids and the ids have to increase every order.

library(IBrokers)
tws=twsConnect(clientId = 1,host = "localhost", port = 7497 )

id <- tws.reqids(1)

contract=twsEquity(symbol = "AAL", exch = "SMART" )
# give an order id
order=twsOrder(id, action = "BUY", totalQuantity ="10", tif = "OPG" )
placeOrder(twsconn = tws, Contract = contract, Order = order)

# increment id
id <- id+1
contract=twsEquity(symbol = "DAL", exch = "SMART" )
order=twsOrder(id,action = "BUY", totalQuantity ="10", tif = "OPG" )
placeOrder(twsconn = tws, Contract = contract, Order = order)

I don't think that code will work. The defaults for order look to be LMT with a price of 0. You may want to try orderType = "MKT". Check the documentation for IBrokers.

I would suggest using a different API, it doesn't look like you have used the R package much so it's not a big deal to switch. It probably won't work for much longer. I think it is unsupported and the API has changed since the last update.

brian
  • 10,619
  • 4
  • 21
  • 79