I’ve written a Python-based trading script that consumes Dhan’s WebSocket feed for live market data (LTP) and places orders through the REST endpoints. The code runs smoothly until the very first SELL order is executed; immediately after that trade, the live market feed stops updating and the socket fails to close gracefully. In effect, I’m dealing with a runtime error inside the API integration layer that leaves the connection hanging and the algo without prices. What I need is straightforward: locate the exact point in the code where the disconnect handshake or event loop handling breaks, patch it so the stream stays alive after subsequent orders, and make sure the session shuts down cleanly when I call my exit routine. You’re free to refine how the asyncio event loop, reconnection logic, or callback handlers are organised, provided the overall architecture remains intact. Deliverables • Updated Python script(s) with the runtime fix applied • A short note (or inline comments) explaining what was changed and why • Quick test proof—CLI log or Jupyter snippet—showing the LTP feed still flowing after at least one SELL trade and then closing without errors You’ll likely touch Python 3.10, the official dhanhq WebSocket client, asyncio, and possibly websockets or requests; feel free to introduce lightweight helpers if it makes the flow more robust. Let’s get this feed stable.