Exiting a Bracket Order

quicksilverm
Hi there,

The examples here show exiting a single child order.
However, with each Bracket Order entry, there are atleast 2 child orders. One of the child order is a
STOP-LOSS order and the second one has to be a LIMIT order ( in OPEN state).

However, for a 1000 quantity execution, there would most likely be multiple children.

Now, the question is -
1. To exit all the quantity, do I need to exit each child ?
2. Or, to exit all the quantity, I can exit on any one child ?
3. Or, to exit all the quantity, I need to exit on only StopLoss orders or only my LIMIT orders.

My current code for exiting order could be something like

public void exitBracketOrder() {
try {
Map params = new HashMap<>();
params.put("parent_order_id", orderId); // Put the parent order here
for (String s : childOrders) {
Order order = kiteConnect.cancelOrder(params, s, "bo");

}
} catch (KiteException e) {
log.error(e.message);
}

}

Here, the childOrders is created in such a way

Order order = kiteConnect.getOrder(orderId);
for (int i = 0; i < order.orders.size(); i++) {
// Do not add the parent
if (order.orders.get(i).parentOrderId != null) {
childOrders.add(order.orders.get(i).orderId);
}
}
  • sujith
    Hi @quicksilverm,
    To exit all quantities, you can cancel any one order either limit or stop loss order.
    If you exit limit order then limit is executed at market and corresponding stop loss order is cancelled.
    Your childOrders list can be populated by filtering orderbook with two conditions,
    1. get orders with parentOrderId param, same as parent order id.
    2. get all limit orders or get all stop loss orders and place cancel request for these orders.
Sign In or Register to comment.