Skip to main content

hypercall/client/wallet_client/
queries.rs

1use super::WalletClient;
2use sonic_rs::Value;
3
4impl WalletClient {
5    pub async fn get_orders(
6        &self,
7        base_url: &str,
8    ) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
9        let response = self
10            .http_client
11            .get(format!(
12                "{}/orders?wallet={}",
13                base_url, self.wallet_address
14            ))
15            .send()
16            .await?;
17
18        let status = response.status();
19        let body = response.text().await?;
20
21        if !status.is_success() {
22            return Err(format!("Failed to get orders: {} - {}", status, body).into());
23        }
24
25        Ok(sonic_rs::from_str(&body)?)
26    }
27
28    pub async fn get_portfolio(
29        &self,
30        base_url: &str,
31    ) -> Result<sonic_rs::Value, Box<dyn std::error::Error + Send + Sync>> {
32        let response = self
33            .http_client
34            .get(format!(
35                "{}/portfolio?wallet={}",
36                base_url, self.wallet_address
37            ))
38            .send()
39            .await?;
40
41        let status = response.status();
42        let body = response.text().await?;
43
44        if !status.is_success() {
45            return Err(format!("Failed to get portfolio: {} - {}", status, body).into());
46        }
47
48        Ok(sonic_rs::from_str(&body)?)
49    }
50}