https://api.dhan.co/positions
response
{“dhanClientId”:"**********",“tradingSymbol”:“RELIANCE”,“securityId”:“2885”,“positionType”:“LONG”,“exchangeSegment”:“NSE_EQ”,“productType”:“INTRADAY”,“buyAvg”:2512.4,“buyQty”:1,“sellAvg”:0.0,“sellQty”:0,“netQty”:1,“realizedProfit”:0.0,“unrealizedProfit”:0.0,“rbiReferenceRate”:1.0,“multiplier”:1,“carryForwardBuyQty”:0,“carryForwardSellQty”:0,“carryForwardBuyValue”:0.0,“carryForwardSellValue”:0.0,“dayBuyQty”:1,“daySellQty”:0,“dayBuyValue”:2512.4,“daySellValue”:0.0,“drvExpiryDate”:“0001-01-01”,“drvOptionType”:“NA”,“drvStrikePrice”:0.0,“crossCurrency”:false}
Hi @vive1101011
hey @vive1101011, this is not a bug. We don’t provide this data on APIs, most users who consume APIs can simply add P&L on all individual positions and get this with a simple query. We do the same and render combined P&L on the fly on Dhan platforms - you will see this is much much faster than all other platforms out there.
Why we don’t provide this - to get collective P&L from all positions on LTP that is changing dynamically and then streaming it - will result in lag & performance issues if we start streaming this.
Sir,
Actually the problem is if quote api(getting LTP) not available to the individual investors then the only option left to calculate p&l is using /charts/intraday 1min candle close, which is delayed.
Hey @PravinJ,
My two cents:
- Having an unrealised P&L (or even realised P&L) seem like a first class entity for any Position, and hence even at cost of some performance, the preference would be to have it coming from source rather than the clients getting LTP separately for each stock having a position and computing it. Majority of clients can bear a lag of ~1 second as they won’t be having an HFT use-case. Those having one would anyways fetch LTP themselves.
- I would feel the central source would be more optimised in terms of lag because of multiple requests coming in which can be pooled. It might be suboptimal if each of us client does it individually.
(Btw, if the proposal is to not provide unrealised or realised profits in the Positions API, why even keep those empty fields there, and leave room for confusion?)
Hoping the team would accommodate the above request
Hey @ms25
Fair point you have on this… and we did speak with many users while building APIs. Most, and when I say most its very high calculate this by themselves.
If you will see our implementation of P&L in any of Dhan’s platforms - App or Web, we render P&L much much faster than anyone else would, and we do it on the fly there itself. When we give P&L to users via APIs, it comes live from our trading systems and that basically will take it down (by load and hamper performance) as we will have to calculate this and transmit.
Additionally, many API users we have interacted with have their own source of LTP / Live Prices. So their use-case of trading is just resolved with trading APIs. Also our infrastructure cost of trading APIs is significantly lower than data broadcast APIs (live P&L). That helps us give Trading APIs for free.
We recently made Trading APIs of Dhan free: DhanHQ Superfast Trading APIs Update: Trading APIs are now FREE for all
Thank you @PravinJ for the prompt response
Sure, I can understand. Anyways, its not a burning problem for me, and can live without it.
I do feel that if any fields are not being populated, why to pass them unnecessary
Increases the payload and processing on client end.
Maybe the fields not being populated/used can be removed, also to remove any confusion and expectations
Hi stanly_thomas,
I was not able to implement instant pnl as tick data is still not available on Dhan.
@PravinJ
Algo Trader’s like us are Facing issues as
Ticker data is not available. We are unable to calculate PNL and SET SL in system.
Relying on Ohlc data of 1 minute candles will effect our system considerably.
Pls consider websocket a Priority.