barter_data/exchange/bybit/book/
l1.rs

1use barter_instrument::exchange::ExchangeId;
2use chrono::Utc;
3
4use crate::{
5    books::Level,
6    event::{MarketEvent, MarketIter},
7    subscription::book::OrderBookL1,
8};
9
10use super::BybitOrderBookMessage;
11
12impl<InstrumentKey> From<(ExchangeId, InstrumentKey, BybitOrderBookMessage)>
13    for MarketIter<InstrumentKey, OrderBookL1>
14where
15    InstrumentKey: Clone,
16{
17    fn from(
18        (exchange, instrument, book): (ExchangeId, InstrumentKey, BybitOrderBookMessage),
19    ) -> Self {
20        let best_ask = book.data.asks.first().copied().map(Level::from);
21        let best_bid = book.data.bids.first().copied().map(Level::from);
22
23        Self(vec![Ok(MarketEvent {
24            time_exchange: book.time,
25            time_received: Utc::now(),
26            exchange,
27            instrument,
28            kind: OrderBookL1 {
29                last_update_time: book.time,
30                best_bid,
31                best_ask,
32            },
33        })])
34    }
35}