1use error_chain::bail;
2
3use crate::model::{Empty, ExchangeInformation, ServerTime, Symbol};
4use crate::client::Client;
5use crate::errors::Result;
6use crate::api::API;
7use crate::api::Spot;
8
9#[derive(Clone)]
10pub struct General {
11 pub client: Client,
12}
13
14impl General {
15 pub fn ping(&self) -> Result<String> {
17 self.client.get::<Empty>(API::Spot(Spot::Ping), None)?;
18 Ok("pong".into())
19 }
20
21 pub fn get_server_time(&self) -> Result<ServerTime> {
23 self.client.get(API::Spot(Spot::Time), None)
24 }
25
26 pub fn exchange_info(&self) -> Result<ExchangeInformation> {
29 self.client.get(API::Spot(Spot::ExchangeInfo), None)
30 }
31
32 pub fn get_symbol_info<S>(&self, symbol: S) -> Result<Symbol>
34 where
35 S: Into<String>,
36 {
37 let upper_symbol = symbol.into().to_uppercase();
38 match self.exchange_info() {
39 Ok(info) => {
40 for item in info.symbols {
41 if item.symbol == upper_symbol {
42 return Ok(item);
43 }
44 }
45 bail!("Symbol not found")
46 }
47 Err(e) => Err(e),
48 }
49 }
50}