Skip to main content

dhan_rs/api/
portfolio.rs

1//! Portfolio endpoints — Holdings, Positions, Convert Position, Exit All.
2
3use crate::client::DhanClient;
4use crate::error::Result;
5use crate::types::portfolio::*;
6
7impl DhanClient {
8    /// Retrieve all holdings in the demat account.
9    ///
10    /// **Endpoint:** `GET /v2/holdings`
11    pub async fn get_holdings(&self) -> Result<Vec<Holding>> {
12        self.get("/v2/holdings").await
13    }
14
15    /// Retrieve all open positions for the day.
16    ///
17    /// **Endpoint:** `GET /v2/positions`
18    pub async fn get_positions(&self) -> Result<Vec<Position>> {
19        self.get("/v2/positions").await
20    }
21
22    /// Convert a position's product type (e.g. intraday → delivery).
23    ///
24    /// Returns `202 Accepted` on success.
25    ///
26    /// **Endpoint:** `POST /v2/positions/convert`
27    pub async fn convert_position(&self, req: &ConvertPositionRequest) -> Result<()> {
28        self.post_no_content("/v2/positions/convert", req).await
29    }
30
31    /// Exit all active positions and cancel all open orders.
32    ///
33    /// **Endpoint:** `DELETE /v2/positions`
34    pub async fn exit_all_positions(&self) -> Result<ExitAllResponse> {
35        self.delete("/v2/positions").await
36    }
37}