在括号中使用IBroker的多个数量

在括号中使用IBroker的多个数量,r,trading,ibrokers,R,Trading,Ibrokers,我正在与ibrokers合作,试图为一笔交易设定多个收盘价。例如,以106美元买入100股AAPL,以107美元卖出50股,以108美元卖出50股,止损价为105美元 当我发送多份获利回吐订单时,似乎忽略了50股的数量,相反,我收到了两份100股的卖出订单 这是我正在运行的代码 tws <- twsConnect() stock <- twsEquity("AAPL") parentLongId <- reqIds(tws) parentLongOrder <- t

我正在与ibrokers合作,试图为一笔交易设定多个收盘价。例如,以106美元买入100股AAPL,以107美元卖出50股,以108美元卖出50股,止损价为105美元

当我发送多份获利回吐订单时,似乎忽略了50股的数量,相反,我收到了两份100股的卖出订单

这是我正在运行的代码

tws <- twsConnect() 

stock <- twsEquity("AAPL")
parentLongId <- reqIds(tws)

parentLongOrder <- twsOrder(parentLongId, action="BUY", totalQuantity = 100, 
                            orderType = "LMT", lmtPrice = 106, 
                            transmit=TRUE)
placeOrder(tws, stock, parentLongOrder)


childLongProfitId <- reqIds(tws)
childLongProfitOrder <- twsOrder(childLongProfitId, action="SELL", totalQuantity = 50, 
                                 orderType = "LMT", lmtPrice = 107,
                                 transmit=TRUE, parentId = parentLongId)
placeOrder(tws, stock, childLongProfitOrder)

childLongProfitId2 <- reqIds(tws)
childLongProfitOrder2 <- twsOrder(childLongProfitId2, action="SELL", totalQuantity = 50, 
                                  orderType = "LMT", lmtPrice = 108,
                                  transmit=TRUE, parentId = parentLongId)
placeOrder(tws, stock, childLongProfitOrder2)

childLongStopId <- reqIds(tws)
childLongStopOrder <- twsOrder(childLongStopId, action="SELL", totalQuantity = 100, 
                               orderType = "STP", auxPrice = 105,
                               transmit=TRUE, parentId = parentLongId, account=accountNum)
placeOrder(tws, stock, childLongStopOrder)

twsDisconnect(tws) 

tws建议先下100份订单,然后再下50份订单。这意味着你要进行一次交易。API有时功能异常。。。尤其是开源的。在这里使用Java API的详细设置可能会更好

我建议使用2个括号订单,或者只使用一个带有2批OCA收盘订单的订单。基本上是以一半的金额下两个档次的订单,但利润额不同。嗨,布莱恩。创建两套订单会起作用,但如果我想移动止损点,可能会产生问题。我需要移动两次。我并不总是希望命令被“设定并忘记”,我只是看到了这一点。如果你能把赏金延长6个小时左右,我可以帮你解决这个问题。谢谢。嗨,马特,很遗憾,先下停止令是行不通的。我对java不是很熟悉,尽管我知道它的支持要好得多。另一种选择是使用Excel DDE。对于像这样简单的事情,它很可能会奏效。挑战在于,一旦事情变得更复杂,我可能就不走运了。
tws <- twsConnect() #open connection, R automatically pauses until manually accepted on IB.

stock <- twsEquity("AAPL")
parentLongId <- reqIds(tws)

parentLongOrder <- twsOrder(parentLongId, action="BUY", totalQuantity = 100, 
                            orderType = "LMT", lmtPrice = 106, 
                            transmit=TRUE)
placeOrder(tws, stock, parentLongOrder)


childLongProfitId <- reqIds(tws)
childLongProfitOrder <- twsOrder(childLongProfitId, action="SELL", totalQuantity = 50, 
                                 orderType = "LMT", lmtPrice = 107,
                                 transmit=TRUE)
placeOrder(tws, stock, childLongProfitOrder)

childLongProfitId2 <- reqIds(tws)
childLongProfitOrder2 <- twsOrder(childLongProfitId2, action="SELL", totalQuantity = 50, 
                                  orderType = "LMT", lmtPrice = 108,
                                  transmit=TRUE)
placeOrder(tws, stock, childLongProfitOrder2)

childLongStopId <- reqIds(tws)
childLongStopOrder <- twsOrder(childLongStopId, action="SELL", totalQuantity = 100, 
                               orderType = "STP", auxPrice = 105,
                               transmit=TRUE, parentId = parentLongId, account=accountNum)
placeOrder(tws, stock, childLongStopOrder)

twsDisconnect(tws)