How to know current status of a SL-L order?

akhilesh_singla
I want to modify my SL-L order. Before the modification, I should know if SL-L order is completed or not. But JSON returned from Kite always show SL-L order state "success" instead of "Trigger Pending" state. I'm using below code to get current status:
function checkOrderStatus(orderId) {
const urlEndPoint = orderUrl + "/" + orderId;

const response = UrlFetchApp.fetch(urlEndPoint, {
method: "GET",
headers: {
"Authorization": "token " + apiKey + ":" + accessToken
}
});

return JSON.parse(response.getContentText()).status;
}
  • akhilesh_singla
    akhilesh_singla edited April 25
    @sujith Could you please help? Instead of checking order status, should I send order modification request straightaway and if exception occur (indicating SL-L order got completed), then handle it accordingly?
  • sujith
    You seem to be fetching order history, you can know more about the API structure here.
  • akhilesh_singla
    Thanks. I resolved it myself as below:
    function modifyOrder(orderId, price) {
    const order = {
    price: price,
    trigger_price: (price - 0.05)
    };

    const urlEndPoint = isIceberg ? orderUrl + "/iceberg/" + orderId : orderUrl + "/regular/" + orderId;

    try {
    const response = UrlFetchApp.fetch(urlEndPoint, {
    method: "PUT",
    headers: {
    "Authorization": "token " + apiKey + ":" + accessToken
    },
    payload: toFormData(order)
    });
    console.log("SL modified to ", price);
    return true;
    } catch (e) {
    console.log("SL order completed");
    return false;
    }
    }
  • sujith
    A success response for modify order request doesn't mean order is modified. It means the order modification request is success. Once the request reaches Kite Trade, it is passed on to our internal mini RMS, other OMS and OMS checks and exchange checks and then if all the checks go through in all the hops then only it is modified.
    Hence it is better to fetch order and check before confirming that order is modified or not.
    If the new value is not visible in the fetch order response then the rejection reason is in the status_message of the order response.
Sign In or Register to comment.