exc_binance/types/adaptations/
book.rs1use exc_core::{types, Adaptor, ExchangeError};
2use futures::{StreamExt, TryStreamExt};
3
4use crate::{
5 websocket::{protocol::frame::DepthFrame, request::WsRequest},
6 Request,
7};
8
9impl Adaptor<types::SubscribeBidAsk> for Request {
10 fn from_request(req: types::SubscribeBidAsk) -> Result<Self, ExchangeError> {
11 Ok(WsRequest::dispatch_bid_ask(req).into())
12 }
13
14 fn into_response(resp: Self::Response) -> Result<types::BidAskStream, ExchangeError> {
15 let stream = resp.into_stream::<DepthFrame>()?;
16 Ok(stream
17 .map_err(ExchangeError::from)
18 .and_then(|t| async move { t.try_into() })
19 .boxed())
20 }
21}