I’m currently migrating my trading code from my previous broker to Dhan. While doing so, I noticed that Dhan does not currently provide a socket-based API for live position updates. This feature is quite essential for managing open positions.
Could you please let me know if there are any plans to introduce a WebSocket-based position API in the near future?
Thanks,
Hello @Vishal_Singh
Yes, we do have Positions API and Socket updates for orders. Positions change only post order execution, and this is why mainly API serves as a better solution which can be polled as required or on the event of any order execution.
Can you let us know more about the use case, how socket helps your use case?
I use a position socket API to trail my stop-loss orders in real time. Since my trades typically last less than a minute, relying on a polling-based API means I’d need to hit the endpoint every 2–3 seconds, which feels both inefficient and redundant.
A socket-based position API would be ideal in this scenario—it could push updates instantly, allowing me to respond within seconds and manage exits more effectively. This makes it a strong use case for active traders like me.
Hello @Vishal_Singh
Got it. Two points here, on websocket streaming of Positions:
- For P&L updates, especially calculating stop loss dynamically, will suggest using Live Market Feed along with Positions API, where you only need to poll Positions API in case of any order update on websocket or postback. This is a more efficient system as it ensures that you are actually able to calculate P&L in real-time.
Yes, Positions streaming would also achieve the same, but this would essentially mean us calculating position with every price update (multiple times per second) and then streaming the same to you. This would require you to keep on reading the position websockets, which will involve calculation at both server end and your end.
- Now we do have Super Orders on APIs, which make it extremely simple for you to trail stop loss. You do not need to monitor your position and the running P&L, making code at your end quite straightforward.