How to cancel orders at once?

Custom indicators, trading strategies, data export and recording and more...
blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

How to cancel orders at once?

Post by blk » Wed May 12, 2021 1:26 am

Hi,

(Addon using rithmic data and bookmap simplified API)

Is there a way to send a cancel to all active orders without triggering the "Too many cancels last 30sec" error from Rithmic? This does not happen If I click in the cancel/flat TCP buttons so I'm wondering if there is a way to group the orders and call "cancel all" using a single call to the API provider (api.updateOrder)?

Thanks

Svyatoslav
Site Admin
Posts: 183
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 25 times

Re: How to cancel orders at once?

Post by Svyatoslav » Wed May 12, 2021 7:23 am

Hi. There is no true "cancel all" in API at this point, but pay attention to OrderCancelParameters#batchId and OrderCancelParameters#batchEnd. So you send a bunch of cancellations with the same batch ID, then send batch end flag in last message. This way bookmap knows not to send redundant cancellations, like in case of OCO pairs, which is what triggers those warnings.

blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

Re: How to cancel orders at once?

Post by blk » Wed May 12, 2021 12:17 pm

Hi, thanks for your reply.  So using the batchId and batchEnd we can try something like this?
 

Code: Select all

[size=100]long batchId = ThreadLocalRandom.current().nextLong(1000);[/size]
for (int i = 0; i < orderIds.size() - 1; i++) {
    api.updateOrder(new OrderCancelParameters(orderIds.get(i), batchId, false));
}
//End of batch
api.updateOrder(new OrderCancelParameters(orderIds.get(i) - 1, batchId, true));

Svyatoslav
Site Admin
Posts: 183
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 25 times

Re: How to cancel orders at once?

Post by Svyatoslav » Wed May 12, 2021 12:20 pm

Yes, just use entire range of Long to decrease chances of collision with any other simultaneously executed batch.

blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

Re: How to cancel orders at once?

Post by blk » Wed May 12, 2021 12:36 pm

Ok, thanks for your help

blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

Re: How to cancel orders at once?

Post by blk » Wed May 12, 2021 8:00 pm

I have another question... if I need to move X orders or update the size or X orders... Is there a recommended way to do it? Wondering if we can do it in batches to avoid Rithmic messages...

api.updateOrder for OrderMoveParameters and OrderResizeParameters

Svyatoslav
Site Admin
Posts: 183
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 25 times

Re: How to cancel orders at once?

Post by Svyatoslav » Thu May 13, 2021 5:02 am

It's not currently supported, you have to update those one by one. But I don't think Rithimic will show you a warning unless you are moving a really large number of orders.

blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

Re: How to cancel orders at once?

Post by blk » Thu May 13, 2021 12:43 pm

Got it... Is there a way to capture the error messages when we try to update/cancel order via bookmap API ?

Lets say Rithmic returned "Atomic order operation in progress", I'm wondering if we can catch that message to try again after some time if the order is still active.

Svyatoslav
Site Admin
Posts: 183
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 25 times

Re: How to cancel orders at once?

Post by Svyatoslav » Thu May 13, 2021 4:38 pm

Well, you can catch the text message via Layer1ApiAdminListener#onSystemTextMessage, but you won't be able to clearly match it to an order (you can do it approximately via some heuristics, but that's not ideal, of course)

Post Reply