Skip to main content

bybit_api/api/
fiat.rs

1//! Fiat API endpoints.
2
3use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::fiat::*;
6use crate::models::AccountType;
7
8impl BybitClient {
9    /// Request a Quote.
10    pub async fn apply_quote(&self, params: ApplyQuoteParams) -> Result<ApplyQuoteResponse> {
11        self.post("/v5/fiat/quote-apply", &params).await
12    }
13
14    /// Confirm Quote and Execute Trade.
15    pub async fn confirm_quote(&self, params: ConfirmQuoteParams) -> Result<ConfirmQuoteResponse> {
16        self.post("/v5/fiat/trade-execute", &params).await
17    }
18
19    /// Get Account Information.
20    // FIXME(gen-sdk-rust): plan agent referenced GetAccountInfoResponse without
21    // emitting the type to models/fiat.rs. Falling back to serde_json::Value.
22    // FIXME(typed-signature): falls back to `serde_json::Value` because the
23    // OpenAPI spec referenced a response/request type that gen-sdk-rust could
24    // not auto-resolve. Replace with a typed struct in a follow-up PR.
25    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    /// Get Ads.
31    pub async fn get_ads(&self, params: GetAdsParams) -> Result<GetAdsResponse> {
32        self.post("/v5/p2p/item/online", &params).await
33    }
34
35    /// Get All Orders.
36    // FIXME(gen-sdk-rust): plan agent referenced GetAllOrdersParams +
37    // GetAllOrdersResponse without emitting the types to models/fiat.rs.
38    // Falling back to serde_json::Value for both.
39    // FIXME(typed-signature): falls back to `serde_json::Value` because the
40    // OpenAPI spec referenced a response/request type that gen-sdk-rust could
41    // not auto-resolve. Replace with a typed struct in a follow-up PR.
42    pub async fn get_all_orders(&self, params: serde_json::Value) -> Result<serde_json::Value> {
43        self.post("/v5/p2p/order/simplifyList", &params).await
44    }
45
46    /// Get Chat Message.
47    pub async fn get_chat_messages(
48        &self,
49        params: GetChatMessagesParams,
50    ) -> Result<GetChatMessagesResponse> {
51        self.post("/v5/p2p/order/message/listpage", &params).await
52    }
53
54    /// Get Coin Balance.
55    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", &params)
75            .await
76    }
77
78    /// Get Counterparty User Info.
79    pub async fn get_counterparty_user_info(
80        &self,
81        params: GetCounterpartyUserInfoParams,
82    ) -> Result<GetCounterpartyUserInfoResponse> {
83        self.post("/v5/p2p/user/order/personal/info", &params).await
84    }
85
86    /// Get My Ad Details.
87    pub async fn get_my_ad_details(
88        &self,
89        params: GetMyAdDetailsParams,
90    ) -> Result<GetMyAdDetailsResponse> {
91        self.post("/v5/p2p/item/info", &params).await
92    }
93
94    /// Get My Ads.
95    pub async fn get_my_ads(&self, params: GetMyAdsParams) -> Result<GetMyAdsResponse> {
96        self.post("/v5/p2p/item/personal/list", &params).await
97    }
98
99    /// Get Order Detail.
100    pub async fn get_order_detail(
101        &self,
102        params: GetOrderDetailParams,
103    ) -> Result<GetOrderDetailResponse> {
104        self.post("/v5/p2p/order/info", &params).await
105    }
106
107    /// Get Pending Orders.
108    pub async fn get_pending_orders(
109        &self,
110        params: GetPendingOrdersParams,
111    ) -> Result<GetPendingOrdersResponse> {
112        self.post("/v5/p2p/order/pending/simplifyList", &params)
113            .await
114    }
115
116    /// Get Reference Price.
117    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", &params).await
127    }
128
129    /// Get User Payment.
130    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    /// Mark Order as Paid.
136    pub async fn mark_order_as_paid(
137        &self,
138        params: MarkOrderAsPaidParams,
139    ) -> Result<MarkOrderAsPaidResponse> {
140        self.post("/v5/p2p/order/pay", &params).await
141    }
142
143    /// Post Ad.
144    pub async fn post_ad(&self, params: PostAdParams) -> Result<PostAdResponse> {
145        self.post("/v5/p2p/item/create", &params).await
146    }
147
148    /// Query Account Balance.
149    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", &params).await
162    }
163
164    /// Get Trading Pairs.
165    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", &params).await
172    }
173
174    /// Get Funding History.
175    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", &params).await
196    }
197
198    /// Query Trade Status.
199    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", &params).await
212    }
213
214    /// Query Trade History.
215    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", &params).await
238    }
239
240    /// Release Assets.
241    // FIXME(typed-signature): falls back to `serde_json::Value` because the
242    // OpenAPI spec referenced a response/request type that gen-sdk-rust could
243    // not auto-resolve. Replace with a typed struct in a follow-up PR.
244    pub async fn release_assets(&self, params: ReleaseAssetsParams) -> Result<serde_json::Value> {
245        self.post("/v5/p2p/order/finish", &params).await
246    }
247
248    /// Remove Ad.
249    // FIXME(typed-signature): falls back to `serde_json::Value` because the
250    // OpenAPI spec referenced a response/request type that gen-sdk-rust could
251    // not auto-resolve. Replace with a typed struct in a follow-up PR.
252    pub async fn remove_ad(&self, params: RemoveAdParams) -> Result<serde_json::Value> {
253        self.post("/v5/p2p/item/cancel", &params).await
254    }
255
256    /// Send Chat Message.
257    // FIXME(typed-signature): falls back to `serde_json::Value` because the
258    // OpenAPI spec referenced a response/request type that gen-sdk-rust could
259    // not auto-resolve. Replace with a typed struct in a follow-up PR.
260    pub async fn send_chat_message(
261        &self,
262        params: SendChatMessageParams,
263    ) -> Result<serde_json::Value> {
264        self.post("/v5/p2p/order/message/send", &params).await
265    }
266
267    /// Update / Relist Ad.
268    pub async fn update_ad(&self, params: UpdateAdParams) -> Result<UpdateAdResponse> {
269        self.post("/v5/p2p/item/update", &params).await
270    }
271
272    /// Upload Chat File.
273    pub async fn upload_chat_file(
274        &self,
275        params: UploadChatFileParams,
276    ) -> Result<UploadChatFileResponse> {
277        self.post("/v5/p2p/oss/upload_file", &params).await
278    }
279}