dhan_rs/api/traders_control.rs
1//! Trader's Control endpoints — Kill Switch, P&L Based Exit.
2
3use crate::client::DhanClient;
4use crate::error::Result;
5use crate::types::traders_control::*;
6
7impl DhanClient {
8 /// Activate or deactivate the kill switch for the current trading day.
9 ///
10 /// Pass `"ACTIVATE"` or `"DEACTIVATE"` as the `status` parameter.
11 ///
12 /// **Endpoint:** `POST /v2/killswitch?killSwitchStatus={status}`
13 pub async fn manage_kill_switch(&self, status: &str) -> Result<KillSwitchResponse> {
14 let path = format!("/v2/killswitch?killSwitchStatus={status}");
15 // POST with no body — send an empty JSON object.
16 self.post(&path, &serde_json::json!({})).await
17 }
18
19 /// Retrieve current kill switch status.
20 ///
21 /// **Endpoint:** `GET /v2/killswitch`
22 pub async fn get_kill_switch_status(&self) -> Result<KillSwitchResponse> {
23 self.get("/v2/killswitch").await
24 }
25
26 /// Configure P&L-based auto-exit for the current trading day.
27 ///
28 /// **Endpoint:** `PUT /v2/pnlExit`
29 pub async fn set_pnl_exit(&self, req: &PnlExitRequest) -> Result<PnlExitResponse> {
30 self.put("/v2/pnlExit", req).await
31 }
32
33 /// Disable the active P&L-based exit configuration.
34 ///
35 /// **Endpoint:** `DELETE /v2/pnlExit`
36 pub async fn stop_pnl_exit(&self) -> Result<PnlExitResponse> {
37 self.delete("/v2/pnlExit").await
38 }
39
40 /// Fetch the currently active P&L-based exit configuration.
41 ///
42 /// **Endpoint:** `GET /v2/pnlExit`
43 pub async fn get_pnl_exit(&self) -> Result<PnlExitConfig> {
44 self.get("/v2/pnlExit").await
45 }
46}