How to cancel orders at once?
How to cancel orders at once?
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
(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
-
- Site Admin
- Posts: 279
- Joined: Mon Jun 11, 2018 11:44 am
- Has thanked: 2 times
- Been thanked: 31 times
Re: How to cancel orders at once?
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?
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));
-
- Site Admin
- Posts: 279
- Joined: Mon Jun 11, 2018 11:44 am
- Has thanked: 2 times
- Been thanked: 31 times
Re: How to cancel orders at once?
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?
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
api.updateOrder for OrderMoveParameters and OrderResizeParameters
-
- Site Admin
- Posts: 279
- Joined: Mon Jun 11, 2018 11:44 am
- Has thanked: 2 times
- Been thanked: 31 times
Re: How to cancel orders at once?
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?
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.
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.
-
- Site Admin
- Posts: 279
- Joined: Mon Jun 11, 2018 11:44 am
- Has thanked: 2 times
- Been thanked: 31 times
Re: How to cancel orders at once?
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)