CO Cancel Order

infotrade
As per your documentation, you are passing Variety as BO to cancel Co order. Is it valid?
https://github.com/zerodhatech/dotnetkiteconnect/blob/master/KiteConnectSample/Program.cs

// CO LIMIT exiting

kite.CancelOrder(
OrderId: "1234",
Variety: Constants.VARIETY_BO,
ParentOrderId: "5678"
);
  • rakeshr
    @infotrade
    Thanks for pointing it out.We will rectify this.
  • infotrade
    I can't close CO position with code. My Code snippet is
    kite.CancelOrder(order.OrderId, Constants.VARIETY_CO, order.ParentOrderId);

    please correct my code.
  • sujith
    Did you get any error message from the request or you can check the order history or check status message of the order entry?
  • infotrade
    Nothing is happening. here is the code snippet

    List orders = kite.GetOrders().Where(o => o.Status == "OPEN" && scriptNames.Contains(o.Exchange + ":" + o.Tradingsymbol) && o.ParentOrderId != "").ToList();

    if (order.Product == "CO" && order.Tag == tagString)
    {
    kite.CancelOrder(order.OrderId, Constants.VARIETY_CO, order.ParentOrderId);
    await Task.Delay(334);
    }

  • sujith
    You haven't defined the order variable and what if an order is parent order, a parent order will not have parentOrderId.

    PS: We use the same code in our production apps. You must be going wrong somewhere. I suggest going through codebase properly once.
  • infotrade
    infotrade edited November 7
    this is the complete code base,
    List<Order> orders = kite.GetOrders().Where(o => o.Status == "OPEN" && scriptNames.Contains(o.Exchange + ":" + o.Tradingsymbol) && o.ParentOrderId != "").ToList();
    writeLog(logFile, "End kite.GetOrders()");
    foreach (Order order in orders)
    {
    try
    {
    if (orders.Where(o => o.ParentOrderId == order.ParentOrderId && o.Product == "BO" && o.Tag == tagString).ToList().Count > 0)
    {
    kite.CancelOrder(order.OrderId, Constants.VARIETY_BO, order.ParentOrderId);
    await Task.Delay(334);
    }
    else if (order.Product == "CO" && order.Tag == tagString)
    {
    writeLog(logFile, "Cancelling CO Order");
    kite.CancelOrder(order.OrderId, Constants.VARIETY_CO, order.ParentOrderId);
    await Task.Delay(334);
    }
    }
    catch (Exception ex)
    {
    writeLog(logFile, "Error: " + ex.Message);
    }
    }
  • sujith
    Can you run it in debug mode as mentioned here and paste the logs here?
Sign In or Register to comment.