Profit and loss via v2 api

Hi,

I would like to know if there is any functionality in the v2 API by which I can find my profit and loss. Just like in the mobile app, I see my total profit/loss of the upstox portfolio, can I get the same via the program? I am using python

HI @Harbilas_Bal

To answer your query, you can get profit and loss via 2 methods

  1. For historical trade profit and loss, do visit the Trade Profit and Loss section of the documentation

  2. To get P&L of an existing position, you can use the Get Positions API in the portfolio section.

For positions API
However, do note that there will be a cache of upto 1 minute for response from Positions API so you might see a slightly outdated P&L.

To get the current P&L, you can get LTP of the instrument via websockets and use the below formula to compute your current P&L
pnl = (buy_value - sell_value) + (quantity * multiplier * ltp)
(All fields are available in the response of the API)

Hope this helps

Above calc I have to perform, on which output? O/p from trade p/l or get positions?
Secondly, in either case, it is tedious because if I have N stocks, I need to to this for each script.
So, I want p/l from holdings, not positions.

@Harbilas_Bal

The calculations mentioned are of positions API if you want real-time P&L of your existing positions down to the second

The trade profit and loss API gives you the profit and loss of your holdings for a period and segment similar to a tax report

Hope this helps