use crate::error::Result;
use crate::http::{BaseClient, RequestOptions};
use crate::models::{TradeDate, Variety, VarietyMonthYearStat, VarietyMonthYearStatRequest};
const PATH_GET_CURR_TRADE_DATE: &str = "/dceapi/forward/publicweb/maxTradeDate";
const PATH_GET_VARIETY_LIST: &str = "/dceapi/forward/publicweb/variety";
const PATH_GET_VARIETY_MONTH_YEAR_STAT: &str =
"/dceapi/forward/publicweb/phasestat/varietyMonthYearStat";
#[derive(Debug, Clone)]
pub struct CommonService {
client: BaseClient,
}
impl CommonService {
pub fn new(client: BaseClient) -> Self {
CommonService { client }
}
pub async fn get_curr_trade_date(&self, opts: Option<RequestOptions>) -> Result<TradeDate> {
self.client.do_get(PATH_GET_CURR_TRADE_DATE, opts).await
}
pub async fn get_variety_list(&self, opts: Option<RequestOptions>) -> Result<Vec<Variety>> {
self.client.do_get(PATH_GET_VARIETY_LIST, opts).await
}
pub async fn get_variety_month_year_stat(
&self,
req: &VarietyMonthYearStatRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<VarietyMonthYearStat>> {
self.client
.do_post(PATH_GET_VARIETY_MONTH_YEAR_STAT, req, opts)
.await
}
}