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