Today I see there has been sudden change in the JSON response for Positions.
The two fields unrealised & realised are not present while making json query for positions.
My entire program started working abruptly because of this. Can you please intimate whenever you make such sudden changes in your API. We have our programs relying on your data. Such sudden changes can screw up Auto Trading Programs.
Also, on the Kite Connect documentation, this field still exists as part of JSON response.
I did my workaround using the below code. If anyone facing the same issue, can use the below code (modify it as per ur prog language) function getUnrealisedProfit($openPosition){ if(!isset($openPosition["unrealised"])){ if($openPosition["netQuantity"] > 0){ var_dump($openPosition); $realised = ($openPosition["sellPrice"] - $openPosition["buyPrice"]) * $openPosition["multiplier"] * $openPosition["sellQuantity"]; $unrealised = $openPosition["pnl"] - $realised; println("Realised PNL = ".$realised); return $unrealised; }elseif($openPosition["netQuantity"] > 0){ $realised = ($openPosition["sellPrice"] - $openPosition["buyPrice"]) * $openPosition["multiplier"] * $openPosition["buyQuantity"]; $unrealised = $openPosition["pnl"] - $realised; return $unrealised; } }else{ return $openPosition["unrealised"]; } }
This is not the correct workaround. It does not give correct results when positions are open. Please dont use it. Lets wait for the patch from IT team.
The fields are added back, but the values in realisedPnl and UnRealised PNL is not coming as correct.
If we book profit once and when we enter the trade again in the same instrument, the realised profit becomes zero and unrealised profit started showing realised profit + non-realised profit.
Again, my program got broke today because of this.
We had recently done some internal changes recently but we didn't intend to change API response format. We are looking into this.
Also, to bring to your notice, most of the fields in JSON response of Positions now have word "day_" prefixed.
For example,
"m2m" - >"day_m2m"
"buy_price" - > "day_buy_price"
"buy_quantity" -> "day_buy_quantity"
.
.
.
etc
Please synchronize the docs and actual JSON response.
If anyone facing the same issue, can use the below code (modify it as per ur prog language)
function getUnrealisedProfit($openPosition){
if(!isset($openPosition["unrealised"])){
if($openPosition["netQuantity"] > 0){
var_dump($openPosition);
$realised = ($openPosition["sellPrice"] - $openPosition["buyPrice"]) * $openPosition["multiplier"] * $openPosition["sellQuantity"];
$unrealised = $openPosition["pnl"] - $realised;
println("Realised PNL = ".$realised);
return $unrealised;
}elseif($openPosition["netQuantity"] > 0){
$realised = ($openPosition["sellPrice"] - $openPosition["buyPrice"]) * $openPosition["multiplier"] * $openPosition["buyQuantity"];
$unrealised = $openPosition["pnl"] - $realised;
return $unrealised;
}
}else{
return $openPosition["unrealised"];
}
}
If anyone facing the same issue, can use the below code (modify it as per ur prog language)
function getUnrealisedProfit($openPosition){
if(!isset($openPosition["unrealised"])){
if($openPosition["netQuantity"] > 0){
var_dump($openPosition);
$realised = ($openPosition["sellPrice"] - $openPosition["buyPrice"]) * $openPosition["multiplier"] * $openPosition["sellQuantity"];
$unrealised = $openPosition["pnl"] - $realised;
println("Realised PNL = ".$realised);
return $unrealised;
}elseif($openPosition["netQuantity"] < 0){
$realised = ($openPosition["sellPrice"] - $openPosition["buyPrice"]) * $openPosition["multiplier"] * $openPosition["buyQuantity"];
$unrealised = $openPosition["pnl"] - $realised;
return $unrealised;
}
}else{
return $openPosition["unrealised"];
}
}
While these properties were depreciated seems we have to manually calculate the realized/unrealized pnl
@sujith is there any change log available.
You guys don't have to do these changes. We will revert it back to old response format.
The fields are added back, but the values in realisedPnl and UnRealised PNL is not coming as correct.
If we book profit once and when we enter the trade again in the same instrument, the realised profit becomes zero and unrealised profit started showing realised profit + non-realised profit.
Again, my program got broke today because of this.
This was not the case before.
Please verify at your end.
Thanks,
Sourabh.
We are looking into this.
There was some confusion about the fields, it is resolved now. We will implement it and make a release soon.