use crate::error::{Error, Result};
use crate::http::{BaseClient, RequestOptions};
use crate::models::{
ContractStat, ContractStatRequest, MonthQuotesRequest, Quote, QuotesRequest, WeekQuotesRequest,
};
const PATH_GET_NIGHT_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/tiNightQuotes";
const PATH_GET_DAY_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/dayQuotes";
const PATH_GET_WEEK_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/weekQuotes";
const PATH_GET_MONTH_QUOTES: &str = "/dceapi/forward/publicweb/dailystat/monthQuotes";
const PATH_GET_CONTRACT_STAT: &str = "/dceapi/forward/publicweb/dailystat/contractStat";
#[derive(Debug, Clone)]
pub struct MarketService {
client: BaseClient,
}
impl MarketService {
pub fn new(client: BaseClient) -> Self {
MarketService { client }
}
pub async fn get_night_quotes(
&self,
req: &QuotesRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<Quote>> {
self.client.do_post(PATH_GET_NIGHT_QUOTES, req, opts).await
}
pub async fn get_day_quotes(
&self,
req: &QuotesRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<Quote>> {
self.client.do_post(PATH_GET_DAY_QUOTES, req, opts).await
}
pub async fn get_week_quotes(
&self,
req: &WeekQuotesRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<Quote>> {
self.client.do_post(PATH_GET_WEEK_QUOTES, req, opts).await
}
pub async fn get_month_quotes(
&self,
req: &MonthQuotesRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<Quote>> {
self.client.do_post(PATH_GET_MONTH_QUOTES, req, opts).await
}
pub async fn get_contract_stat(
&self,
req: &ContractStatRequest,
opts: Option<RequestOptions>,
) -> Result<ContractStat> {
if req.contract_code.is_empty() {
return Err(Error::validation("contract_code", "contract_code is required"));
}
self.client.do_post(PATH_GET_CONTRACT_STAT, req, opts).await
}
}