Skip to main content

dhan_rs/types/
traders_control.rs

1#![allow(missing_docs)]
2//! Trader's Control types — Kill Switch, P&L Based Exit.
3
4use serde::{Deserialize, Serialize};
5
6// ---------------------------------------------------------------------------
7// Kill Switch
8// ---------------------------------------------------------------------------
9
10/// Response from managing or querying the kill switch.
11#[derive(Debug, Clone, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct KillSwitchResponse {
14    pub dhan_client_id: Option<String>,
15    pub kill_switch_status: String,
16}
17
18// ---------------------------------------------------------------------------
19// P&L Based Exit
20// ---------------------------------------------------------------------------
21
22/// Request body for configuring P&L-based auto-exit.
23///
24/// Used by `POST /v2/pnlExit`.
25#[derive(Debug, Clone, Serialize)]
26#[serde(rename_all = "camelCase")]
27pub struct PnlExitRequest {
28    /// Target profit amount to trigger exit.
29    pub profit_value: String,
30    /// Target loss amount to trigger exit.
31    pub loss_value: String,
32    /// Product types to apply exit to (e.g. `["INTRADAY", "DELIVERY"]`).
33    pub product_type: Vec<String>,
34    /// Whether to enable kill switch after exit.
35    pub enable_kill_switch: bool,
36}
37
38/// Response from configuring or stopping P&L-based exit.
39#[derive(Debug, Clone, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct PnlExitResponse {
42    pub pnl_exit_status: String,
43    pub message: String,
44}
45
46/// Current P&L-based exit configuration.
47#[derive(Debug, Clone, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct PnlExitConfig {
50    pub pnl_exit_status: Option<String>,
51    #[serde(default)]
52    pub profit: Option<String>,
53    #[serde(default)]
54    pub loss: Option<String>,
55    /// Product types / segments (may come as `segments` in the wire format).
56    #[serde(default, alias = "segments")]
57    pub product_type: Option<Vec<String>>,
58    #[serde(default)]
59    pub enable_kill_switch: Option<bool>,
60}