use std::collections::HashMap;
use crate::error::Result;
use crate::http::{BaseClient, RequestOptions};
use crate::models::{
ArbitrageContract, ArbitrageContractRequest, ContractInfo, ContractInfoRequest,
DayTradeParamRequest, TradeParam,
};
const PATH_GET_DAY_TRADE_PARAM: &str = "/dceapi/forward/publicweb/tradepara/dayTradPara";
const PATH_GET_MONTH_TRADE_PARAM: &str = "/dceapi/forward/publicweb/tradepara/monthTradPara";
const PATH_GET_CONTRACT_INFO: &str = "/dceapi/forward/publicweb/tradepara/contractInfo";
const PATH_GET_ARBITRAGE_CONTRACT: &str = "/dceapi/forward/publicweb/tradepara/arbitrageContract";
#[derive(Debug, Clone)]
pub struct TradeService {
client: BaseClient,
}
impl TradeService {
pub fn new(client: BaseClient) -> Self {
TradeService { client }
}
pub async fn get_day_trade_param(
&self,
req: &DayTradeParamRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<TradeParam>> {
self.client.do_post(PATH_GET_DAY_TRADE_PARAM, req, opts).await
}
pub async fn get_month_trade_param(
&self,
opts: Option<RequestOptions>,
) -> Result<HashMap<String, serde_json::Value>> {
#[derive(serde::Serialize)]
struct EmptyRequest {}
self.client
.do_post(PATH_GET_MONTH_TRADE_PARAM, &EmptyRequest {}, opts)
.await
}
pub async fn get_contract_info(
&self,
req: &ContractInfoRequest,
opts: Option<RequestOptions>,
) -> Result<Vec<ContractInfo>> {
self.client.do_post(PATH_GET_CONTRACT_INFO, req, opts).await
}
pub async fn get_arbitrage_contract(
&self,
lang: Option<&str>,
opts: Option<RequestOptions>,
) -> Result<Vec<ArbitrageContract>> {
let req = ArbitrageContractRequest {
lang: lang.unwrap_or("zh").to_string(),
};
self.client.do_post(PATH_GET_ARBITRAGE_CONTRACT, &req, opts).await
}
}