1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Trader's Control endpoints — Kill Switch, P&L Based Exit.
use crate::client::DhanClient;
use crate::error::{DhanError, Result};
use crate::types::traders_control::*;
impl DhanClient {
/// Activate or deactivate the kill switch for the current trading day.
///
/// Pass `"ACTIVATE"` or `"DEACTIVATE"` as the `status` parameter.
///
/// **Endpoint:** `POST /v2/killswitch?killSwitchStatus={status}`
pub async fn manage_kill_switch(&self, status: &str) -> Result<KillSwitchResponse> {
if !matches!(status, "ACTIVATE" | "DEACTIVATE") {
return Err(DhanError::InvalidArgument(
"kill switch status must be ACTIVATE or DEACTIVATE".into(),
));
}
// The only accepted values are fixed protocol enums, so no caller
// input is interpolated into the query string.
let path = match status {
"ACTIVATE" => "/v2/killswitch?killSwitchStatus=ACTIVATE",
"DEACTIVATE" => "/v2/killswitch?killSwitchStatus=DEACTIVATE",
_ => unreachable!("status was validated above"),
};
self.post_without_body(path).await
}
/// Retrieve current kill switch status.
///
/// **Endpoint:** `GET /v2/killswitch`
pub async fn get_kill_switch_status(&self) -> Result<KillSwitchResponse> {
self.get("/v2/killswitch").await
}
/// Configure P&L-based auto-exit for the current trading day.
///
/// **Endpoint:** `POST /v2/pnlExit`
pub async fn set_pnl_exit(&self, req: &PnlExitRequest) -> Result<PnlExitResponse> {
req.validate()
.map_err(|message| DhanError::InvalidArgument(message.into()))?;
self.post("/v2/pnlExit", req).await
}
/// Disable the active P&L-based exit configuration.
///
/// **Endpoint:** `DELETE /v2/pnlExit`
pub async fn stop_pnl_exit(&self) -> Result<PnlExitResponse> {
self.delete("/v2/pnlExit").await
}
/// Fetch the currently active P&L-based exit configuration.
///
/// **Endpoint:** `GET /v2/pnlExit`
pub async fn get_pnl_exit(&self) -> Result<PnlExitConfig> {
self.get("/v2/pnlExit").await
}
}