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
use tokio::sync::{broadcast, watch};
use bat_markets_core::{HealthNotification, HealthReport};
use crate::client::BatMarkets;
/// Cheap health snapshots for applications and automation.
pub struct HealthClient<'a> {
inner: &'a BatMarkets,
}
impl<'a> HealthClient<'a> {
pub(crate) const fn new(inner: &'a BatMarkets) -> Self {
Self { inner }
}
/// Return the current health snapshot.
#[must_use]
pub fn snapshot(&self) -> HealthReport {
self.inner.shared.health_snapshot()
}
/// Subscribe to snapshot-style health changes.
///
/// ```no_run
/// use bat_markets::{BatMarkets, errors::Result, types::{Product, Venue}};
///
/// # #[tokio::main]
/// # async fn main() -> Result<()> {
/// let client = BatMarkets::builder()
/// .venue(Venue::Bybit)
/// .product(Product::LinearUsdt)
/// .build_live()
/// .await?;
/// let receiver = client.health().subscribe();
/// let _initial = receiver.borrow().clone();
/// # Ok(())
/// # }
/// ```
pub fn subscribe(&self) -> watch::Receiver<HealthReport> {
self.inner.shared.subscribe_health()
}
/// Subscribe to transition-style health notifications.
///
/// Notifications are emitted for structural state changes, not every market-data tick.
pub fn notifications(&self) -> broadcast::Receiver<HealthNotification> {
self.inner.shared.subscribe_health_notifications()
}
}