bpx_api_client/routes/
trades.rs1use bpx_api_types::trade::Trade;
2
3use crate::error::Result;
4use crate::BpxClient;
5
6const API_TRADES: &str = "/api/v1/trades";
7const API_TRADES_HISTORY: &str = "/api/v1/trades/history";
8
9impl BpxClient {
10 pub async fn get_recent_trades(&self, symbol: &str, limit: Option<i16>) -> Result<Vec<Trade>> {
12 let mut url = format!("{}{}?symbol={}", self.base_url, API_TRADES, symbol);
13 if let Some(limit) = limit {
14 url.push_str(&format!("&limit={}", limit));
15 }
16 let res = self.get(url).await?;
17 res.json().await.map_err(Into::into)
18 }
19
20 pub async fn get_historical_trades(
22 &self,
23 symbol: &str,
24 limit: Option<i64>,
25 offset: Option<i64>,
26 ) -> Result<Vec<Trade>> {
27 let mut url = format!("{}{}?symbol={}", self.base_url, API_TRADES_HISTORY, symbol);
28 for (k, v) in [("limit", limit), ("offset", offset)] {
29 if let Some(v) = v {
30 url.push_str(&format!("&{}={}", k, v));
31 }
32 }
33 let res = self.get(url).await?;
34 res.json().await.map_err(Into::into)
35 }
36}