Page 1 of 1

How to cancel orders at once?

Posted: Wed May 12, 2021 1:26 am
by blk
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

Re: How to cancel orders at once?

Posted: Wed May 12, 2021 7:23 am
by Svyatoslav
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.

Re: How to cancel orders at once?

Posted: Wed May 12, 2021 12:17 pm
by blk
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));

Re: How to cancel orders at once?

Posted: Wed May 12, 2021 12:20 pm
by Svyatoslav
Yes, just use entire range of Long to decrease chances of collision with any other simultaneously executed batch.

Re: How to cancel orders at once?

Posted: Wed May 12, 2021 12:36 pm
by blk
Ok, thanks for your help

Re: How to cancel orders at once?

Posted: Wed May 12, 2021 8:00 pm
by blk
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

Re: How to cancel orders at once?

Posted: Thu May 13, 2021 5:02 am
by Svyatoslav
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.

Re: How to cancel orders at once?

Posted: Thu May 13, 2021 12:43 pm
by blk
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.

Re: How to cancel orders at once?

Posted: Thu May 13, 2021 4:38 pm
by Svyatoslav
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)