use crate::param::{Quantity, Volume};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum TradeAmount {
Quantity(Quantity),
Volume(Volume),
}
impl std::fmt::Display for TradeAmount {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Quantity(qty) => write!(formatter, "{qty}"),
Self::Volume(vol) => write!(formatter, "{vol}"),
}
}
}
#[cfg(test)]
mod tests {
use crate::param::{Quantity, Volume};
use super::TradeAmount;
#[test]
fn display_quantity_variant() {
let amount = TradeAmount::Quantity(Quantity::from_str("10").expect("must be valid"));
assert_eq!(amount.to_string(), "10");
}
#[test]
fn display_volume_variant() {
let amount = TradeAmount::Volume(Volume::from_str("500.5").expect("must be valid"));
assert_eq!(amount.to_string(), "500.5");
}
}