Skip to main content

jupiter_sdk/api/
price.rs

1use crate::{price::{GetPriceReq, GetPriceRes}, JupiterClient, JupiterError};
2
3
4
5
6#[derive(Clone)]
7pub struct PriceService<'a>{
8    client: &'a JupiterClient,
9}
10
11
12impl<'a> PriceService<'a> {
13    pub fn new(client: &'a JupiterClient) -> Self {
14        Self { client }
15    }
16
17    pub async fn get_price(
18        &self,
19        req: &GetPriceReq,
20    ) -> Result<GetPriceRes, JupiterError> {
21        let path = "/price/v3";
22        self.client.get_json_with_query(&path, req).await
23    }
24}
25
26
27
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[tokio::test]
34    async fn test_get_price() {
35        let client = JupiterClient::new(crate::JupiterConfig::default()).unwrap();
36        let price_service = PriceService::new(&client);
37
38        let res = price_service.get_price(&&GetPriceReq {
39            ids: "So11111111111111111111111111111111111111112,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string(),
40        }).await;
41
42        match res {
43            Ok(res) => {
44                println!("get_price: {}", serde_json::to_string_pretty(&res).unwrap());
45            }
46            Err(e) => {
47                panic!("get_price error: {}", e);
48            }
49        }
50    }
51}
52