Better signal formatting

This commit is contained in:
2026-08-02 00:19:47 +02:00
parent 51998aad68
commit 05cf081339
3 changed files with 117 additions and 118 deletions
+17 -18
View File
@@ -54,31 +54,22 @@ impl Formatted for EventLog {
impl Formatted for SignalStatus {
fn get_formatted(&self) -> Vec<String> {
match self {
Ok(signal) => {
Ok(signal) | Err(signal) => {
vec![
format!("\x1b[33mOK\x1b[0m"),
if matches!(signal.side, Side::Ask) {
if matches!(self, Ok(_)) {
format!("\x1b[34mOK\x1b[0m")
} else {
format!("\x1b[31mREJ\x1b[0m")
},
if matches!(signal.side, Side::Bid) {
format!("\x1b[32mBUY\x1b[0m")
} else {
format!("\x1b[31mSELL\x1b[0m")
},
format_symbol(&signal.symbol),
format_usd(signal.entry_price.as_f64()),
format!("\x1b[33mAPR {}\x1b[0m", signal.confidence),
]
}
Err(signal) => {
vec![
format!("\x1b[31mERR\x1b[0m"),
if matches!(signal.side, Side::Ask) {
format!("\x1b[32mBUY\x1b[0m")
} else {
format!("\x1b[31mSELL\x1b[0m")
},
format_symbol(&signal.symbol),
format_usd(signal.entry_price.as_f64()),
format!("\x1b[33mAPR {}\x1b[0m", signal.confidence),
format_usd(signal.take_profit.as_f64()),
format_usd_reverse(signal.stop_loss.as_f64()),
]
}
}
@@ -274,6 +265,14 @@ pub fn format_usd(value: f64) -> String {
}
}
pub fn format_usd_reverse(value: f64) -> String {
if value.is_sign_positive() {
format!("\x1b[31m${}\x1b[0m", format_f64(value))
} else {
format!("\x1b[32m${}\x1b[0m", format_f64(value))
}
}
pub fn format_f64(value: f64) -> String {
let abs = value.abs();