exc_binance/types/adaptations/
trade.rs

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