I got following exception while getting an order update from websocket. Kindly go through it and do the needful. Below is the response:
{"type":"order","order_id":"200416001702034","variety":"regular","transaction_type":"BUY","quantity":20,"average_price":0,"exchange":"NFO","tradingsymbol":"BANKNIFTY2041618700PE","status":"REJECTED","status_message":"Insufficient funds. Required margin is 3198.00 but available margin is 0.00.","meta":{}}
Exception is below:
JSONObject["data"] not found.
I am testing some of my logic thats why I have not added any amount in my account as of now. Please do the needful.
Simply while placing order I got this exception via websocket order update. May be JSON response which comes from server via websocket like below:
{"type":"order","order_id":"200416001702034","variety":"regular","transaction_type":"BUY","quantity":20,"average_price":0,"exchange":"NFO","tradingsymbol":"BANKNIFTY2041618700PE","status":"REJECTED","status_message":"Insufficient funds. Required margin is 3198.00 but available margin is 0.00.","meta":{}}
Above JSON response is not in appropriate structure and it does not contain "data" key. To reproduce this you have to place order from an account which contains 0 funds and simply print JSON response like this:
Please read comment above this line "return gson.fromJson(String.valueOf(data.get("data")), Order.class);" //=================================================== public Order getOrder(JSONObject data) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override public Date deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { try { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.parse(jsonElement.getAsString()); } catch (ParseException e) { return null; } } }); Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss").create();
// May be this line is cause for that exception. Because you want to get order JSON by using "data" key which actually not in passed JSON Object return gson.fromJson(String.valueOf(data.get("data")), Order.class); }
I have tried this multiple times from yesterday. I am using javakiteconnect 3.1.1 I am getting this message which seems fine.
I did try placing the order for the segment as you mentioned as well and orders were placed from the Kite Connect app and Kite web app as well. The result remains the same. I also tried to print all incoming text messages from the websocket and there were no other messages.
Simply while placing order I got this exception via websocket order update. May be JSON response which comes from server via websocket like below:
{"type":"order","order_id":"200416001702034","variety":"regular","transaction_type":"BUY","quantity":20,"average_price":0,"exchange":"NFO","tradingsymbol":"BANKNIFTY2041618700PE","status":"REJECTED","status_message":"Insufficient funds. Required margin is 3198.00 but available margin is 0.00.","meta":{}}
Above JSON response is not in appropriate structure and it does not contain "data" key. To reproduce this you have to place order from an account which contains 0 funds and simply print JSON response like this: Maybe this JSON response should be like below JSON format which is described in https://kite.trade/docs/connect/v3/orders/ to parse in Order Model appropriately. Now please go through this and do the needful ASAP.
I did try placing the order for the segment as you mentioned as well and orders were placed from the Kite Connect app and Kite web app as well. The result remains the same.
I also tried to print all incoming text messages from the websocket and there were no other messages.
Did you modify the URL of Kite Ticker or make any other code modifications?
Did you find cause?