1use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::fiat::*;
6use crate::models::AccountType;
7
8impl BybitClient {
9 pub async fn apply_quote(&self, params: ApplyQuoteParams) -> Result<ApplyQuoteResponse> {
11 self.post("/v5/fiat/quote-apply", ¶ms).await
12 }
13
14 pub async fn confirm_quote(&self, params: ConfirmQuoteParams) -> Result<ConfirmQuoteResponse> {
16 self.post("/v5/fiat/trade-execute", ¶ms).await
17 }
18
19 pub async fn get_p2p_personal_info(&self) -> Result<serde_json::Value> {
26 self.post("/v5/p2p/user/personal/info", &serde_json::json!({}))
27 .await
28 }
29
30 pub async fn get_ads(&self, params: GetAdsParams) -> Result<GetAdsResponse> {
32 self.post("/v5/p2p/item/online", ¶ms).await
33 }
34
35 pub async fn get_all_orders(&self, params: serde_json::Value) -> Result<serde_json::Value> {
43 self.post("/v5/p2p/order/simplifyList", ¶ms).await
44 }
45
46 pub async fn get_chat_messages(
48 &self,
49 params: GetChatMessagesParams,
50 ) -> Result<GetChatMessagesResponse> {
51 self.post("/v5/p2p/order/message/listpage", ¶ms).await
52 }
53
54 pub async fn get_coin_balance(
56 &self,
57 account_type: AccountType,
58 member_id: Option<&str>,
59 coin: Option<&str>,
60 with_bonus: Option<i64>,
61 ) -> Result<GetCoinBalanceResponse> {
62 let account_type_str = account_type.to_string();
63 let with_bonus_str = with_bonus.map(|v| v.to_string());
64 let mut params = vec![("accountType", account_type_str.as_str())];
65 if let Some(m) = member_id {
66 params.push(("memberId", m));
67 }
68 if let Some(c) = coin {
69 params.push(("coin", c));
70 }
71 if let Some(ref wb) = with_bonus_str {
72 params.push(("withBonus", wb.as_str()));
73 }
74 self.get("/v5/asset/transfer/query-account-coins-balance", ¶ms)
75 .await
76 }
77
78 pub async fn get_counterparty_user_info(
80 &self,
81 params: GetCounterpartyUserInfoParams,
82 ) -> Result<GetCounterpartyUserInfoResponse> {
83 self.post("/v5/p2p/user/order/personal/info", ¶ms).await
84 }
85
86 pub async fn get_my_ad_details(
88 &self,
89 params: GetMyAdDetailsParams,
90 ) -> Result<GetMyAdDetailsResponse> {
91 self.post("/v5/p2p/item/info", ¶ms).await
92 }
93
94 pub async fn get_my_ads(&self, params: GetMyAdsParams) -> Result<GetMyAdsResponse> {
96 self.post("/v5/p2p/item/personal/list", ¶ms).await
97 }
98
99 pub async fn get_order_detail(
101 &self,
102 params: GetOrderDetailParams,
103 ) -> Result<GetOrderDetailResponse> {
104 self.post("/v5/p2p/order/info", ¶ms).await
105 }
106
107 pub async fn get_pending_orders(
109 &self,
110 params: GetPendingOrdersParams,
111 ) -> Result<GetPendingOrdersResponse> {
112 self.post("/v5/p2p/order/pending/simplifyList", ¶ms)
113 .await
114 }
115
116 pub async fn get_reference_price(
118 &self,
119 symbol: &str,
120 payment_method: Option<&str>,
121 ) -> Result<GetReferencePriceResponse> {
122 let mut params = vec![("symbol", symbol)];
123 if let Some(pm) = payment_method {
124 params.push(("paymentMethod", pm));
125 }
126 self.get("/v5/fiat/reference-price", ¶ms).await
127 }
128
129 pub async fn get_user_payment(&self) -> Result<GetUserPaymentResponse> {
131 self.post("/v5/p2p/user/payment/list", &serde_json::json!({}))
132 .await
133 }
134
135 pub async fn mark_order_as_paid(
137 &self,
138 params: MarkOrderAsPaidParams,
139 ) -> Result<MarkOrderAsPaidResponse> {
140 self.post("/v5/p2p/order/pay", ¶ms).await
141 }
142
143 pub async fn post_ad(&self, params: PostAdParams) -> Result<PostAdResponse> {
145 self.post("/v5/p2p/item/create", ¶ms).await
146 }
147
148 pub async fn query_balance(
150 &self,
151 account_category: Option<&str>,
152 currency: Option<&str>,
153 ) -> Result<QueryBalanceResponse> {
154 let mut params = vec![];
155 if let Some(ac) = account_category {
156 params.push(("accountCategory", ac));
157 }
158 if let Some(c) = currency {
159 params.push(("currency", c));
160 }
161 self.get("/v5/fiat/balance-query", ¶ms).await
162 }
163
164 pub async fn query_coin_list(&self, side: Option<i64>) -> Result<QueryCoinListResponse> {
166 let side_str = side.map(|v| v.to_string());
167 let mut params = vec![];
168 if let Some(ref s) = side_str {
169 params.push(("side", s.as_str()));
170 }
171 self.get("/v5/fiat/query-coin-list", ¶ms).await
172 }
173
174 pub async fn query_funding_detail_api(
176 &self,
177 create_time_from: Option<&str>,
178 create_time_to: Option<&str>,
179 limit: Option<&str>,
180 cursor: Option<&str>,
181 ) -> Result<QueryFundingDetailApiResponse> {
182 let mut params = vec![];
183 if let Some(v) = create_time_from {
184 params.push(("createTimeFrom", v));
185 }
186 if let Some(v) = create_time_to {
187 params.push(("createTimeTo", v));
188 }
189 if let Some(v) = limit {
190 params.push(("limit", v));
191 }
192 if let Some(v) = cursor {
193 params.push(("cursor", v));
194 }
195 self.get("/v5/asset/fundinghistory", ¶ms).await
196 }
197
198 pub async fn query_trade(
200 &self,
201 trade_no: Option<&str>,
202 merchant_request_id: Option<&str>,
203 ) -> Result<QueryTradeResponse> {
204 let mut params = vec![];
205 if let Some(v) = trade_no {
206 params.push(("tradeNo", v));
207 }
208 if let Some(v) = merchant_request_id {
209 params.push(("merchantRequestId", v));
210 }
211 self.get("/v5/fiat/trade-query", ¶ms).await
212 }
213
214 pub async fn query_trade_history(
216 &self,
217 index: Option<i64>,
218 limit: Option<i64>,
219 start_time: Option<&str>,
220 end_time: Option<&str>,
221 ) -> Result<QueryTradeHistoryResponse> {
222 let index_str = index.map(|v| v.to_string());
223 let limit_str = limit.map(|v| v.to_string());
224 let mut params = vec![];
225 if let Some(ref v) = index_str {
226 params.push(("index", v.as_str()));
227 }
228 if let Some(ref v) = limit_str {
229 params.push(("limit", v.as_str()));
230 }
231 if let Some(v) = start_time {
232 params.push(("startTime", v));
233 }
234 if let Some(v) = end_time {
235 params.push(("endTime", v));
236 }
237 self.get("/v5/fiat/query-trade-history", ¶ms).await
238 }
239
240 pub async fn release_assets(&self, params: ReleaseAssetsParams) -> Result<serde_json::Value> {
245 self.post("/v5/p2p/order/finish", ¶ms).await
246 }
247
248 pub async fn remove_ad(&self, params: RemoveAdParams) -> Result<serde_json::Value> {
253 self.post("/v5/p2p/item/cancel", ¶ms).await
254 }
255
256 pub async fn send_chat_message(
261 &self,
262 params: SendChatMessageParams,
263 ) -> Result<serde_json::Value> {
264 self.post("/v5/p2p/order/message/send", ¶ms).await
265 }
266
267 pub async fn update_ad(&self, params: UpdateAdParams) -> Result<UpdateAdResponse> {
269 self.post("/v5/p2p/item/update", ¶ms).await
270 }
271
272 pub async fn upload_chat_file(
274 &self,
275 params: UploadChatFileParams,
276 ) -> Result<UploadChatFileResponse> {
277 self.post("/v5/p2p/oss/upload_file", ¶ms).await
278 }
279}