BO Cancel Order

infotrade
@HowUTrade
I have followed the way you mentioned in out last discussion to cancel the BO orders. Link
I am getting error "BO order cannot be cancelled" when I try to cancel it using API.
Code Snippet:

List orders = kite.GetOrders();
foreach (Order order in orders)
{
try
{
if (order.Status == "OPEN" && order.Product == "BO")
{
List orderHistory = kite.GetOrderHistory(order.OrderId);
if (orderHistory[orderHistory.Count - 1].Status != Constants.ORDER_STATUS_COMPLETE)
kite.CancelOrder(order.OrderId);
await Task.Delay(334);
}

}
catch (Exception ex)
{
txtError.AppendText(DateTime.Now + ": Error: "+ ex.Message + Environment.NewLine);
}
}
Tagged:
  • HowUTrade
    @infotrade

    You are using official .Net library, as per its doc
    You need to pass Parent OrderId along with Child OrderId

    // BO SL exiting

    kite.CancelOrder(
    OrderId: "1234",
    Variety: Constants.VARIETY_BO,
    ParentOrderId: "5678"
    );


    Your logic should be like this;
    1.Get Order book
    2.Loop through each order
    3.Check for the condition (Status == "OPEN" && ProdType == "BO" && ParentOrderId != "")
    4.If condition is true then call Kite.CancelOrder(OrderId, Variety, ParentOrderId)

    and you don't need the below i.e. inner loop
    List orderHistory = kite.GetOrderHistory(order.OrderId);
  • infotrade
    It works as expected. Thank you.
This discussion has been closed.