use crate::platform::id::Id;
use std::fmt::{Display, Formatter};
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Account {
pub id: Id,
pub buying_power: f64,
pub cash: f64,
pub currency: String,
pub market_value_long: f64,
pub market_value_short: f64,
pub equity: f64,
}
impl Account {
#[cfg(test)]
pub fn fixture() -> Self {
Self {
buying_power: 1000.0,
cash: 500.0,
equity: 500.0,
..Default::default()
}
}
}
impl Display for Account {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let buying_power = self.buying_power;
let equity = self.equity;
let cash = self.cash;
write!(
f,
"buying power: {:.2}, equity: {:.2}, cash: {:.2}",
buying_power, equity, cash
)
}
}
#[cfg(test)]
mod test {
use crate::platform::account::Account;
#[test]
fn display() {
let account = Account {
buying_power: 100.0,
equity: 200.0,
cash: 50.0,
..Default::default()
};
let display = account.to_string();
let expected = "buying power: 100.00, equity: 200.00, cash: 50.00";
assert_eq!(display, expected)
}
}