Skip to main content

flowsurface_data/
audio.rs

1use crate::util::ok_or_default;
2use exchange::SerTicker;
3
4use rustc_hash::FxHashMap;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
8pub enum Threshold {
9    Count(usize),
10    Qty(f32),
11}
12
13impl std::fmt::Display for Threshold {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        match self {
16            Threshold::Count(count) => write!(f, "Count based: {}", count),
17            Threshold::Qty(qty) => write!(f, "Qty based: {:.2}", qty),
18        }
19    }
20}
21
22#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
23pub struct StreamCfg {
24    pub enabled: bool,
25    pub threshold: Threshold,
26}
27
28impl Default for StreamCfg {
29    fn default() -> Self {
30        StreamCfg {
31            enabled: true,
32            threshold: Threshold::Count(10),
33        }
34    }
35}
36
37#[derive(Default, Clone, Deserialize, Serialize)]
38#[serde(default)]
39pub struct AudioStream {
40    #[serde(deserialize_with = "ok_or_default")]
41    pub streams: FxHashMap<SerTicker, StreamCfg>,
42    #[serde(deserialize_with = "ok_or_default")]
43    pub volume: Option<f32>,
44}