xapi-binance 0.0.1

Binance API client
Documentation
use crate::{
    clients::spot::BnSpot,
    common::response::{BnRestRespType, BnWsApiRespType},
    data::{
        enums::ratelimit::BnRateLimitType, exchange_information::BnSpotExchangeInformation,
        server_time::BnServerTime,
    },
};
use http::Method;
use nonzero_ext::nonzero;
use xapi_shared::{data::empty::SharedEmpty, rest::SharedRestClientTrait};

impl BnSpot {
    /// Test connectivity to the Rest API.
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#test-connectivity>
    pub async fn ping(&self) -> BnRestRespType<SharedEmpty> {
        self.executor
            .call_with_no_payload(
                &[
                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                Method::GET,
                self.executor
                    .get_endpoint()
                    .build_rest_api_url("/api/v3/ping"),
            )
            .await
    }

    /// Test connectivity to the WebSocket API.
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#test-connectivity>
    pub async fn ping_ws(&self) -> BnWsApiRespType<SharedEmpty> {
        self.executor
            .call_ws_api(
                &[
                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                "ping",
                None::<()>,
            )
            .await
    }

    /// Test connectivity to the Rest API and get the current server time.
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time>
    pub async fn get_server_time(&self) -> BnRestRespType<BnServerTime> {
        self.executor
            .call_with_no_payload(
                &[
                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                Method::GET,
                self.executor
                    .get_endpoint()
                    .build_rest_api_url("/api/v3/time"),
            )
            .await
    }

    /// Test connectivity to the WebSocket API and get the current server time.
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#check-server-time>
    pub async fn get_server_time_ws(&self) -> BnWsApiRespType<BnServerTime> {
        self.executor
            .call_ws_api(
                &[
                    (BnRateLimitType::RequestWeight, nonzero!(1u32)),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                "time",
                None::<()>,
            )
            .await
    }

    /// Current exchange trading rules and symbol information
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information>
    pub async fn get_exchange_information(&self) -> BnRestRespType<BnSpotExchangeInformation> {
        self.executor
            .call_with_no_payload(
                &[
                    (BnRateLimitType::RequestWeight, nonzero!(20u32)),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                Method::GET,
                self.executor
                    .get_endpoint()
                    .build_rest_api_url("/api/v3/exchangeInfo"),
            )
            .await
    }

    /// Query current exchange trading rules, rate limits, and symbol information.
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#exchange-information>
    pub async fn get_exchange_information_ws(&self) -> BnWsApiRespType<BnSpotExchangeInformation> {
        self.executor
            .call_ws_api(
                &[
                    (BnRateLimitType::RequestWeight, nonzero!(20u32)),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                "exchangeInfo",
                None::<()>,
            )
            .await
    }
}