**IMP** Sudden Changes in JSON response of API crashed my program

pivottrading.net
Hi Guys,

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.

Please reply

Thanks,
Sourabh.
  • sujith
    Hi @Saurabh,
    We had recently done some internal changes recently but we didn't intend to change API response format. We are looking into this.
  • pivottrading.net
    pivottrading.net edited March 2017
    Thanks Sujith for the reply.

    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.
  • pivottrading.net
    pivottrading.net edited March 2017
    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"];
    }
    }
  • pivottrading.net
    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"];
    }
    }
  • pivottrading.net
    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.
  • joy
    Seems the following properties were added
    "day_buy_price"
    "day_sell_value"
    "day_buy_quantity"
    "buy_m2m"
    "day_sell_price"
    "sell_m2m"
    "day_buy_value"
    "day_sell_quantity"
    "token"
    "type"

    While these properties were depreciated
    "unrealised"
    "value"
    "realised"
    seems we have to manually calculate the realized/unrealized pnl :(

    @sujith is there any change log available.
  • sujith
    @joy, @pivottrading.net,
    You guys don't have to do these changes. We will revert it back to old response format.
  • pivottrading.net
    Sujith,

    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.
  • sujith
    Hi Saurabh,
    We are looking into this.
  • sujith
    Hi Saurabh,
    There was some confusion about the fields, it is resolved now. We will implement it and make a release soon.
Sign In or Register to comment.