ib-api-reloaded / ib_async

Python sync/async framework for Interactive Brokers API (replaces ib_insync)
BSD 2-Clause "Simplified" License
370 stars 62 forks source link

One cancels all : group of orders should contain orders with exactly the same account #75

Open helhadry opened 4 days ago

helhadry commented 4 days ago

Hello,

I get this error while creating the trail and the stop order using the one cancels all logic (OCA), it's working fine in the paper account but not in the live account, below is the error message:

ERROR - Error 10224, reqId 673: One-cancels-all group of orders should contain orders with exactly the same account. OCA group '0913e328-d9c4-4b4a-99b8-f6b921824f25' contains orders for Personal Account (account_name), Undefined.

What can be the issue here please ? below is the code if this help :

oca_group_name = str(uuid.uuid4())

if position["enable_trailing_stop"]:
    trailing_stop_order = Order(
        orderType="TRAIL",
        action="SELL",
        totalQuantity=position["current_shares"],
        trailingPercent=position["trailing_stop"] * 100,
        tif="GTC",
        outsideRth=True,
        ocaGroup=oca_group_name,
        ocaType=1,
    )

    trade = self.place_order(position["contract"], trailing_stop_order)

    position["trailing_stop_order_id"] = trade.order.orderId
    position["trailing_stop_order"] = trade.order

stop_loss_order = StopOrder("SELL", position["current_shares"], stop_loss_price, tif="GTC", outsideRth=True)
stop_loss_order.ocaGroup = oca_group_name
stop_loss_order.ocaType = 1

trade = self.place_order(position["contract"], stop_loss_order)

Thanks, Hamza

mattsta commented 2 days ago

What could be happening:

The more standard way of doing this would be to use parent orders if everything is submitted at once (buy <- {sell loss, sell, profit}): https://interactivebrokers.github.io/tws-api/bracket_order.html

Or you could manually add your account id to every order too.