0

使用 Ibrokers 账户,我知道如何使用一个代码进行交易,在下面的示例中,我使用“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)

但是我对一次交易多个代码很感兴趣,例如如何下订单购买“DAL”和“AAL”。如何在 R 中将多个订单放入 IBrokers?

4

1 回答 1

0

我怀疑您的代码现在甚至可以正常工作。要下另一个订单,只需下一个订单。请注意,它们必须具有单独的 id,并且 id 必须增加每个订单。

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)

我认为该代码行不通。订单的默认LMT 价格为 0。您可能想尝试一下orderType = "MKT"。查看 IBrokers 的文档。

我建议使用不同的 API,看起来您使用 R 包的次数不多,因此切换起来没什么大不了的。它可能不会工作更长的时间。我认为它不受支持,并且自上次更新以来 API 已更改。

于 2020-06-28T23:01:38.107 回答