dceapi_rs/services/
trade.rs1use std::collections::HashMap;
4
5use crate::error::Result;
6use crate::http::{BaseClient, RequestOptions};
7use crate::models::{
8 ArbitrageContract, ArbitrageContractRequest, ContractInfo, ContractInfoRequest,
9 DayTradeParamRequest, TradeParam,
10};
11
12const PATH_GET_DAY_TRADE_PARAM: &str = "/dceapi/forward/publicweb/tradepara/dayTradPara";
14
15const PATH_GET_MONTH_TRADE_PARAM: &str = "/dceapi/forward/publicweb/tradepara/monthTradPara";
17
18const PATH_GET_CONTRACT_INFO: &str = "/dceapi/forward/publicweb/tradepara/contractInfo";
20
21const PATH_GET_ARBITRAGE_CONTRACT: &str = "/dceapi/forward/publicweb/tradepara/arbitrageContract";
23
24#[derive(Debug, Clone)]
26pub struct TradeService {
27 client: BaseClient,
28}
29
30impl TradeService {
31 pub fn new(client: BaseClient) -> Self {
33 TradeService { client }
34 }
35
36 pub async fn get_day_trade_param(
44 &self,
45 req: &DayTradeParamRequest,
46 opts: Option<RequestOptions>,
47 ) -> Result<Vec<TradeParam>> {
48 self.client.do_post(PATH_GET_DAY_TRADE_PARAM, req, opts).await
49 }
50
51 pub async fn get_month_trade_param(
56 &self,
57 opts: Option<RequestOptions>,
58 ) -> Result<HashMap<String, serde_json::Value>> {
59 #[derive(serde::Serialize)]
60 struct EmptyRequest {}
61
62 self.client
63 .do_post(PATH_GET_MONTH_TRADE_PARAM, &EmptyRequest {}, opts)
64 .await
65 }
66
67 pub async fn get_contract_info(
75 &self,
76 req: &ContractInfoRequest,
77 opts: Option<RequestOptions>,
78 ) -> Result<Vec<ContractInfo>> {
79 self.client.do_post(PATH_GET_CONTRACT_INFO, req, opts).await
80 }
81
82 pub async fn get_arbitrage_contract(
90 &self,
91 lang: Option<&str>,
92 opts: Option<RequestOptions>,
93 ) -> Result<Vec<ArbitrageContract>> {
94 let req = ArbitrageContractRequest {
95 lang: lang.unwrap_or("zh").to_string(),
96 };
97 self.client.do_post(PATH_GET_ARBITRAGE_CONTRACT, &req, opts).await
98 }
99}