1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
}
}