Now Live: P&L based Exit and Exit All on APIs

Hello Traders,

DhanHQ APIs were built with the philosophy to bring institutional-grade capabilities to retail API traders in India.

From the start, we’ve focused on removing barriers between your strategy and execution. Whether it’s streaming full market depth, providing expired options data for backtesting, enabling technical conditions through Conditional Triggers, or delivering seamless order execution through DEXT - every API we ship is designed to eliminate something you’d otherwise have to build yourself.

Whenever we are building any new feature, it should pass these two questions. First, is this new feature making trading simpler or more efficient for a trader. And the second, is it adding value to their current trading setup.

For DhanHQ APIs, we aim to cut down the effort and time taken between fetching data from a broker to executing order. But there is much more once an order is placed on the exchange and traders have an active position.

Risk Management - this is the one area where even the most sophisticated API traders end up writing the same repetitive code. Given the criticality of this step, once you have an active position, managing risk requires handling scenarios in real time which are computation heavy.

Until now, retail traders had to go through extensive development cycles just to get proper risk management in place for their trades. This includes writing code to track cumulative P&L across positions, calculating profit and loss thresholds in real-time, building exit logic that works across different product types, and ensuring orders execute fast enough when limits are breached. This entire workflow takes up significant development time and computational resources, and traders often run into execution delays and errors during critical exit moments. At the same time, systems lacked the reliability to handle sudden market movements and the ability to exit all positions instantly when broader market conditions demanded it.

We are eliminating this entire workflow today. Risk management has been at the core of trading on Dhan - whether that be through features like Trader’s Control on our platforms or execution guardrails we’ve built into DEXT or building an all new Order type with Super Orders.

We started with bringing Kill Switch on API. We have also worked to bring automation to order execution through Conditional Triggers and Super Orders. We are bringing the same automation and reliability to risk management now on APIs.

Introducing: P&L based Exit and Exit All Positions on APIs

P&L Based Exit - is automated risk management that runs on our infrastructure, not yours. Set your profit and loss thresholds once, and we monitor your cumulative P&L across all positions in real-time. The moment your limits are hit, all applicable positions exit automatically. No monitoring scripts. No manual intervention. No delays. No Heavy-lifting at your end.

Exit All Positions - is your master position management tool. One API call, and every open position closes while every pending order cancels, instantly. Whether you’re responding to macro events, time-based rules, or just need to shut down operations, your entire book clears in one action. With this you can build your own Kill-Switch for Open Positions at your end.

What does this change for API Traders and Developers

With the P&L Based Exit API, your risk parameters stay active throughout the trading session. Set your profit and loss values once, choose which product types to monitor - INTRADAY, DELIVERY, or both - and enable kill switch for complete position closure if needed.

Our systems track your cumulative P&L in real-time and execute exits automatically when thresholds are breached. As a developer, you skip building P&L tracking systems and exit logic across multiple positions - one API call handles data aggregation, threshold monitoring, and exit order placement.

The Exit All Positions API gives you absolute control when you need it. Not all exits are threshold-based - sometimes your strategy responds to broader market conditions, external signals, or time rules. One API call exits all positions and cancels all orders simultaneously, ensuring your entire book clears instantly when your strategy demands it.

You maintain full control after configuration. Modify profit and loss values at any time without restarting. Check current settings through status APIs. Settings automatically reset at market close to keep strategies fresh each day. Stop P&L exits entirely if conditions change. Every action is trackable, every configuration is accessible.

The P&L Based Exit and Exit All Positions APIs are currently available for all product types on DhanHQ, with real-time P&L monitoring and instant execution backed by DEXT.

The complete API documentation with all endpoints, parameters, and response structures is live on DhanHQ API Documentation - here.

As always, we’ll keep evolving this based on how you use it. Your feedback matters whether it’s a feature request, a bug report, or just sharing how these APIs fit into your risk management strategies.

Here’s to trading with confidence, knowing your risk is always under control.

Happy Building and Trading with APIs on Dhan,
Hardik

1 Like

Hi @Hardik, the link ‘DhanHQ API Documentation - here.’ is missing. Please update.

Hi @Market_Wizard It is now updated. Please check.

Can this control be implemented when in profit to preserve profit

Hi @Vikas_Chourasia, welcome to MadeforTrade!

We will evaluate this with our team, thank you for your valuable feedback.