binance_rs_plus/
general.rs1use crate::model::{Empty, ExchangeInformation, ServerTime, Symbol};
2use crate::client::Client;
3use crate::errors::{Result, Error}; use crate::api::API;
5use crate::api::Spot;
6
7#[derive(Clone)]
8pub struct General {
9 pub client: Client,
10}
11
12impl General {
13 pub async fn ping(&self) -> Result<String> {
15 self.client
17 .get::<Empty>(API::Spot(Spot::Ping), None)
18 .await?; Ok("pong".into())
20 }
21
22 pub async fn get_server_time(&self) -> Result<ServerTime> {
24 self.client.get(API::Spot(Spot::Time), None).await }
27
28 pub async fn exchange_info(&self) -> Result<ExchangeInformation> {
31 self.client.get(API::Spot(Spot::ExchangeInfo), None).await }
34
35 pub async fn get_symbol_info<S>(&self, symbol: S) -> Result<Symbol>
37 where
39 S: Into<String>,
40 {
41 let upper_symbol = symbol.into().to_uppercase();
42 match self.exchange_info().await {
43 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())) }
52 Err(e) => Err(e),
53 }
54 }
55}