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;
    }
    }
Sign In or Register to comment.