Cancel pending orders

Hello all, a little help/guidance needed here regarding IBController + TWS

What I have:
IBKR FA Account - one login with multiple accounts under that login.

What I need:
Cancel all pending orders in a specific account, not all.

What I tried:

  1. CancelAllPendingOrders() by itself -- cancels all pending orders like it says.

  2. CancelAllPendingOrders() with SetAccount() which doesn't do what I need because per the instructions SetAccount() specifies the account only for PlaceOrders() and ModifyOrders()

  3. My next thought was to try and get a csv list of pending orders using IBC.GetPendingList(0,"Pending") and then cancel them using a quick loop and CancelOrder() however the GetPendingList() still looks over ALL accounts

  4. I have not found a way to return the account number for a specific pending order... say for example the IBC.GetPendingList(0,"Pending") returns order ids 34,45,47,79... then I would loop through that list, check which account 34 is in, if in that account then Cancel...

One idea would be to store all the orders I sent out in a staticvar per account but this opens the risk of the var getting cleared by mistake... so trying to keep as a last resort.

If anyone have any suggestions, pointers, tips I would appreciate it!

A :slight_smile:

I hope you realize that a specific order ii applicable to one or more account depending on the allocation (read the allocation methods especially on the family account).
This is one to many relationships (order ---> accounts) and what you are asking is not possible to do. If you cancel an order it will have an impact on all related accounts. It is not possible to unscramble an egg.

I’m not sure I am understanding exactly what you are saying… I am not trying to unscramble anything.

Let me rephrase my question:

I have accounts U123, U456 and U789… each are independent accounts that I access using one login (so one TWS instance).

Is there any way that I can return the order ids of all pending orders only in account U123?

If these account are independent (NOT a part of a family account) you can connect to TWS using only one at the time. TWS and IBController tell you which account is active and all orders displayed there are linked to that specific account, so the relationship account ---> orders is one to many, So any order cancellation will be applicable only to one account.