Executed Price Returning NULL for Order ID

APPU
Dear Team,

I am occasionally encountering an issue where the executed price is returned as NULL for certain order IDs. Below is a sample snippet of the code:

private String getexecutedPrice(String orderId) {
String executedPrice = null;
KiteConnect kiteConnect = new KiteConnect(KiteAppConstants.API_KEY);
kiteConnect.setAccessToken(getToken());
List orderDetails = null;
try {
orderDetails = kiteConnect.getOrderTrades(orderId);
} catch (JSONException | IOException | KiteException e) {
e.printStackTrace();
}
for (Trade orderinfo : orderDetails) {
executedPrice = orderinfo.averagePrice;
}
return executedPrice;
}


Logs:

Failed after two retry:

Request Order Placed 1874313719496859648 Time Wed Jan 01 10:06:28 IST 2025
Execute Price null Time Wed Jan 01 10:06:28 IST 2025
Execute Price null Time Wed Jan 01 10:06:28 IST 2025
Failed to retrieve executedPrice after 2 attempts.


Occasional success in one retry:

Request Order Placed 1873954824345640960 Time Tue Dec 31 10:20:21 IST 2024
Execute Price null Time Tue Dec 31 10:20:21 IST 2024
Execute Price 164.25 Time Tue Dec 31 10:20:21 IST 2024

Most of the time, the value is retrieved successfully without any issues. Could you please advise on what needs to be done? This is critical since my stop-loss and target calculations depend on the executed price.
Regards
Appu
  • sujith
    You can add a few milliseconds delay and then fetch the orderbook. It is possible that orderbook hasn't been updated on Kite Trade by the time you fetch the orders.
Sign In or Register to comment.