You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
Hello,
I’m trying to set a bracket order, and I want to place a parent order with several take profits, each one with different targets. To do it, I place 3 bracket orders, but when the first one is filled, I get the error 201-cancelled order ‘you cannot have both sides of the contract…’.
Your orderId logic looks a bit off because if you manually increment parent.orderId + N then the ib.client.getReqId() will generate duplicate IDs in the future. You can just use getReqId() each time.
Your last example looks like it should work, but you'll have a problem if only one take profit triggers at (shares/2) then the price collapses and your stop executes at (shares) because you'll end up short (shares/2) instead of flat like you probably expect.
Hello @mattsta!
Thank you very much for your help.
How should I inform the quantity for the take profits and the stop loss to avoid end up short??
For instance, If I buy 2 contracts, instead of buy_contracts/2, should I code the stop loss as the remaining contracts??
Thanks!!
There's not a "simple" way for IBKR to fix the problem of multiple take-profit at different levels also with a full remaining quantity stop out condition.
Basically, you'd need to write a custom system to watch your trade executions (add a commisionReportEvent handler to catch every symbol+price+side+profit update) then if your take profit order executes first, you submit an order modification to reduce the quantity for the stop loss each time. Also, there's no guarantee a take profit limit order will execute the full quantity anyway so you need to track your live positions against the executed positions on every update too (so you could have: BUY 100, SELL 50, SELL 50, STOP 100, but maybe it executes BUY 100, SELL 25, STOP 100 (you end up short -25), so you would need to manually update STOP 100 to be STOP 75 after the first SELL 25 happens, etc).
It's not easy to automate multiple partial take profit orders like that, but it can be done if you track all the edge cases.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello,
I’m trying to set a bracket order, and I want to place a parent order with several take profits, each one with different targets. To do it, I place 3 bracket orders, but when the first one is filled, I get the error 201-cancelled order ‘you cannot have both sides of the contract…’.
this is the code I run:
The lmtPrice and auxPrice should be changed once the first parent order has been filled.
I think maybe I could change the order as it follows:
or maybe like this:
Has somebody got any idea how to set this order properly?
thank you very much
The text was updated successfully, but these errors were encountered: