exc_binance/websocket/
mod.rs1pub mod error;
3
4pub mod protocol;
6
7pub mod request;
9
10pub mod response;
12
13pub mod endpoint;
15
16pub(crate) mod connect;
17
18use std::task::{Context, Poll};
19
20use futures::future::BoxFuture;
21use tower::{util::BoxService, Service};
22
23use self::{
24 connect::BinanceWsHost, endpoint::WsEndpoint, error::WsError, protocol::frame::Name,
25 request::WsRequest, response::WsResponse,
26};
27
28pub struct BinanceWebsocketApi {
30 svc: BoxService<WsRequest, WsResponse, WsError>,
31}
32
33impl BinanceWebsocketApi {
34 pub fn usd_margin_futures() -> WsEndpoint {
36 WsEndpoint::new(
37 BinanceWsHost::UsdMarginFutures,
38 Name::new("markPrice").with_inst("bnbusdt"),
39 )
40 }
41
42 pub fn spot() -> WsEndpoint {
44 WsEndpoint::new(
45 BinanceWsHost::Spot,
46 Name::new("miniTicker").with_inst("btcusdt"),
47 )
48 }
49
50 pub fn european_options() -> WsEndpoint {
52 WsEndpoint::new(
53 BinanceWsHost::EuropeanOptions,
54 Name::new("index").with_inst("BTCUSDT"),
55 )
56 }
57}
58
59impl Service<WsRequest> for BinanceWebsocketApi {
60 type Response = WsResponse;
61 type Error = WsError;
62 type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
63
64 fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
65 self.svc.poll_ready(cx)
66 }
67
68 fn call(&mut self, req: WsRequest) -> Self::Future {
69 self.svc.call(req)
70 }
71}