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, MainSeriesInfo, MainSeriesInfoRequest, MarginArbiPerfPara,
10 MarginArbiPerfParaRequest, NewContractInfo, NewContractInfoRequest, TradeParam, TradingParam,
11 TradingParamRequest,
12};
13
14const PATH_GET_DAY_TRADE_PARAM: &str = "/dceapi/forward/publicweb/tradepara/dayTradPara";
16
17const PATH_GET_MONTH_TRADE_PARAM: &str = "/dceapi/forward/publicweb/tradepara/monthTradPara";
19
20const PATH_GET_CONTRACT_INFO: &str = "/dceapi/forward/publicweb/tradepara/contractInfo";
22
23const PATH_GET_ARBITRAGE_CONTRACT: &str = "/dceapi/forward/publicweb/tradepara/arbitrageContract";
25
26const PATH_GET_TRADING_PARAM: &str = "/dceapi/forward/publicweb/tradepara/tradingParam";
28
29const PATH_GET_MARGIN_ARBI_PERF_PARA: &str =
31 "/dceapi/forward/publicweb/tradepara/marginArbiPerfPara";
32
33const PATH_GET_NEW_CONTRACT_INFO: &str = "/dceapi/forward/publicweb/tradepara/newContractInfo";
35
36const PATH_GET_MAIN_SERIES_INFO: &str = "/dceapi/forward/publicweb/tradepara/mainSeriesInfo";
38
39#[derive(Debug, Clone)]
41pub struct TradeService {
42 client: BaseClient,
43}
44
45impl TradeService {
46 pub fn new(client: BaseClient) -> Self {
48 TradeService { client }
49 }
50
51 pub async fn get_day_trade_param(
59 &self,
60 req: &DayTradeParamRequest,
61 opts: Option<RequestOptions>,
62 ) -> Result<Vec<TradeParam>> {
63 self.client
64 .do_post(PATH_GET_DAY_TRADE_PARAM, req, opts)
65 .await
66 }
67
68 pub async fn get_month_trade_param(
73 &self,
74 opts: Option<RequestOptions>,
75 ) -> Result<HashMap<String, serde_json::Value>> {
76 #[derive(serde::Serialize)]
77 struct EmptyRequest {}
78
79 self.client
80 .do_post(PATH_GET_MONTH_TRADE_PARAM, &EmptyRequest {}, opts)
81 .await
82 }
83
84 pub async fn get_contract_info(
92 &self,
93 req: &ContractInfoRequest,
94 opts: Option<RequestOptions>,
95 ) -> Result<Vec<ContractInfo>> {
96 self.client.do_post(PATH_GET_CONTRACT_INFO, req, opts).await
97 }
98
99 pub async fn get_arbitrage_contract(
107 &self,
108 lang: Option<&str>,
109 opts: Option<RequestOptions>,
110 ) -> Result<Vec<ArbitrageContract>> {
111 let req = ArbitrageContractRequest {
112 lang: lang.unwrap_or("zh").to_string(),
113 };
114 self.client
115 .do_post(PATH_GET_ARBITRAGE_CONTRACT, &req, opts)
116 .await
117 }
118
119 pub async fn get_trading_param(
127 &self,
128 lang: Option<&str>,
129 opts: Option<RequestOptions>,
130 ) -> Result<Vec<TradingParam>> {
131 let req = TradingParamRequest {
132 lang: lang.unwrap_or("zh").to_string(),
133 };
134 self.client
135 .do_post(PATH_GET_TRADING_PARAM, &req, opts)
136 .await
137 }
138
139 pub async fn get_margin_arbi_perf_para(
147 &self,
148 req: &MarginArbiPerfParaRequest,
149 opts: Option<RequestOptions>,
150 ) -> Result<Vec<MarginArbiPerfPara>> {
151 self.client
152 .do_post(PATH_GET_MARGIN_ARBI_PERF_PARA, req, opts)
153 .await
154 }
155
156 pub async fn get_new_contract_info(
164 &self,
165 req: &NewContractInfoRequest,
166 opts: Option<RequestOptions>,
167 ) -> Result<Vec<NewContractInfo>> {
168 self.client
169 .do_post(PATH_GET_NEW_CONTRACT_INFO, req, opts)
170 .await
171 }
172
173 pub async fn get_main_series_info(
181 &self,
182 req: &MainSeriesInfoRequest,
183 opts: Option<RequestOptions>,
184 ) -> Result<Vec<MainSeriesInfo>> {
185 self.client
186 .do_post(PATH_GET_MAIN_SERIES_INFO, req, opts)
187 .await
188 }
189}