From 02a06b2647ccdd95d91f299fccfe4d1f14bbafdd Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 15 Jul 2026 12:30:02 +0200 Subject: [PATCH] Account and properties --- src/formatting.rs | 25 +++++++++++++++++++++++-- src/main.rs | 26 ++++++++++++++------------ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 1ba62e7..2eff77f 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,4 +1,4 @@ -use crate::types::{ActivePosition, WatchListItem}; +use crate::types::{Account, ActivePosition, WatchListItem}; pub trait Formatted { fn get_formatted(&self) -> Vec; @@ -40,6 +40,27 @@ impl Formatted for ActivePosition { } } +pub struct Property(&'static str, String); + +impl Formatted for Account { + fn get_formatted(&self) -> Vec { + vec![ + Property("Equity", format_f64(self.equity)), + Property("Liquid", format_f64(self.liquid)), + Property("Unreal", format_f64(self.unreal)), + Property("Realized", format_f64(self.realized)), + Property("Margin", format_f64(self.margin)), + ] + .get_formatted() + } +} + +impl Formatted for Property { + fn get_formatted(&self) -> Vec { + vec![format!("\x1b[91m{}\x1b[0m", self.0), self.1.clone()] + } +} + impl Formatted for Vec { fn get_formatted(&self) -> Vec { let mut output = Vec::new(); @@ -66,7 +87,7 @@ impl Formatted for Vec { for (col_idx, col) in row.iter().enumerate() { let width = widths[col_idx]; - row_out.push_str(&format!("{:>width$}", col, width = width)); + row_out.push_str(&format!("{:, watch_list: State>, active_positions: State>, + account: State, } impl App for PulseTradeApp { @@ -147,17 +149,10 @@ impl App for PulseTradeApp { ), ( LayoutItem::Widget(Size::Flex(1)), - Box::new( - vec![ - " ACCOUNT", - " Equity: $25,483.21", - " Liquid: $11,928.43", - " Unreal: +$483.12", - " Realized: +$2,182.49", - " Margin: 0.00%", - ] - .join("\n"), - ), + Box::new(format![ + " ACCOUNT\n{}", + apply_padding(self.account.lock().await.get_formatted()).join("\n") + ]), ), ]), ); @@ -207,6 +202,13 @@ async fn main() { command: ctx.use_state(InputState::new()), watch_list: ctx.use_state(Vec::new()), active_positions: ctx.use_state(Vec::new()), + account: ctx.use_state(Account { + equity: 25_483.21, + liquid: 11_928.43, + unreal: 483.12, + realized: 2_182.49, + margin: 0.0, + }), }) .await; }