#[derive(Clone)] struct Symbol; impl Symbol { const XMR: &'static str = "XMR"; const BTC: &'static str = "BTC"; const ETH: &'static str = "ETH"; const USD: &'static str = "USD"; } #[derive(Clone)] struct TradingPair { quote: Symbol } impl TradingPair {} #[derive(Clone)] struct Currency { name: String, amount: f64, price: Option, } impl Currency { pub fn new, F: Into>(name: S, amount: F, price: Option) -> Self { Currency { name: name.into(), amount: amount.into(), price: price.map(|x| x.into()), } } pub fn name(&self) -> &str { &self.name } pub fn amount(&self) -> f64 { self.amount } pub fn price(&self) -> Option { self.price } } #[derive(Clone)] enum WalletKind { Margin, Exchange, Funding, } #[derive(Clone)] struct Balance { currency: Currency, quote: Symbol, quote_equivalent: f64, wallet: WalletKind, } impl Balance { pub fn new(currency: Currency, quote: Symbol, quote_equivalent: f64, wallet: WalletKind) -> Self { Balance { currency, quote, quote_equivalent, wallet } } pub fn currency(&self) -> &Currency { &self.currency } pub fn quote(&self) -> &Symbol { &self.quote } pub fn quote_equivalent(&self) -> f64 { self.quote_equivalent } pub fn wallet(&self) -> &WalletKind { &self.wallet } } struct BalanceGroup { quote: Symbol, quote_equivalent: f64, balances: Vec, } impl BalanceGroup { pub fn new(quote: Symbol) -> Self { BalanceGroup { quote, balances: Vec::new(), quote_equivalent: 0f64 } } pub fn add_balance(&mut self, balance: &Balance) { self.balances.push(balance.clone()); self.quote_equivalent += balance.quote_equivalent() } pub fn currency_names(&self) -> Vec { self.balances.iter() .map(|x| x.currency().name().into()) .collect() } pub fn quote(&self) -> &Symbol { &self.quote } pub fn balances(&self) -> &Vec { &self.balances } }