Live PNL API Endpoint

Hello is there any direct endpoint to fetch live PNL for all the open positions ?

I tried creating by using position api but that has lot of things to do like summing up the unrealized profit and all other stuff also since it is not based on websocket fetching live data continuously is not working properly as I have used loop function

There isn’t. We have to calculate on our end using LTPs and depth

@optionstrader could you please share the logic

Simplest way is to Fetch LTPs from Sockets/Api calls / Quotes

Then Fetch positions from order books i.e entry/exit prices and calculate PNL at our end based on LTP

Hello @optionstrader @fisek209281

We have actually added this on V2, where you get unrealised profit value. You just need to sum open positions to get overall P&L.

@Shiva_Devendra Welcome to MadeForTrade community!

1 Like

Super cool, will explore the endpoints .Thank you

Hello @Hardik I am creating a script that fetches overall live pnl and if it reaches my loss limit it will close all the open position and activate kill switch.
For closing the position I just get the order details from open position using position api and placing the sell order. However, for live pnl I have used loop function that is creating a mess.
Is there any other way to fetch live pnl ? without using loop function.

Hello @Shiva_Devendra

Currently, to calculate live PnL using the API, you can either compare the LTP (Last Traded Price) with the Buy Price, or calculate it based on your Unrealized Profit. Please note that performing this calculation might requires the use of a loop.

1 Like

actually unrealizedProfit return wrong data

There used to be warning for this on v1, but v2 does not have the warning and yet it still returns the wrong data

@Hardik @fisek209281 I have read the V2 API doc and there are many things that needs to be corrected - the url for kill switch is also incorrect. Please check…

Hello @fisek209281 @Shiva_Devendra

Thank you for highlighting, will check this and change if required.