Skip to main content

bybit_api/api/
rfq.rs

1//! RFQ API endpoints.
2
3use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::rfq::*;
6
7impl BybitClient {
8    /// Accept Non-LP Quote.
9    pub async fn accept_non_lp_quote(
10        &self,
11        params: AcceptNonLpQuoteParams,
12    ) -> Result<AcceptNonLpQuoteResponse> {
13        self.post("/v5/rfq/accept-other-quote", &params).await
14    }
15
16    /// Cancel All Quotes.
17    pub async fn cancel_all_quotes(
18        &self,
19        params: CancelAllQuotesParams,
20    ) -> Result<CancelAllQuotesResponse> {
21        self.post("/v5/rfq/cancel-all-quotes", &params).await
22    }
23
24    /// Cancel All RFQs.
25    pub async fn cancel_all_rfqs(
26        &self,
27        params: CancelAllRfqsParams,
28    ) -> Result<CancelAllRfqsResponse> {
29        self.post("/v5/rfq/cancel-all-rfq", &params).await
30    }
31
32    /// Cancel Quote.
33    pub async fn cancel_quote(&self, params: CancelQuoteParams) -> Result<CancelQuoteResponse> {
34        self.post("/v5/rfq/cancel-quote", &params).await
35    }
36
37    /// Cancel RFQ.
38    pub async fn cancel_rfq(&self, params: CancelRfqParams) -> Result<CancelRfqResponse> {
39        self.post("/v5/rfq/cancel-rfq", &params).await
40    }
41
42    /// Create Quote.
43    pub async fn create_quote(&self, params: CreateQuoteParams) -> Result<CreateQuoteResponse> {
44        self.post("/v5/rfq/create-quote", &params).await
45    }
46
47    /// Create RFQ.
48    pub async fn create_rfq(&self, params: CreateRfqParams) -> Result<CreateRfqResponse> {
49        self.post("/v5/rfq/create-rfq", &params).await
50    }
51
52    /// Execute Quote.
53    pub async fn execute_quote(&self, params: ExecuteQuoteParams) -> Result<ExecuteQuoteResponse> {
54        self.post("/v5/rfq/execute-quote", &params).await
55    }
56
57    /// Get Public Trades.
58    pub async fn get_public_trades(
59        &self,
60        start_time: Option<i64>,
61        end_time: Option<i64>,
62        limit: Option<u32>,
63        cursor: Option<&str>,
64    ) -> Result<GetPublicTradesResponse> {
65        let start_time_str = start_time.map(|v| v.to_string());
66        let end_time_str = end_time.map(|v| v.to_string());
67        let limit_str = limit.map(|v| v.to_string());
68
69        let mut params: Vec<(&str, &str)> = vec![];
70        if let Some(ref s) = start_time_str {
71            params.push(("startTime", s.as_str()));
72        }
73        if let Some(ref s) = end_time_str {
74            params.push(("endTime", s.as_str()));
75        }
76        if let Some(ref s) = limit_str {
77            params.push(("limit", s.as_str()));
78        }
79        if let Some(c) = cursor {
80            params.push(("cursor", c));
81        }
82
83        self.get("/v5/rfq/public-trades", &params).await
84    }
85
86    /// Get Quotes.
87    ///
88    /// # Example
89    /// ```rust,no_run
90    /// # use bybit_api::{BybitClient, GetQuotesParams};
91    /// # async fn example() -> bybit_api::Result<()> {
92    /// let client = BybitClient::testnet("k", "s")?;
93    /// let quotes = client.get_quotes(GetQuotesParams {
94    ///     rfq_id: Some("xxx".into()),
95    ///     limit: Some(20),
96    ///     ..Default::default()
97    /// }).await?;
98    /// # Ok(())
99    /// # }
100    /// ```
101    pub async fn get_quotes(&self, p: GetQuotesParams) -> Result<GetQuotesResponse> {
102        let limit_str = p.limit.map(|v| v.to_string());
103        let mut params: Vec<(&str, &str)> = vec![];
104        if let Some(ref s) = p.rfq_id {
105            params.push(("rfqId", s.as_str()));
106        }
107        if let Some(ref s) = p.quote_id {
108            params.push(("quoteId", s.as_str()));
109        }
110        if let Some(ref s) = p.quote_link_id {
111            params.push(("quoteLinkId", s.as_str()));
112        }
113        if let Some(ref s) = p.trader_type {
114            params.push(("traderType", s.as_str()));
115        }
116        if let Some(ref s) = p.status {
117            params.push(("status", s.as_str()));
118        }
119        if let Some(ref s) = limit_str {
120            params.push(("limit", s.as_str()));
121        }
122        if let Some(ref s) = p.cursor {
123            params.push(("cursor", s.as_str()));
124        }
125        self.get("/v5/rfq/quote-list", &params).await
126    }
127
128    /// Get Quotes Realtime.
129    pub async fn get_quotes_realtime(
130        &self,
131        rfq_id: Option<&str>,
132        quote_id: Option<&str>,
133        quote_link_id: Option<&str>,
134        trader_type: Option<&str>,
135    ) -> Result<GetQuotesRealtimeResponse> {
136        let mut params: Vec<(&str, &str)> = vec![];
137        if let Some(s) = rfq_id {
138            params.push(("rfqId", s));
139        }
140        if let Some(s) = quote_id {
141            params.push(("quoteId", s));
142        }
143        if let Some(s) = quote_link_id {
144            params.push(("quoteLinkId", s));
145        }
146        if let Some(s) = trader_type {
147            params.push(("traderType", s));
148        }
149
150        self.get("/v5/rfq/quote-realtime", &params).await
151    }
152
153    /// Get RFQ Config.
154    pub async fn get_rfq_config(&self) -> Result<GetRfqConfigResponse> {
155        self.get("/v5/rfq/config", &[]).await
156    }
157
158    /// Get RFQs.
159    pub async fn get_rfqs(
160        &self,
161        rfq_id: Option<&str>,
162        rfq_link_id: Option<&str>,
163        trader_type: Option<&str>,
164        status: Option<&str>,
165        limit: Option<u32>,
166        cursor: Option<&str>,
167    ) -> Result<GetRfqsResponse> {
168        let limit_str = limit.map(|v| v.to_string());
169
170        let mut params: Vec<(&str, &str)> = vec![];
171        if let Some(s) = rfq_id {
172            params.push(("rfqId", s));
173        }
174        if let Some(s) = rfq_link_id {
175            params.push(("rfqLinkId", s));
176        }
177        if let Some(s) = trader_type {
178            params.push(("traderType", s));
179        }
180        if let Some(s) = status {
181            params.push(("status", s));
182        }
183        if let Some(ref s) = limit_str {
184            params.push(("limit", s.as_str()));
185        }
186        if let Some(s) = cursor {
187            params.push(("cursor", s));
188        }
189
190        self.get("/v5/rfq/rfq-list", &params).await
191    }
192
193    /// Get RFQs Realtime.
194    pub async fn get_rfqs_realtime(
195        &self,
196        rfq_id: Option<&str>,
197        rfq_link_id: Option<&str>,
198        trader_type: Option<&str>,
199    ) -> Result<GetRfqsRealtimeResponse> {
200        let mut params: Vec<(&str, &str)> = vec![];
201        if let Some(s) = rfq_id {
202            params.push(("rfqId", s));
203        }
204        if let Some(s) = rfq_link_id {
205            params.push(("rfqLinkId", s));
206        }
207        if let Some(s) = trader_type {
208            params.push(("traderType", s));
209        }
210
211        self.get("/v5/rfq/rfq-realtime", &params).await
212    }
213
214    /// Get Trade History.
215    pub async fn get_trade_history(
216        &self,
217        p: GetTradeHistoryParams,
218    ) -> Result<GetTradeHistoryResponse> {
219        let limit_str = p.limit.map(|v| v.to_string());
220        let mut params: Vec<(&str, &str)> = vec![];
221        if let Some(ref s) = p.rfq_id {
222            params.push(("rfqId", s.as_str()));
223        }
224        if let Some(ref s) = p.rfq_link_id {
225            params.push(("rfqLinkId", s.as_str()));
226        }
227        if let Some(ref s) = p.quote_id {
228            params.push(("quoteId", s.as_str()));
229        }
230        if let Some(ref s) = p.quote_link_id {
231            params.push(("quoteLinkId", s.as_str()));
232        }
233        if let Some(ref s) = p.trader_type {
234            params.push(("traderType", s.as_str()));
235        }
236        if let Some(ref s) = p.status {
237            params.push(("status", s.as_str()));
238        }
239        if let Some(ref s) = limit_str {
240            params.push(("limit", s.as_str()));
241        }
242        if let Some(ref s) = p.cursor {
243            params.push(("cursor", s.as_str()));
244        }
245        self.get("/v5/rfq/trade-list", &params).await
246    }
247}