Skip to main content

binance/
general.rs

1use crate::model::{Empty, ExchangeInformation, ServerTime, Symbol};
2use crate::client::Client;
3use crate::errors::{Result, SdkError};
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 fn ping(&self) -> Result<String> {
15        self.client.get::<Empty>(API::Spot(Spot::Ping), None)?;
16        Ok("pong".into())
17    }
18
19    // Check server time
20    pub fn get_server_time(&self) -> Result<ServerTime> {
21        self.client.get(API::Spot(Spot::Time), None)
22    }
23
24    // Obtain exchange information
25    // - Current exchange trading rules and symbol information
26    pub fn exchange_info(&self) -> Result<ExchangeInformation> {
27        self.client.get(API::Spot(Spot::ExchangeInfo), None)
28    }
29
30    // Get Symbol information
31    pub fn get_symbol_info<S>(&self, symbol: S) -> Result<Symbol>
32    where
33        S: Into<String>,
34    {
35        let upper_symbol = symbol.into().to_uppercase();
36        match self.exchange_info() {
37            Ok(info) => {
38                for item in info.symbols {
39                    if item.symbol == upper_symbol {
40                        return Ok(item);
41                    }
42                }
43                Err(SdkError::Other("Symbol not found".into()))
44            }
45            Err(e) => Err(e),
46        }
47    }
48}