xapi-binance 0.0.1

Binance API client
Documentation
use crate::{
    clients::spot::BnSpot,
    common::response::{BnRestRespType, BnWsApiRespType},
    data::{
        enums::ratelimit::BnRateLimitType,
        order_book::{BnGetOrderBookParams, BnSpotOrderBook},
    },
};
use http::Method;
use nonzero_ext::nonzero;
use xapi_shared::rest::SharedRestClientTrait;

impl BnSpot {
    /// Get order book
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#order-book>
    pub async fn get_order_book(
        &self,
        params: &BnGetOrderBookParams,
    ) -> BnRestRespType<BnSpotOrderBook> {
        let weight = match params.limit.unwrap_or(100) {
            1..=100 => nonzero!(5u32),
            101..=500 => nonzero!(25u32),
            501..=1000 => nonzero!(50u32),
            _ => nonzero!(250u32),
        };

        self.executor
            .call(
                &[
                    (BnRateLimitType::RequestWeight, weight),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                Method::GET,
                self.executor
                    .get_endpoint()
                    .build_rest_api_url("/api/v3/depth"),
                Some(params),
            )
            .await
    }

    // /// Get current order book.
    // ///
    // /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#order-book>
    // pub async fn get_order_book_ws(
    //     &self,
    //     params: &BnGetOrderBookParams,
    // ) -> BnWsApiRespType<BnSpotOrderBook> {
    //     let weight = match params.limit.unwrap_or(100) {
    //         1..=100 => nonzero!(5u32),
    //         101..=500 => nonzero!(25u32),
    //         501..=1000 => nonzero!(50u32),
    //         _ => nonzero!(250u32),
    //     };

    //     self.executor
    //         .send(
    //             &[
    //                 (BnRateLimitType::RequestWeight, weight),
    //                 (BnRateLimitType::RawRequests, nonzero!(1u32)),
    //             ],
    //             false,
    //             "depth",
    //             Some(params),
    //         )
    //         .await
    // }

    /// Get current order book.
    ///
    /// <https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#order-book>
    pub async fn get_order_book_ws(
        &self,
        params: &BnGetOrderBookParams,
    ) -> BnWsApiRespType<BnSpotOrderBook> {
        let weight = match params.limit.unwrap_or(100) {
            1..=100 => nonzero!(5u32),
            101..=500 => nonzero!(25u32),
            501..=1000 => nonzero!(50u32),
            _ => nonzero!(250u32),
        };

        self.executor
            .call_ws_api(
                &[
                    (BnRateLimitType::RequestWeight, weight),
                    (BnRateLimitType::RawRequests, nonzero!(1u32)),
                ],
                false,
                "depth",
                Some(params),
            )
            .await
    }
}