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

openTrades() does not return profit taker from bracket order #89

Open
mauserrifle opened this issue Nov 5, 2024 · 4 comments
Open

openTrades() does not return profit taker from bracket order #89

mauserrifle opened this issue Nov 5, 2024 · 4 comments

Comments

@mauserrifle
Copy link

Hi,

I have been successfully using ib_insync in the past and switched to ib_async today. I have an issue now that openTrades() does not return my profit takers anymore from an open bracket order. The profit taker is visible in TWS and it works there. But ib_async only fetches 1 open order which is the stop, the profit taker is missing.

Is there work done on this functionality? Anyone know why this happens? Maybe a TWS related issue? (I tried both stable and latest).

@mauserrifle
Copy link
Author

I started using ib.trades() and this way I can fetch and filter it myself using status. But when I try to modify the profit taker order using placeOrder I get error that the parent order cannot be found. So much is going wrong and I suspect something changed in TWS. I cannot test the original library ib_insync since it doesn't work anymore (disconnect issues) with the latest TWS stable/latest. I have had no issues for 2 years with this codebase and did lots of algo testing (thousand of test trades). Now it seems so bugged. Really wondering whether more people have issues.

@mattsta
Copy link
Contributor

mattsta commented Nov 5, 2024

But ib_async only fetches 1 open order which is the stop, the profit taker is missing.

That does sound odd. Seems it should show either all or nothing, but not just half of them? Maybe double check the config option "Download open orders on connection" is enabled? Also make sure your client id is 0 if you are trying to read orders not placed from the API originally. IBKR restricts orders by client id and only id=0 (by default) can see all orders. Mixing TWS orders and API orders can cause problems sometimes.

when I try to modify the profit taker order using placeOrder I get error that the parent order cannot be found.

Yes, this does happen because the original order is gone, but the updated order still has parentId populated, so when the order is re-submitted, the field doesn't work anymore. If you need to update a bracket order, manually set .parentId = 0 on the updated order. Also make sure updated orders have .transmit = True because sometimes .transmit = False is used when adding bracket orders before enabling them as a full OTOCO/OCA group.

@mauserrifle
Copy link
Author

mauserrifle commented Nov 6, 2024

Thank you so much for such extended response.

I tried ClientId 0, it didn't have affect. It's all orders managed by the API, no mix with manual.

I will do new testing when the market is open again :) Hope to get it working one way or another. I think I should be able to when openTrades() still fails but I use trades() and filtering with the parentId fix. I have transmit on True. I will check the "Download open orders on connection".

Commenting with update soon! Thanks again 🙏

@mauserrifle
Copy link
Author

"Download open orders on connection" was already on.
openTrades() still fails to return the profit taker today but luckily I have a working bot again by using trades() with isActive() array filter. order.parentId = 0 fixed placing the order. Happy it works again! Still strange though.

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