dceapi_rs/services/
market.rs1use crate::error::{Error, Result};
4use crate::http::{BaseClient, RequestOptions};
5use crate::models::{
6 ContractStat, ContractStatRequest, MonthQuotesRequest, Quote, QuotesRequest, WeekQuotesRequest,
7};
8
9const PATH_GET_NIGHT_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/tiNightQuotes";
11
12const PATH_GET_DAY_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/dayQuotes";
14
15const PATH_GET_WEEK_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/weekQuotes";
17
18const PATH_GET_MONTH_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/monthQuotes";
20
21const PATH_GET_CONTRACT_STAT: &str = "/dceapi/forward/publicweb/dailystat/contractStat";
23
24#[derive(Debug, Clone)]
26pub struct MarketService {
27 client: BaseClient,
28}
29
30impl MarketService {
31 pub fn new(client: BaseClient) -> Self {
33 MarketService { client }
34 }
35
36 pub async fn get_night_quotes(
42 &self,
43 req: &QuotesRequest,
44 opts: Option<RequestOptions>,
45 ) -> Result<Vec<Quote>> {
46 self.client.do_post(PATH_GET_NIGHT_QUOTES, req, opts).await
47 }
48
49 pub async fn get_day_quotes(
55 &self,
56 req: &QuotesRequest,
57 opts: Option<RequestOptions>,
58 ) -> Result<Vec<Quote>> {
59 self.client.do_post(PATH_GET_DAY_QUOTES, req, opts).await
60 }
61
62 pub async fn get_week_quotes(
68 &self,
69 req: &WeekQuotesRequest,
70 opts: Option<RequestOptions>,
71 ) -> Result<Vec<Quote>> {
72 self.client.do_post(PATH_GET_WEEK_QUOTES, req, opts).await
73 }
74
75 pub async fn get_month_quotes(
81 &self,
82 req: &MonthQuotesRequest,
83 opts: Option<RequestOptions>,
84 ) -> Result<Vec<Quote>> {
85 self.client.do_post(PATH_GET_MONTH_QUOTES, req, opts).await
86 }
87
88 pub async fn get_contract_stat(
94 &self,
95 req: &ContractStatRequest,
96 opts: Option<RequestOptions>,
97 ) -> Result<ContractStat> {
98 if req.contract_code.is_empty() {
99 return Err(Error::validation("contract_code", "contract_code is required"));
100 }
101 self.client.do_post(PATH_GET_CONTRACT_STAT, req, opts).await
102 }
103}