Skip to main content

dhan_rs/types/
orders.rs

1#![allow(missing_docs)]
2//! Order management types.
3
4use serde::{Deserialize, Serialize};
5
6use crate::types::enums::*;
7
8// ---------------------------------------------------------------------------
9// Place Order
10// ---------------------------------------------------------------------------
11
12/// Request body for placing a new order.
13///
14/// Used by `POST /v2/orders` and `POST /v2/orders/slicing`.
15#[derive(Debug, Clone, Serialize)]
16#[serde(rename_all = "camelCase")]
17pub struct PlaceOrderRequest {
18    /// User-specific identification generated by Dhan.
19    pub dhan_client_id: String,
20    /// User/partner generated tracking ID.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub correlation_id: Option<String>,
23    /// Buy or Sell.
24    pub transaction_type: TransactionType,
25    /// Exchange & segment.
26    pub exchange_segment: ExchangeSegment,
27    /// Product type.
28    pub product_type: ProductType,
29    /// Order type.
30    pub order_type: OrderType,
31    /// Order validity.
32    pub validity: Validity,
33    /// Exchange standard security ID.
34    pub security_id: String,
35    /// Number of shares.
36    pub quantity: u64,
37    /// Number of shares visible (>30% of quantity).
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub disclosed_quantity: Option<u64>,
40    /// Price at which order is placed.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub price: Option<f64>,
43    /// Trigger price for SL/SL-M orders.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub trigger_price: Option<f64>,
46    /// Flag for after-market orders.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub after_market_order: Option<bool>,
49    /// Timing for after-market order.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub amo_time: Option<AmoTime>,
52    /// Bracket order target price change.
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub bo_profit_value: Option<f64>,
55    /// Bracket order stop-loss price change.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub bo_stop_loss_value: Option<f64>,
58}
59
60// ---------------------------------------------------------------------------
61// Modify Order
62// ---------------------------------------------------------------------------
63
64/// Request body for modifying a pending order.
65///
66/// Used by `PUT /v2/orders/{order-id}`.
67#[derive(Debug, Clone, Serialize)]
68#[serde(rename_all = "camelCase")]
69pub struct ModifyOrderRequest {
70    /// User-specific identification generated by Dhan.
71    pub dhan_client_id: String,
72    /// Order ID to modify.
73    pub order_id: String,
74    /// Order type.
75    pub order_type: OrderType,
76    /// Leg name (for BO/CO orders).
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub leg_name: Option<LegName>,
79    /// Quantity to modify.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub quantity: Option<u64>,
82    /// Price to modify.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub price: Option<f64>,
85    /// Disclosed quantity.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub disclosed_quantity: Option<u64>,
88    /// Trigger price for SL/SL-M.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub trigger_price: Option<f64>,
91    /// Validity.
92    pub validity: Validity,
93}
94
95// ---------------------------------------------------------------------------
96// Order Response
97// ---------------------------------------------------------------------------
98
99/// Response from placing, modifying, or cancelling an order.
100#[derive(Debug, Clone, Deserialize)]
101#[serde(rename_all = "camelCase")]
102pub struct OrderResponse {
103    /// Order-specific identification generated by Dhan.
104    pub order_id: String,
105    /// Last updated status of the order.
106    pub order_status: String,
107}
108
109// ---------------------------------------------------------------------------
110// Order Detail (Order Book entry)
111// ---------------------------------------------------------------------------
112
113/// Full order detail as returned by the order book.
114#[derive(Debug, Clone, Deserialize)]
115#[serde(rename_all = "camelCase")]
116pub struct OrderDetail {
117    pub dhan_client_id: Option<String>,
118    pub order_id: Option<String>,
119    pub correlation_id: Option<String>,
120    pub order_status: Option<String>,
121    pub transaction_type: Option<String>,
122    pub exchange_segment: Option<String>,
123    pub product_type: Option<String>,
124    pub order_type: Option<String>,
125    pub validity: Option<String>,
126    pub trading_symbol: Option<String>,
127    pub security_id: Option<String>,
128    #[serde(default)]
129    pub quantity: Option<u64>,
130    #[serde(default)]
131    pub disclosed_quantity: Option<u64>,
132    #[serde(default)]
133    pub price: Option<f64>,
134    #[serde(default)]
135    pub trigger_price: Option<f64>,
136    #[serde(default)]
137    pub after_market_order: Option<bool>,
138    #[serde(default)]
139    pub bo_profit_value: Option<f64>,
140    #[serde(default)]
141    pub bo_stop_loss_value: Option<f64>,
142    pub leg_name: Option<String>,
143    pub create_time: Option<String>,
144    pub update_time: Option<String>,
145    pub exchange_time: Option<String>,
146    pub drv_expiry_date: Option<String>,
147    pub drv_option_type: Option<String>,
148    #[serde(default)]
149    pub drv_strike_price: Option<f64>,
150    pub oms_error_code: Option<String>,
151    pub oms_error_description: Option<String>,
152    pub algo_id: Option<String>,
153    #[serde(default)]
154    pub remaining_quantity: Option<u64>,
155    #[serde(default)]
156    pub average_traded_price: Option<f64>,
157    #[serde(default)]
158    pub filled_qty: Option<u64>,
159}
160
161// ---------------------------------------------------------------------------
162// Trade Detail (Trade Book entry)
163// ---------------------------------------------------------------------------
164
165/// Trade detail as returned by the trade book.
166#[derive(Debug, Clone, Deserialize)]
167#[serde(rename_all = "camelCase")]
168pub struct TradeDetail {
169    pub dhan_client_id: Option<String>,
170    pub order_id: Option<String>,
171    pub exchange_order_id: Option<String>,
172    pub exchange_trade_id: Option<String>,
173    pub transaction_type: Option<String>,
174    pub exchange_segment: Option<String>,
175    pub product_type: Option<String>,
176    pub order_type: Option<String>,
177    pub trading_symbol: Option<String>,
178    pub security_id: Option<String>,
179    #[serde(default)]
180    pub traded_quantity: Option<u64>,
181    #[serde(default)]
182    pub traded_price: Option<f64>,
183    pub create_time: Option<String>,
184    pub update_time: Option<String>,
185    pub exchange_time: Option<String>,
186    pub drv_expiry_date: Option<String>,
187    pub drv_option_type: Option<String>,
188    #[serde(default)]
189    pub drv_strike_price: Option<f64>,
190}