Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
helhadry opened this issue Sep 29, 2024 · 1 comment

Comments

@helhadry
Copy link

helhadry commented Sep 29, 2024

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

@helhadry helhadry changed the title One cancels all : Group contains orders for Personal Account One cancels all : group of orders should contain orders with exactly the same account Sep 29, 2024
@mattsta
Copy link
Contributor

mattsta commented Sep 30, 2024

What could be happening:

  • trailing_stop_order is submitted without an account id
  • but place_order() updates trailing_stop_order to populate the account id
  • now stop_loss_order is submitted without an account id too
  • IBKR sees two orders with different account definitions and rejects the combination

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants