Skip to main content

dhan_rs/api/
data.rs

1//! Data API endpoints for rolling options, technical metrics, market movers,
2//! and company information.
3
4use crate::client::DhanClient;
5use crate::error::{DhanError, Result};
6use crate::types::data::*;
7
8impl DhanClient {
9    /// Fetch continuous expired-option chart data.
10    ///
11    /// **Endpoint:** `POST /v2/charts/rollingoption`
12    pub async fn get_rolling_option_data(
13        &self,
14        req: &RollingOptionRequest,
15    ) -> Result<RollingOptionResponse> {
16        req.validate()
17            .map_err(|message| DhanError::InvalidArgument(message.into()))?;
18        self.post("/v2/charts/rollingoption", req).await
19    }
20
21    /// Fetch point-in-time technical indicators for the latest closed candle.
22    ///
23    /// **Endpoint:** `POST /v2/data/technical`
24    pub async fn get_technical_metrics(
25        &self,
26        req: &TechnicalMetricsRequest,
27    ) -> Result<TechnicalMetricsResponse> {
28        req.validate()
29            .map_err(|message| DhanError::InvalidArgument(message.into()))?;
30        self.post("/v2/data/technical", req).await
31    }
32
33    /// Fetch instruments ranked by OI, volume, or price movement.
34    ///
35    /// **Endpoint:** `POST /v2/data/marketmovers`
36    pub async fn get_market_movers(
37        &self,
38        req: &MarketMoversRequest,
39    ) -> Result<MarketMoversResponse> {
40        req.validate()
41            .map_err(|message| DhanError::InvalidArgument(message.into()))?;
42        self.post("/v2/data/marketmovers", req).await
43    }
44
45    /// Fetch selected company overview, ratio, or shareholding sections.
46    ///
47    /// **Endpoint:** `POST /v2/data/companyinfo`
48    pub async fn get_company_info(&self, req: &CompanyInfoRequest) -> Result<CompanyInfoResponse> {
49        req.validate()
50            .map_err(|message| DhanError::InvalidArgument(message.into()))?;
51        self.post("/v2/data/companyinfo", req).await
52    }
53}