binance/general.rs
1use serde_json::Value;
2
3use crate::client::*;
4use crate::errors::*;
5use crate::rest_model::*;
6
7#[derive(Clone)]
8pub struct General {
9 pub client: Client,
10}
11
12impl General {
13 /// Test connectivity
14 /// # Examples
15 /// ```rust
16 /// use binance::{api::*, general::*, config::*};
17 /// let conf = Config::default().set_rest_api_endpoint(DATA_REST_ENDPOINT);
18 /// let general: General = Binance::new_with_env(&conf);
19 /// let pong = tokio_test::block_on(general.ping());
20 /// assert!(pong.is_ok(), "{:?}", pong);
21 /// assert_eq!(pong.unwrap(), "pong");
22 /// ```
23 pub async fn ping(&self) -> Result<&'static str> {
24 let _: Value = self.client.get("/api/v3/ping", None).await?;
25
26 Ok("pong")
27 }
28
29 /// Check server time
30 /// # Examples
31 /// ```rust
32 /// use binance::{api::*, general::*, config::*};
33 /// let conf = Config::default().set_rest_api_endpoint(DATA_REST_ENDPOINT);
34 /// let general: General = Binance::new_with_env(&conf);
35 /// let server_time = tokio_test::block_on(general.get_server_time());
36 /// assert!(server_time.is_ok(), "{:?}", server_time);
37 /// ```
38 pub async fn get_server_time(&self) -> Result<ServerTime> { self.client.get("/api/v3/time", None).await }
39
40 /// Obtain exchange information (rate limits, symbol metadata etc)
41 /// # Examples
42 /// ```rust
43 /// use binance::{api::*, general::*, config::*};
44 /// let conf = Config::default().set_rest_api_endpoint(DATA_REST_ENDPOINT);
45 /// let general: General = Binance::new_with_env(&conf);
46 /// let exchange_info = tokio_test::block_on(general.exchange_info());
47 /// assert!(exchange_info.is_ok(), "{:?}", exchange_info);
48 /// ```
49 pub async fn exchange_info(&self) -> Result<ExchangeInformation> {
50 self.client.get("/api/v3/exchangeInfo", None).await
51 }
52}