Kotak-Neo / kotak-neo-api

100 stars 86 forks source link

How to calculate PNL using positions data & why PNL/MTM is not added in API itself ? #73

Closed ShivdasBachewar closed 9 months ago

ShivdasBachewar commented 9 months ago

I have two queries.

  1. Why Profit/loss value not added in response json positions_api
  2. considering its very complex to share profit/loss value in response, a) how to calculate profit or loss using given data.. b) we get following data after hitting api {"stat": "Ok", "stCode": 200, "data": [{"buyAmt": "2625.00", "cfSellAmt": "0.00", "prod": "NRML", "exSeg": "nse_fo", "sqrFlg": "Y", "actId": "PRS2206", "cfBuyQty": "0", "cfSellQty": "0", "tok": "53179", "flBuyQty": "25", "flSellQty": "25", "sellAmt": "2625.00", "posFlg": "true", "cfBuyAmt": "0.00", "stkPrc": "0.00", "trdSym": "BANKNIFTY21JULFUT", "sym": "BANKNIFTY", "expDt": "29 Jul, 2021", "type": "FUTIDX", "series": "XX", "brdLtQty": "25", "exp": "1627569000", "optTp": "XX", "genNum": "1", "genDen": "1", "prcNum": "1", "prcDen": "1", "lotSz": "25", "multiplier": "1", "precision": "2", "hsUpTm": "2021/07/13 18:34:44"}]}
geek-coder commented 9 months ago

For intraday use (buyAmt -sellAmt ) as initialValue . get currentValue by getting netQty by ( flBuyQty - flSellQty) * current ltp pnl = currentValue - initialValue

For carry forward use cf fields, similarlly.

ShivdasBachewar commented 9 months ago

understood you mean to say

pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);

ShivdasBachewar commented 9 months ago

can kotak neo api add a field on pnl in json response

Kotak-Neo commented 9 months ago

Hi we have added the PnL calculation documentation in the Positions.md file.