Improved inspect and positions

This commit is contained in:
2026-07-24 01:13:28 +02:00
parent 8b5fa22deb
commit 7b0f80864b
2 changed files with 28 additions and 41 deletions
+14 -7
View File
@@ -41,9 +41,11 @@ pub struct WatchListItem {
#[pwp] #[pwp]
pub struct ActivePosition { pub struct ActivePosition {
symbol: String, pub symbol: String,
profit: f64, pub size: f64,
amount: f64, pub entry_price: f64,
pub mark_price: f64,
pub profit: f64,
} }
#[pwp] #[pwp]
@@ -138,10 +140,15 @@ pub struct Alert {
#[pwp] #[pwp]
pub enum InspectTarget { pub enum InspectTarget {
None, None,
Symbol(WatchListItem), Some(Vec<InspectItem>),
Position(ActivePosition), }
Signal(Signal),
Alert(Alert), #[pwp]
pub enum InspectItem {
String(String),
Symbol(String),
USD(f64),
F64(f64),
} }
impl std::fmt::Display for MarketTrend { impl std::fmt::Display for MarketTrend {
+14 -34
View File
@@ -1,6 +1,6 @@
use pulse_wire::terminal::{ use pulse_wire::terminal::{
ActivePosition, Alert, AlertLevel, EventLog, InspectTarget, LogKind, MarketOverview, Signal, ActivePosition, Alert, AlertLevel, EventLog, InspectItem, InspectTarget, LogKind,
SignalKind, Status, WatchListItem, MarketOverview, Signal, SignalKind, Status, WatchListItem,
}; };
pub trait Formatted { pub trait Formatted {
@@ -12,37 +12,15 @@ impl Formatted for InspectTarget {
match self { match self {
Self::None => vec!["\x1b[2mnothing to inspect\x1b[0m".to_string()], Self::None => vec!["\x1b[2mnothing to inspect\x1b[0m".to_string()],
Self::Symbol(watch) => vec![ Self::Some(items) => items
Property("Symbol", format!("\x1b[35m{}\x1b[0m", watch.symbol)), .iter()
Property( .map(|item| match item {
"Price", InspectItem::F64(v) => format_f64(*v),
format!("\x1b[96m{}\x1b[0m", format_f64(watch.price)), InspectItem::USD(v) => format!("${}", format_f64(*v)),
), InspectItem::Symbol(v) => format!("\x1b[35m{v}\x1b[0m"),
Property("Trend", format!("{}", format_f64(watch.trend))), InspectItem::String(v) => v.clone(),
Property("24h volume", format!("${}", format_f64(watch.volume_24h))), })
] .collect(),
.get_formatted(),
Self::Position(pos) => vec![
Property("Symbol", format!("\x1b[35m{}\x1b[0m", pos.symbol)),
Property("Profit", format!("{:+.2}", pos.profit)),
Property("Amount", format!("{}", pos.amount)),
]
.get_formatted(),
Self::Signal(sig) => vec![
Property("Type", format!("{}", sig.kind)),
Property("Symbol", format!("\x1b[35m{}\x1b[0m", sig.symbol)),
Property("Parameter", format!("{}", sig.param)),
Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(sig.price))),
]
.get_formatted(),
Self::Alert(alert) => vec![
Property("Level", format!("{}", alert.level)),
Property("Message", alert.message.clone()),
]
.get_formatted(),
} }
} }
} }
@@ -121,7 +99,9 @@ impl Formatted for ActivePosition {
fn get_formatted(&self) -> Vec<String> { fn get_formatted(&self) -> Vec<String> {
vec![ vec![
format!("\x1b[35m{}\x1b[0m", self.symbol), format!("\x1b[35m{}\x1b[0m", self.symbol),
format_f64(self.amount), format_f64(self.size),
format_f64(self.entry_price),
format_f64(self.mark_price),
format!( format!(
"{} {}", "{} {}",
if self.profit.is_sign_positive() { if self.profit.is_sign_positive() {