Skip to main content

binance_rs_plus/
general.rs

1use crate::model::{Empty, ExchangeInformation, ServerTime, Symbol};
2use crate::client::Client;
3use crate::errors::{Result, Error}; // Added Error
4use crate::api::API;
5use crate::api::Spot;
6
7#[derive(Clone)]
8pub struct General {
9    pub client: Client,
10}
11
12impl General {
13    // Test connectivity
14    pub async fn ping(&self) -> Result<String> {
15        // async added
16        self.client
17            .get::<Empty>(API::Spot(Spot::Ping), None)
18            .await?; // .await? added
19        Ok("pong".into())
20    }
21
22    // Check server time
23    pub async fn get_server_time(&self) -> Result<ServerTime> {
24        // async added
25        self.client.get(API::Spot(Spot::Time), None).await // .await added
26    }
27
28    // Obtain exchange information
29    // - Current exchange trading rules and symbol information
30    pub async fn exchange_info(&self) -> Result<ExchangeInformation> {
31        // async added
32        self.client.get(API::Spot(Spot::ExchangeInfo), None).await // .await added
33    }
34
35    // Get Symbol information
36    pub async fn get_symbol_info<S>(&self, symbol: S) -> Result<Symbol>
37    // async added
38    where
39        S: Into<String>,
40    {
41        let upper_symbol = symbol.into().to_uppercase();
42        match self.exchange_info().await {
43            // .await added
44            Ok(info) => {
45                for item in info.symbols {
46                    if item.symbol == upper_symbol {
47                        return Ok(item);
48                    }
49                }
50                Err(Error::Custom("Symbol not found".to_string())) // Replaced bail
51            }
52            Err(e) => Err(e),
53        }
54    }
55}