getOrderHistory Java API not working

dudeshetty
I am placing an order using the Java API as shown below:
Order fOrder = s.placeMISOrder(TradeType.BUY, quantity, fEntryPrice);
Here 's' is a custom class developed by me & not relevant to the discussion.

The order gets successfully executed & filled if I monitor it from the UI & appears under Positions.
However if I use the Java API to monitor the status, it seems to give me incorrect status & therefore not helpful in controlling the rest of my java code flow.

The code I am using is as shown below. (connectAPI is the KiteConnect object)
I am exiting the loop after 10 attempts as the API always seems to be getting a status of: PUT ORDER REQ RECEIVED

int count = 0;
fOrder.status = "";
while (!(fOrder.status.equals("COMPLETE") ||
fOrder.status.equals("REJECTED"))) {
Thread.sleep(2000);
System.out.println(fOrder.status);
count += 1;
List orders =
connectAPI.getOrderHistory(fOrder.orderId);
fOrder = orders.get(0);
if (count > 10) {
break;
}
}
  • dudeshetty
    Just had a look at the KiteConnect.java in Github & seems like the issue is not related to the Java API, but the REST API itself. Does the getOrderHistory work with any API for that matter? Please respond at the earliest.
  • sujith
    It seems to be working fine. You can have a look at the documentation to know more about the order history API.
  • dudeshetty
    I already shared the code above. It doesnt seem to be working. I can give example of the orders executed today. eg: OrderID:200401002524971 The order is executed & filled already. It still seems to give a status of "PUT ORDER REQ RECEIVED" & filled quantity as 0 where as the actual filled quantity is 9.
    Let me know if something is wrong in the syntax.
  • sujith
    It is an array of different statuses in our system, any order placed by the user will go through the put order request received status. You need to find the entry where the order status is complete and check the param.
  • dudeshetty
    OK, I get it now & can confirm that the last element of the Array/List has the correct status.
    Below code gets the correct status:
    orderHistory = connectAPI.getOrderHistory(orderId);
    returnOrder = orderHistory.get(orderHistory.size() - 1);
    You can close the thread.
This discussion has been closed.