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
pub mod error;
pub mod protocol;
pub mod request;
pub mod response;
pub mod endpoint;
pub(crate) mod connect;
use std::task::{Context, Poll};
use futures::future::BoxFuture;
use tower::{util::BoxService, Service};
use self::{
connect::BinanceWsHost, endpoint::WsEndpoint, error::WsError, protocol::frame::Name,
request::WsRequest, response::WsResponse,
};
pub struct BinanceWebsocketApi {
svc: BoxService<WsRequest, WsResponse, WsError>,
}
impl BinanceWebsocketApi {
pub fn usd_margin_futures() -> WsEndpoint {
WsEndpoint::new(
BinanceWsHost::UsdMarginFutures,
Name::new("markPrice").inst("bnbusdt"),
)
}
pub fn spot() -> WsEndpoint {
WsEndpoint::new(BinanceWsHost::Spot, Name::new("miniTicker").inst("btcusdt"))
}
}
impl Service<WsRequest> for BinanceWebsocketApi {
type Response = WsResponse;
type Error = WsError;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.svc.poll_ready(cx)
}
fn call(&mut self, req: WsRequest) -> Self::Future {
self.svc.call(req)
}
}