dhan_rs/api/
traders_control.rs1use crate::client::DhanClient;
4use crate::error::{DhanError, Result};
5use crate::types::traders_control::*;
6
7impl DhanClient {
8 pub async fn manage_kill_switch(&self, status: &str) -> Result<KillSwitchResponse> {
14 if !matches!(status, "ACTIVATE" | "DEACTIVATE") {
15 return Err(DhanError::InvalidArgument(
16 "kill switch status must be ACTIVATE or DEACTIVATE".into(),
17 ));
18 }
19 let path = match status {
22 "ACTIVATE" => "/v2/killswitch?killSwitchStatus=ACTIVATE",
23 "DEACTIVATE" => "/v2/killswitch?killSwitchStatus=DEACTIVATE",
24 _ => unreachable!("status was validated above"),
25 };
26 self.post_without_body(path).await
27 }
28
29 pub async fn get_kill_switch_status(&self) -> Result<KillSwitchResponse> {
33 self.get("/v2/killswitch").await
34 }
35
36 pub async fn set_pnl_exit(&self, req: &PnlExitRequest) -> Result<PnlExitResponse> {
40 req.validate()
41 .map_err(|message| DhanError::InvalidArgument(message.into()))?;
42 self.post("/v2/pnlExit", req).await
43 }
44
45 pub async fn stop_pnl_exit(&self) -> Result<PnlExitResponse> {
49 self.delete("/v2/pnlExit").await
50 }
51
52 pub async fn get_pnl_exit(&self) -> Result<PnlExitConfig> {
56 self.get("/v2/pnlExit").await
57 }
58}