Getting below exception while parsing JSON reponse for position. Have printed the repsonse after stacktrace. Column 276 is at InstrumentToken ends
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was NUMBER at line 1 column 276 path $[0].instrument_token at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72) at com.google.gson.Gson.fromJson(Gson.java:879) at com.google.gson.Gson.fromJson(Gson.java:844) at com.google.gson.Gson.fromJson(Gson.java:793) at com.google.gson.Gson.fromJson(Gson.java:765) at com.zerodhatech.kiteconnect.KiteConnect.getPositions(KiteConnect.java:439)
This is from the official example code public void getPositions(KiteConnect kiteConnect) throws KiteException, IOException { // Get positions returns position model which contains list of positions. Map> position = kiteConnect.getPositions(); System.out.println(position.get("net").size()); System.out.println(position.get("day").size()); }
I have simply added systrace to below Kiteconnect code in order to debug
I added that line because I was getting the error. After removal also, getting the error today too. Don't get it if zero position. But get it if I buy or sell option or buy a stock.
The javakiteconnect is being used on many production systems by many users. We haven't observed any edge case or issue in the getPositions API. I would suggest re-evaluating your code or start afresh if possible.
public void getPositions(KiteConnect kiteConnect) throws KiteException, IOException {
// Get positions returns position model which contains list of positions.
Map> position = kiteConnect.getPositions();
System.out.println(position.get("net").size());
System.out.println(position.get("day").size());
}
I have simply added systrace to below Kiteconnect code in order to debug
public Map> getPositions() throws KiteException, JSONException, IOException {
Map> positionsMap = new HashMap<>();
JSONObject response = new KiteRequestHandler(proxy).getRequest(routes.get("portfolio.positions"), apiKey, accessToken);
JSONObject allPositions = response.getJSONObject("data");
System.out.println(String.valueOf(allPositions.get("net")));
positionsMap.put("net", Arrays.asList(gson.fromJson(String.valueOf(allPositions.get("net")), Position[].class)));
positionsMap.put("day", Arrays.asList(gson.fromJson(String.valueOf(allPositions.get("day")), Position[].class)));
return positionsMap;
}
After removal also, getting the error today too.
Don't get it if zero position.
But get it if I buy or sell option or buy a stock.
I would suggest re-evaluating your code or start afresh if possible.