dceapi_rs/services/
common.rs

1//! Common service for general API endpoints.
2
3use crate::error::Result;
4use crate::http::{BaseClient, RequestOptions};
5use crate::models::{TradeDate, Variety};
6
7/// API endpoint for current trade date.
8const PATH_GET_CURR_TRADE_DATE: &str = "/dceapi/forward/publicweb/maxTradeDate";
9
10/// API endpoint for variety list.
11const PATH_GET_VARIETY_LIST: &str = "/dceapi/forward/publicweb/variety";
12
13/// Common service for general operations.
14#[derive(Debug, Clone)]
15pub struct CommonService {
16    client: BaseClient,
17}
18
19impl CommonService {
20    /// Create a new common service.
21    pub fn new(client: BaseClient) -> Self {
22        CommonService { client }
23    }
24
25    /// Get the current (latest) trade date.
26    ///
27    /// # Arguments
28    /// * `opts` - Optional request options
29    pub async fn get_curr_trade_date(&self, opts: Option<RequestOptions>) -> Result<TradeDate> {
30        self.client.do_get(PATH_GET_CURR_TRADE_DATE, opts).await
31    }
32
33    /// Get the list of available varieties (commodities).
34    ///
35    /// # Arguments
36    /// * `opts` - Optional request options (use trade_type to filter futures/options)
37    pub async fn get_variety_list(&self, opts: Option<RequestOptions>) -> Result<Vec<Variety>> {
38        self.client.do_get(PATH_GET_VARIETY_LIST, opts).await
39    }
40}