use crate::error::Result;
use crate::http::{BaseClient, RequestOptions};
use crate::models::{
ContractMonthMaxOpeni, ContractMonthMaxPrice, ContractMonthMaxRequest,
ContractMonthMaxTurnover, ContractMonthMaxVolume, DivisionPriceInfo, DivisionPriceInfoRequest,
Quote, QuotesRequest, RiseFallEvent, RiseFallEventRequest,
WarehouseReceipt, WarehouseReceiptRequest,
};
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_MONTH_MAX: &str = "/dceapi/forward/publicweb/phasestat/contractMonthMax";
const PATH_GET_RISE_FALL_EVENT: &str = "/dceapi/forward/publicweb/phasestat/riseFallEvent";
const PATH_GET_DIVISION_PRICE_INFO: &str = "/dceapi/forward/publicweb/dailystat/divisionPriceInfo";
const PATH_GET_WAREHOUSE_RECEIPT: &str = "/dceapi/forward/publicweb/dailystat/wbillWeeklyQuotes";
#[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: &QuotesRequest,
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: &QuotesRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<Quote>> {
self.client.do_post(PATH_GET_MONTH_QUOTES, req, opts).await
}
pub async fn get_contract_month_max_volume(
&self,
req: &ContractMonthMaxRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<ContractMonthMaxVolume>> {
self.client
.do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
.await
}
pub async fn get_contract_month_max_turnover(
&self,
req: &ContractMonthMaxRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<ContractMonthMaxTurnover>> {
self.client
.do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
.await
}
pub async fn get_contract_month_max_openi(
&self,
req: &ContractMonthMaxRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<ContractMonthMaxOpeni>> {
self.client
.do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
.await
}
pub async fn get_contract_month_max_price(
&self,
req: &ContractMonthMaxRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<ContractMonthMaxPrice>> {
self.client
.do_post(PATH_GET_CONTRACT_MONTH_MAX, req, opts)
.await
}
pub async fn get_rise_fall_event(
&self,
req: &RiseFallEventRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<RiseFallEvent>> {
self.client
.do_post(PATH_GET_RISE_FALL_EVENT, req, opts)
.await
}
pub async fn get_division_price_info(
&self,
req: &DivisionPriceInfoRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<DivisionPriceInfo>> {
self.client
.do_post(PATH_GET_DIVISION_PRICE_INFO, req, opts)
.await
}
pub async fn get_warehouse_receipt(
&self,
req: &WarehouseReceiptRequest,
opts: Option<RequestOptions>,
) -> Result<WarehouseReceipt> {
self.client
.do_post(PATH_GET_WAREHOUSE_RECEIPT, req, opts)
.await
}
}