This commit is contained in:
2026-07-15 22:53:18 +02:00
parent 12c17279f8
commit 9c7b492ac9
4 changed files with 146 additions and 118 deletions
+45 -56
View File
@@ -12,52 +12,41 @@ impl Formatted for InspectTarget {
match self {
Self::None => vec!["\x1b[2mnothing to inspect\x1b[0m".to_string()],
Self::Symbol {
symbol,
price,
trend,
market_trend,
volatility,
pressure,
alerts,
} => vec![
Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)),
Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(*price))),
Property("Trend", format!("{}", format_f64(*trend))),
Property("Market", format!("{:?}", market_trend)),
Property("Volatility", format!("{:?}", volatility)),
Property("Pressure", format!("{:+.2}%", pressure * 100.0)),
Property("Alerts", format!("{}", alerts.len())),
Self::Symbol(boxed) => {
let (watch, overview) = &**boxed;
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("Market", format!("{}", overview.trend)),
Property("Volatility", format!("{}", overview.volatility)),
Property(
"Pressure",
format!("{:+.2}%", overview.pressure * 100.0),
),
Property("Alerts", format!("{}", overview.alerts.len())),
]
.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::Position {
symbol,
profit,
amount,
} => vec![
Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)),
Property("Profit", format!("{:+.2}", profit)),
Property("Amount", format!("{}", amount)),
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::Signal {
kind,
symbol,
param,
price,
} => vec![
Property("Type", format!("{:?}", kind)),
Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)),
Property("Parameter", format!("{:?}", param)),
Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(*price))),
]
.get_formatted(),
Self::Alert { level, message } => vec![
Property("Level", format!("{:?}", level)),
Property("Message", message.clone()),
Self::Alert(alert) => vec![
Property("Level", format!("{}", alert.level)),
Property("Message", alert.message.clone()),
]
.get_formatted(),
}
@@ -68,11 +57,11 @@ impl Formatted for Alert {
fn get_formatted(&self) -> Vec<String> {
vec![
format!(
"{}{:?}\x1b[0m",
"{}{}\x1b[0m",
match &self.level {
AlertLevel::L => "\x1b[34m",
AlertLevel::M => "\x1b[33m",
AlertLevel::H => "\x1b[31m",
AlertLevel::Low => "\x1b[34m",
AlertLevel::Medium => "\x1b[33m",
AlertLevel::High => "\x1b[31m",
},
self.level
),
@@ -85,12 +74,12 @@ impl Formatted for EventLog {
fn get_formatted(&self) -> Vec<String> {
vec![
format!(
"{}{:?}\x1b[0m",
"{}{}\x1b[0m",
match &self.kind {
LogKind::INFO => "\x1b[34m",
LogKind::DEBUG => "\x1b[36m",
LogKind::ERR => "\x1b[31m",
LogKind::WARN => "\x1b[33m",
LogKind::Info => "\x1b[34m",
LogKind::Debug => "\x1b[36m",
LogKind::Err => "\x1b[31m",
LogKind::Warn => "\x1b[33m",
},
self.kind
),
@@ -103,13 +92,13 @@ impl Formatted for EventLog {
impl Formatted for Signal {
fn get_formatted(&self) -> Vec<String> {
vec![
if matches!(self.kind, SignalKind::BUY) {
format!("\x1b[32m{:?}\x1b[0m", self.kind)
if matches!(self.kind, SignalKind::Buy) {
format!("\x1b[32m{}\x1b[0m", self.kind)
} else {
format!("\x1b[31m{:?}\x1b[0m", self.kind)
format!("\x1b[31m{}\x1b[0m", self.kind)
},
format!("\x1b[35m{}\x1b[0m", self.symbol),
format!("\x1b[34m{:?}\x1b[0m", self.param),
format!("\x1b[34m{}\x1b[0m", self.param),
format_f64(self.price),
]
}
@@ -151,13 +140,13 @@ impl Formatted for ActivePosition {
}
}
pub struct Property(&'static str, String);
struct Property(&'static str, String);
impl Formatted for MarketOverview {
fn get_formatted(&self) -> Vec<String> {
vec![
Property("TREND", format!("{:?}", self.trend)),
Property("VOLATILITY", format!("{:?}", self.volatility)),
Property("TREND", format!("{}", self.trend)),
Property("VOLATILITY", format!("{}", self.volatility)),
Property(
"PRESSURE",
if self.pressure.is_sign_positive() {