Working inspector

This commit is contained in:
2026-07-15 22:10:26 +02:00
parent a4f8e07be6
commit 278a660d5a
3 changed files with 105 additions and 5 deletions
+59 -2
View File
@@ -1,12 +1,69 @@
use crate::types::{
ActivePosition, Alert, AlertLevel, EventLog, LogKind, MarketOverview, Signal, SignalKind,
Status, WatchListItem,
ActivePosition, Alert, AlertLevel, EventLog, InspectTarget, LogKind, MarketOverview, Signal,
SignalKind, Status, WatchListItem,
};
pub trait Formatted {
fn get_formatted(&self) -> Vec<String>;
}
impl Formatted for InspectTarget {
fn get_formatted(&self) -> Vec<String> {
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())),
]
.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)),
]
.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()),
]
.get_formatted(),
}
}
}
impl Formatted for Alert {
fn get_formatted(&self) -> Vec<String> {
vec![
+11 -3
View File
@@ -13,13 +13,16 @@ use pulse_ui::{
align::End,
input::{Input, InputState},
outline::{Outline, VLine},
spaced::{SpacedColumns, SpacedColumns2, SpacedRows2},
spaced::SpacedColumns,
},
};
use crate::{
formatting::{Formatted, apply_padding},
types::{ActivePosition, Alert, EventLog, MarketOverview, Signal, Status, WatchListItem},
types::{
ActivePosition, Alert, EventLog, InspectTarget, MarketOverview, Signal, Status,
WatchListItem,
},
};
pub struct PulseTradeApp {
@@ -30,6 +33,7 @@ pub struct PulseTradeApp {
signals: State<Vec<Signal>>,
market_overview: State<MarketOverview>,
status: State<Status>,
inspect: State<InspectTarget>,
}
impl App for PulseTradeApp {
@@ -232,7 +236,10 @@ impl App for PulseTradeApp {
),
(
LayoutItem::Widget(Size::Flex(1)),
Box::new(vec![" INSPECTOR"].join("\n")),
Box::new(format!(
" INSPECTOR\n{}",
apply_padding(self.inspect.lock().await.get_formatted()).join("\n")
)),
),
(
LayoutItem::Widget(Size::Flex(1)),
@@ -264,6 +271,7 @@ async fn main() {
active_positions: ctx.use_state(Vec::new()),
signals: ctx.use_state(Vec::new()),
logs: ctx.use_state(Vec::new()),
inspect: ctx.use_state(InspectTarget::None),
market_overview: ctx.use_state(MarketOverview {
trend: types::MarketTrend::Bullish,
volatility: types::Volatility::High,
+35
View File
@@ -95,3 +95,38 @@ pub struct Alert {
pub level: AlertLevel,
pub message: String,
}
#[derive(Debug, Clone)]
pub enum InspectTarget {
None,
Symbol {
symbol: String,
price: f64,
trend: f64,
market_trend: MarketTrend,
volatility: Volatility,
pressure: f64,
alerts: Vec<Alert>,
},
Position {
symbol: String,
profit: f64,
amount: f64,
},
Signal {
kind: SignalKind,
symbol: String,
param: SignalParameter,
price: f64,
},
Alert {
level: AlertLevel,
message: String,
},
}