xapi_binance/clients/spot/
general.rs

1use crate::{
2    clients::spot::BnSpot,
3    common::response::{BnRestRespType, BnWsApiRespType},
4    data::{
5        enums::ratelimit::BnRateLimitType, exchange_information::BnSpotExchangeInformation,
6        server_time::BnServerTime,
7    },
8};
9use http::Method;
10use nonzero_ext::nonzero;
11use xapi_shared::{data::empty::SharedEmpty, rest::SharedRestClientTrait};
12
13impl BnSpot {
14    /// Test connectivity to the Rest API.
15    ///
16    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#test-connectivity>
17    pub async fn ping(&self) -> BnRestRespType<SharedEmpty> {
18        self.executor
19            .call_with_no_payload(
20                &[
21                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
22                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
23                ],
24                false,
25                Method::GET,
26                self.executor
27                    .get_endpoint()
28                    .build_rest_api_url("/api/v3/ping"),
29            )
30            .await
31    }
32
33    /// Test connectivity to the WebSocket API.
34    ///
35    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#test-connectivity>
36    pub async fn ping_ws(&self) -> BnWsApiRespType<SharedEmpty> {
37        self.executor
38            .call_ws_api(
39                &[
40                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
41                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
42                ],
43                false,
44                "ping",
45                None::<()>,
46            )
47            .await
48    }
49
50    /// Test connectivity to the Rest API and get the current server time.
51    ///
52    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time>
53    pub async fn get_server_time(&self) -> BnRestRespType<BnServerTime> {
54        self.executor
55            .call_with_no_payload(
56                &[
57                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
58                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
59                ],
60                false,
61                Method::GET,
62                self.executor
63                    .get_endpoint()
64                    .build_rest_api_url("/api/v3/time"),
65            )
66            .await
67    }
68
69    /// Test connectivity to the WebSocket API and get the current server time.
70    ///
71    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#check-server-time>
72    pub async fn get_server_time_ws(&self) -> BnWsApiRespType<BnServerTime> {
73        self.executor
74            .call_ws_api(
75                &[
76                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
77                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
78                ],
79                false,
80                "time",
81                None::<()>,
82            )
83            .await
84    }
85
86    /// Current exchange trading rules and symbol information
87    ///
88    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information>
89    pub async fn get_exchange_information(&self) -> BnRestRespType<BnSpotExchangeInformation> {
90        self.executor
91            .call_with_no_payload(
92                &[
93                    (BnRateLimitType::RequestWeight, nonzero!(20u32)),
94                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
95                ],
96                false,
97                Method::GET,
98                self.executor
99                    .get_endpoint()
100                    .build_rest_api_url("/api/v3/exchangeInfo"),
101            )
102            .await
103    }
104
105    /// Query current exchange trading rules, rate limits, and symbol information.
106    ///
107    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#exchange-information>
108    pub async fn get_exchange_information_ws(&self) -> BnWsApiRespType<BnSpotExchangeInformation> {
109        self.executor
110            .call_ws_api(
111                &[
112                    (BnRateLimitType::RequestWeight, nonzero!(20u32)),
113                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
114                ],
115                false,
116                "exchangeInfo",
117                None::<()>,
118            )
119            .await
120    }
121}