Hi team, As there is no support api to get the positions realized or unrealised profit or loss. How can a custom application calculate the positions pnl on daily basis ? I am looking forward to keep the historical profit loss like console. What's the way to calculate that using orders or tradebook api ?
Kite Connect APIs currently support only trading platform functionalities and do not provide access to back-office data. To access the tradebook, ledger, and other reports, please download them from the Zerodha Console. The historical tradebook is not available via the API at this time.
You can retrieve P&L details for open positions using the Positions API; however, it is not recommended to continuously poll the Positions endpoint for updated P&L. Instead, you should calculate P&L at your end using the formula:
I understood about daily live positions pnl. But if someone have to implement the reports like daily pnl and view back, how one can do that ? Just by fetching orders or positions it's sufficient to calculate the pnl ? The problem occured when positions can be left on expiry date without exits
The formula remains the same for both realised and unrealised P&L. You can calculate P&L at your end using the same formula: pnl = (sellValue - buyValue) + (netQuantity × lastPrice × multiplier)
For realised P&L, you need to replace the lastPrice with the actual sell price or the settlement price. This article provides a more detailed explanation.
You can retrieve P&L details for open positions using the Positions API; however, it is not recommended to continuously poll the Positions endpoint for updated P&L. Instead, you should calculate P&L at your end using the formula:
pnl = (sellValue - buyValue) + (netQuantity × lastPrice × multiplier)
The lastPrice can be obtained via the WebSocket or the Quote API. Please refer to the position API documentation for more details. You may refer to the similar discussion here.
But if someone have to implement the reports like daily pnl and view back, how one can do that ?
Just by fetching orders or positions it's sufficient to calculate the pnl ? The problem occured when positions can be left on expiry date without exits
pnl = (sellValue - buyValue) + (netQuantity × lastPrice × multiplier)
For realised P&L, you need to replace the lastPrice with the actual sell price or the settlement price. This article provides a more detailed explanation.