dceapi_rs/services/
market.rs

1//! Market service for quote and market data APIs.
2
3use crate::error::Result;
4use crate::http::{BaseClient, RequestOptions};
5use crate::models::{
6    ContractMonthMaxOpeni, ContractMonthMaxPrice, ContractMonthMaxRequest,
7    ContractMonthMaxTurnover, ContractMonthMaxVolume, DivisionPriceInfo, DivisionPriceInfoRequest,
8    Quote, QuotesRequest, RiseFallEvent, RiseFallEventRequest,
9    WarehouseReceipt, WarehouseReceiptRequest,
10};
11
12/// API endpoint for night quotes.
13const PATH_GET_NIGHT_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/tiNightQuotes";
14
15/// API endpoint for day quotes.
16const PATH_GET_DAY_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/dayQuotes";
17
18/// API endpoint for week quotes.
19const PATH_GET_WEEK_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/weekQuotes";
20
21/// API endpoint for month quotes.
22const PATH_GET_MONTH_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/monthQuotes";
23
24/// API endpoint for contract monthly max statistics.
25const PATH_GET_CONTRACT_MONTH_MAX: &str = "/dceapi/forward/publicweb/phasestat/contractMonthMax";
26
27/// API endpoint for rise/fall event (trading limit) query.
28const PATH_GET_RISE_FALL_EVENT: &str = "/dceapi/forward/publicweb/phasestat/riseFallEvent";
29
30/// API endpoint for division price info.
31const PATH_GET_DIVISION_PRICE_INFO: &str = "/dceapi/forward/publicweb/dailystat/divisionPriceInfo";
32
33/// API endpoint for warehouse receipt (daily report).
34const PATH_GET_WAREHOUSE_RECEIPT: &str = "/dceapi/forward/publicweb/dailystat/wbillWeeklyQuotes";
35
36/// Market service for accessing quote and market data.
37#[derive(Debug, Clone)]
38pub struct MarketService {
39    client: BaseClient,
40}
41
42impl MarketService {
43    /// Create a new market service.
44    pub fn new(client: BaseClient) -> Self {
45        MarketService { client }
46    }
47
48    /// Get night session quotes.
49    ///
50    /// # Arguments
51    /// * `req` - Request with variety and trade date
52    /// * `opts` - Optional request options
53    pub async fn get_night_quotes(
54        &self,
55        req: &QuotesRequest,
56        opts: Option<RequestOptions>,
57    ) -> Result<Vec<Quote>> {
58        self.client.do_post(PATH_GET_NIGHT_QUOTES, req, opts).await
59    }
60
61    /// Get day session quotes.
62    ///
63    /// # Arguments
64    /// * `req` - Request with variety and trade date
65    /// * `opts` - Optional request options
66    pub async fn get_day_quotes(
67        &self,
68        req: &QuotesRequest,
69        opts: Option<RequestOptions>,
70    ) -> Result<Vec<Quote>> {
71        self.client.do_post(PATH_GET_DAY_QUOTES, req, opts).await
72    }
73
74    /// Get weekly quotes.
75    ///
76    /// # Arguments
77    /// * `req` - Request with variety and trade date (same as day quotes)
78    /// * `opts` - Optional request options
79    pub async fn get_week_quotes(
80        &self,
81        req: &QuotesRequest,
82        opts: Option<RequestOptions>,
83    ) -> Result<Vec<Quote>> {
84        self.client.do_post(PATH_GET_WEEK_QUOTES, req, opts).await
85    }
86
87    /// Get monthly quotes.
88    ///
89    /// # Arguments
90    /// * `req` - Request with variety and trade date (same as day quotes)
91    /// * `opts` - Optional request options
92    pub async fn get_month_quotes(
93        &self,
94        req: &QuotesRequest,
95        opts: Option<RequestOptions>,
96    ) -> Result<Vec<Quote>> {
97        self.client.do_post(PATH_GET_MONTH_QUOTES, req, opts).await
98    }
99
100    /// Get contract monthly max statistics (volume).
101    ///
102    /// # Arguments
103    /// * `req` - Request with stat_content="0" for volume statistics
104    /// * `opts` - Optional request options
105    pub async fn get_contract_month_max_volume(
106        &self,
107        req: &ContractMonthMaxRequest,
108        opts: Option<RequestOptions>,
109    ) -> Result<Vec<ContractMonthMaxVolume>> {
110        self.client
111            .do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
112            .await
113    }
114
115    /// Get contract monthly max statistics (turnover).
116    ///
117    /// # Arguments
118    /// * `req` - Request with stat_content="1" for turnover statistics
119    /// * `opts` - Optional request options
120    pub async fn get_contract_month_max_turnover(
121        &self,
122        req: &ContractMonthMaxRequest,
123        opts: Option<RequestOptions>,
124    ) -> Result<Vec<ContractMonthMaxTurnover>> {
125        self.client
126            .do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
127            .await
128    }
129
130    /// Get contract monthly max statistics (open interest).
131    ///
132    /// # Arguments
133    /// * `req` - Request with stat_content="2" for open interest statistics
134    /// * `opts` - Optional request options
135    pub async fn get_contract_month_max_openi(
136        &self,
137        req: &ContractMonthMaxRequest,
138        opts: Option<RequestOptions>,
139    ) -> Result<Vec<ContractMonthMaxOpeni>> {
140        self.client
141            .do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
142            .await
143    }
144
145    /// Get contract monthly max statistics (price).
146    ///
147    /// # Arguments
148    /// * `req` - Request with stat_content="3" for price statistics
149    /// * `opts` - Optional request options
150    pub async fn get_contract_month_max_price(
151        &self,
152        req: &ContractMonthMaxRequest,
153        opts: Option<RequestOptions>,
154    ) -> Result<Vec<ContractMonthMaxPrice>> {
155        self.client
156            .do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
157            .await
158    }
159
160    /// Get rise/fall events (trading limit occurrences).
161    ///
162    /// # Arguments
163    /// * `req` - Request with date range and variety
164    /// * `opts` - Optional request options
165    pub async fn get_rise_fall_event(
166        &self,
167        req: &RiseFallEventRequest,
168        opts: Option<RequestOptions>,
169    ) -> Result<Vec<RiseFallEvent>> {
170        self.client
171            .do_post(PATH_GET_RISE_FALL_EVENT, req, opts)
172            .await
173    }
174
175    /// Get division price information (settlement reference price by time).
176    ///
177    /// # Arguments
178    /// * `req` - Request with variety, trade date, and trade type
179    /// * `opts` - Optional request options
180    pub async fn get_division_price_info(
181        &self,
182        req: &DivisionPriceInfoRequest,
183        opts: Option<RequestOptions>,
184    ) -> Result<Vec<DivisionPriceInfo>> {
185        self.client
186            .do_post(PATH_GET_DIVISION_PRICE_INFO, req, opts)
187            .await
188    }
189
190    /// Get warehouse receipt daily report.
191    ///
192    /// # Arguments
193    /// * `req` - Request with variety and trade date
194    /// * `opts` - Optional request options
195    pub async fn get_warehouse_receipt(
196        &self,
197        req: &WarehouseReceiptRequest,
198        opts: Option<RequestOptions>,
199    ) -> Result<WarehouseReceipt> {
200        self.client
201            .do_post(PATH_GET_WAREHOUSE_RECEIPT, req, opts)
202            .await
203    }
204}