dceapi_rs/services/
market.rs1use 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
12const PATH_GET_NIGHT_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/tiNightQuotes";
14
15const PATH_GET_DAY_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/dayQuotes";
17
18const PATH_GET_WEEK_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/weekQuotes";
20
21const PATH_GET_MONTH_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/monthQuotes";
23
24const PATH_GET_CONTRACT_MONTH_MAX: &str = "/dceapi/forward/publicweb/phasestat/contractMonthMax";
26
27const PATH_GET_RISE_FALL_EVENT: &str = "/dceapi/forward/publicweb/phasestat/riseFallEvent";
29
30const PATH_GET_DIVISION_PRICE_INFO: &str = "/dceapi/forward/publicweb/dailystat/divisionPriceInfo";
32
33const PATH_GET_WAREHOUSE_RECEIPT: &str = "/dceapi/forward/publicweb/dailystat/wbillWeeklyQuotes";
35
36#[derive(Debug, Clone)]
38pub struct MarketService {
39 client: BaseClient,
40}
41
42impl MarketService {
43 pub fn new(client: BaseClient) -> Self {
45 MarketService { client }
46 }
47
48 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 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 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 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 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 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 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 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 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 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 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}