kiteconnect_async_wasm/models/orders/
order_margin.rs

1use serde::{Deserialize, Serialize};
2
3use crate::models::common::{Exchange, OrderType, Product, TransactionType, Variety};
4
5/// Request item for order/basket margin calculation APIs
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct OrderMarginRequest {
8    /// Name of the exchange
9    pub exchange: Exchange,
10
11    /// Exchange tradingsymbol of the instrument
12    #[serde(rename = "tradingsymbol")]
13    pub trading_symbol: String,
14
15    /// BUY or SELL
16    #[serde(rename = "transaction_type")]
17    pub transaction_type: TransactionType,
18
19    /// Order variety (regular, amo, co, iceberg, auction)
20    pub variety: Variety,
21
22    /// Margin product to use for the order
23    pub product: Product,
24
25    /// Order type (MARKET, LIMIT, SL, SL-M)
26    #[serde(rename = "order_type")]
27    pub order_type: OrderType,
28
29    /// Quantity of the order
30    pub quantity: u32,
31
32    /// Price at which the order is going to be placed (for LIMIT orders)
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub price: Option<f64>,
35
36    /// Trigger price (for SL, SL-M, CO orders)
37    #[serde(rename = "trigger_price", skip_serializing_if = "Option::is_none")]
38    pub trigger_price: Option<f64>,
39}
40
41// === Typed response models ===
42
43/// GST split for charges block
44#[derive(Debug, Clone, Serialize, Deserialize, Default)]
45pub struct GstBreakup {
46    pub igst: f64,
47    pub cgst: f64,
48    pub sgst: f64,
49    pub total: f64,
50}
51
52/// Charges block for margin and virtual contract note responses
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct ChargesBreakdown {
55    /// Sum of all charges
56    pub total: f64,
57    /// Tax levied for each transaction on the exchanges
58    pub transaction_tax: f64,
59    /// Type of transaction tax (stt/ctt)
60    pub transaction_tax_type: String,
61    /// Exchange turnover charge
62    pub exchange_turnover_charge: f64,
63    /// SEBI turnover charge
64    pub sebi_turnover_charge: f64,
65    /// Brokerage charge
66    pub brokerage: f64,
67    /// Stamp duty
68    pub stamp_duty: f64,
69    /// GST split
70    pub gst: GstBreakup,
71}
72
73/// Realised/unrealised PnL block
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct PnlBreakdown {
76    pub realised: f64,
77    pub unrealised: f64,
78}
79
80/// Per-order margin result item from /margins/orders and also used inside basket responses
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct OrderMarginResult {
83    /// Segment type (equity/commodity)
84    #[serde(rename = "type")]
85    pub type_field: String,
86    /// Trading symbol
87    #[serde(rename = "tradingsymbol")]
88    pub trading_symbol: String,
89    /// Exchange
90    pub exchange: Exchange,
91
92    // Margin components
93    pub span: f64,
94    pub exposure: f64,
95    pub option_premium: f64,
96    pub additional: f64,
97    pub bo: f64,
98    pub cash: f64,
99    pub var: f64,
100
101    /// PnL split
102    pub pnl: PnlBreakdown,
103    /// Allowed leverage
104    pub leverage: f64,
105    /// Charges split
106    pub charges: ChargesBreakdown,
107    /// Total margin block
108    pub total: f64,
109}
110
111/// Basket margins response data block
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct BasketMarginsData {
114    pub initial: OrderMarginResult,
115    pub final_: OrderMarginResult,
116    pub orders: Vec<OrderMarginResult>,
117    pub charges: ChargesBreakdown,
118}
119
120/// Full basket margins API typed response wrapper (data field only)
121#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct BasketMarginsResponse {
123    #[serde(flatten)]
124    pub data: BasketMarginsData,
125}
126
127// === Virtual contract note (charges/orders) ===
128
129/// Request item for virtual contract note (/charges/orders)
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct OrderChargesRequest {
132    /// Arbitrary order id used for grouping (can be any string)
133    pub order_id: String,
134    pub exchange: Exchange,
135    #[serde(rename = "tradingsymbol")]
136    pub trading_symbol: String,
137    #[serde(rename = "transaction_type")]
138    pub transaction_type: TransactionType,
139    pub variety: Variety,
140    pub product: Product,
141    #[serde(rename = "order_type")]
142    pub order_type: OrderType,
143    pub quantity: u32,
144    /// Average execution price (non-zero)
145    #[serde(rename = "average_price")]
146    pub average_price: f64,
147}
148
149/// Response item for virtual contract note (/charges/orders)
150#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct OrderChargesResult {
152    #[serde(rename = "transaction_type")]
153    pub transaction_type: TransactionType,
154    #[serde(rename = "tradingsymbol")]
155    pub trading_symbol: String,
156    pub exchange: Exchange,
157    pub variety: Variety,
158    pub product: Product,
159    #[serde(rename = "order_type")]
160    pub order_type: OrderType,
161    pub quantity: u32,
162    pub price: f64,
163    pub charges: ChargesBreakdown,
164}