Rのibrokersパッケージを使用しており、取引の複数の終値を設定しようとしています。たとえば、100株のAAPLを106ドルで購入し、50ドルを107ドルで、50ドルを108ドルで、105ドルのストップ価格で販売します。ブラケット注文の複数の数量RでのIBrokersの使用
複数の利益を受け取る注文を送信すると、50個の数量が無視されるように見える代わりに、それぞれ100個の株式に対して2つの売り注文が得られます。
これは、私はあなたが量がすべて3桁のための100の代わりに、購入のための100と売り注文のそれぞれについて、50であることがわかります
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 <- 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)
それは私が利益をしたいとヒットたら他人をキャンセルする受注を停止するので、これは実際には動作しませんけど。
ありがとうございます。
2つのブラケット注文、または2つのバッチのOCA決済注文を提案します。基本的に金額の半分を金額の異なる2つの金額で注文しますが、金額は異なります。 – brian
こんにちはブライアン。 2セットのオーダーを作成することはできますが、ストップも移動したい場合は問題が発生する可能性があります。私はそれを2回動かす必要があります。私はいつも注文が「忘れられない」ことを望んでいるわけではありません。 – mks212
私はこれを見ました。賞金を6時間ほど延ばすことができれば、私はこれを世話することができます。 –