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]
pub struct ActivePosition {
symbol: String,
profit: f64,
amount: f64,
pub symbol: String,
pub size: f64,
pub entry_price: f64,
pub mark_price: f64,
pub profit: f64,
}
#[pwp]
@@ -138,10 +140,15 @@ pub struct Alert {
#[pwp]
pub enum InspectTarget {
None,
Symbol(WatchListItem),
Position(ActivePosition),
Signal(Signal),
Alert(Alert),
Some(Vec<InspectItem>),
}
#[pwp]
pub enum InspectItem {
String(String),
Symbol(String),
USD(f64),
F64(f64),
}
impl std::fmt::Display for MarketTrend {
+14 -34
View File
@@ -1,6 +1,6 @@
use pulse_wire::terminal::{
ActivePosition, Alert, AlertLevel, EventLog, InspectTarget, LogKind, MarketOverview, Signal,
SignalKind, Status, WatchListItem,
ActivePosition, Alert, AlertLevel, EventLog, InspectItem, InspectTarget, LogKind,
MarketOverview, Signal, SignalKind, Status, WatchListItem,
};
pub trait Formatted {
@@ -12,37 +12,15 @@ impl Formatted for InspectTarget {
match self {
Self::None => vec!["\x1b[2mnothing to inspect\x1b[0m".to_string()],
Self::Symbol(watch) => vec![
Property("Symbol", format!("\x1b[35m{}\x1b[0m", watch.symbol)),
Property(
"Price",
format!("\x1b[96m{}\x1b[0m", format_f64(watch.price)),
),
Property("Trend", format!("{}", format_f64(watch.trend))),
Property("24h volume", format!("${}", format_f64(watch.volume_24h))),
]
.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(),
Self::Some(items) => items
.iter()
.map(|item| match item {
InspectItem::F64(v) => format_f64(*v),
InspectItem::USD(v) => format!("${}", format_f64(*v)),
InspectItem::Symbol(v) => format!("\x1b[35m{v}\x1b[0m"),
InspectItem::String(v) => v.clone(),
})
.collect(),
}
}
}
@@ -121,7 +99,9 @@ impl Formatted for ActivePosition {
fn get_formatted(&self) -> Vec<String> {
vec![
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!(
"{} {}",
if self.profit.is_sign_positive() {