Tidy up
This commit is contained in:
+2
-2
@@ -6,7 +6,7 @@ impl PulseTradeApp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (command, args) = if let Some((command, args)) = command.split_once(" ") {
|
let (command, _args) = if let Some((command, args)) = command.split_once(" ") {
|
||||||
(command, args.split(" ").collect())
|
(command, args.split(" ").collect())
|
||||||
} else {
|
} else {
|
||||||
(command, Vec::new())
|
(command, Vec::new())
|
||||||
@@ -19,7 +19,7 @@ impl PulseTradeApp {
|
|||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
self.logs.lock().await.push(EventLog {
|
self.logs.lock().await.push(EventLog {
|
||||||
kind: crate::types::LogKind::ERR,
|
kind: crate::types::LogKind::Err,
|
||||||
name: "cmd",
|
name: "cmd",
|
||||||
message: format!("Command '{}' not found", command),
|
message: format!("Command '{}' not found", command),
|
||||||
});
|
});
|
||||||
|
|||||||
+45
-56
@@ -12,52 +12,41 @@ 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 {
|
Self::Symbol(boxed) => {
|
||||||
symbol,
|
let (watch, overview) = &**boxed;
|
||||||
price,
|
vec![
|
||||||
trend,
|
Property("Symbol", format!("\x1b[35m{}\x1b[0m", watch.symbol)),
|
||||||
market_trend,
|
Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(watch.price))),
|
||||||
volatility,
|
Property("Trend", format!("{}", format_f64(watch.trend))),
|
||||||
pressure,
|
Property("Market", format!("{}", overview.trend)),
|
||||||
alerts,
|
Property("Volatility", format!("{}", overview.volatility)),
|
||||||
} => vec![
|
Property(
|
||||||
Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)),
|
"Pressure",
|
||||||
Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(*price))),
|
format!("{:+.2}%", overview.pressure * 100.0),
|
||||||
Property("Trend", format!("{}", format_f64(*trend))),
|
),
|
||||||
Property("Market", format!("{:?}", market_trend)),
|
Property("Alerts", format!("{}", overview.alerts.len())),
|
||||||
Property("Volatility", format!("{:?}", volatility)),
|
]
|
||||||
Property("Pressure", format!("{:+.2}%", pressure * 100.0)),
|
.get_formatted()
|
||||||
Property("Alerts", format!("{}", alerts.len())),
|
}
|
||||||
|
|
||||||
|
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(),
|
.get_formatted(),
|
||||||
|
|
||||||
Self::Position {
|
Self::Signal(sig) => vec![
|
||||||
symbol,
|
Property("Type", format!("{}", sig.kind)),
|
||||||
profit,
|
Property("Symbol", format!("\x1b[35m{}\x1b[0m", sig.symbol)),
|
||||||
amount,
|
Property("Parameter", format!("{}", sig.param)),
|
||||||
} => vec![
|
Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(sig.price))),
|
||||||
Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)),
|
|
||||||
Property("Profit", format!("{:+.2}", profit)),
|
|
||||||
Property("Amount", format!("{}", amount)),
|
|
||||||
]
|
]
|
||||||
.get_formatted(),
|
.get_formatted(),
|
||||||
|
|
||||||
Self::Signal {
|
Self::Alert(alert) => vec![
|
||||||
kind,
|
Property("Level", format!("{}", alert.level)),
|
||||||
symbol,
|
Property("Message", alert.message.clone()),
|
||||||
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(),
|
.get_formatted(),
|
||||||
}
|
}
|
||||||
@@ -68,11 +57,11 @@ impl Formatted for Alert {
|
|||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
format!(
|
format!(
|
||||||
"{}{:?}\x1b[0m",
|
"{}{}\x1b[0m",
|
||||||
match &self.level {
|
match &self.level {
|
||||||
AlertLevel::L => "\x1b[34m",
|
AlertLevel::Low => "\x1b[34m",
|
||||||
AlertLevel::M => "\x1b[33m",
|
AlertLevel::Medium => "\x1b[33m",
|
||||||
AlertLevel::H => "\x1b[31m",
|
AlertLevel::High => "\x1b[31m",
|
||||||
},
|
},
|
||||||
self.level
|
self.level
|
||||||
),
|
),
|
||||||
@@ -85,12 +74,12 @@ impl Formatted for EventLog {
|
|||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
format!(
|
format!(
|
||||||
"{}{:?}\x1b[0m",
|
"{}{}\x1b[0m",
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
LogKind::INFO => "\x1b[34m",
|
LogKind::Info => "\x1b[34m",
|
||||||
LogKind::DEBUG => "\x1b[36m",
|
LogKind::Debug => "\x1b[36m",
|
||||||
LogKind::ERR => "\x1b[31m",
|
LogKind::Err => "\x1b[31m",
|
||||||
LogKind::WARN => "\x1b[33m",
|
LogKind::Warn => "\x1b[33m",
|
||||||
},
|
},
|
||||||
self.kind
|
self.kind
|
||||||
),
|
),
|
||||||
@@ -103,13 +92,13 @@ impl Formatted for EventLog {
|
|||||||
impl Formatted for Signal {
|
impl Formatted for Signal {
|
||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
if matches!(self.kind, SignalKind::BUY) {
|
if matches!(self.kind, SignalKind::Buy) {
|
||||||
format!("\x1b[32m{:?}\x1b[0m", self.kind)
|
format!("\x1b[32m{}\x1b[0m", self.kind)
|
||||||
} else {
|
} else {
|
||||||
format!("\x1b[31m{:?}\x1b[0m", self.kind)
|
format!("\x1b[31m{}\x1b[0m", self.kind)
|
||||||
},
|
},
|
||||||
format!("\x1b[35m{}\x1b[0m", self.symbol),
|
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),
|
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 {
|
impl Formatted for MarketOverview {
|
||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
Property("TREND", format!("{:?}", self.trend)),
|
Property("TREND", format!("{}", self.trend)),
|
||||||
Property("VOLATILITY", format!("{:?}", self.volatility)),
|
Property("VOLATILITY", format!("{}", self.volatility)),
|
||||||
Property(
|
Property(
|
||||||
"PRESSURE",
|
"PRESSURE",
|
||||||
if self.pressure.is_sign_positive() {
|
if self.pressure.is_sign_positive() {
|
||||||
|
|||||||
+17
-17
@@ -88,30 +88,30 @@ impl App for PulseTradeApp {
|
|||||||
let mut signals = self.signals.lock().await;
|
let mut signals = self.signals.lock().await;
|
||||||
|
|
||||||
signals.push(Signal {
|
signals.push(Signal {
|
||||||
kind: types::SignalKind::BUY,
|
kind: types::SignalKind::Buy,
|
||||||
symbol: "BTC".to_string(),
|
symbol: "BTC".to_string(),
|
||||||
param: types::SignalParameter::LIM,
|
param: types::SignalParameter::Lim,
|
||||||
price: 118_800.0,
|
price: 118_800.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
signals.push(Signal {
|
signals.push(Signal {
|
||||||
kind: types::SignalKind::BUY,
|
kind: types::SignalKind::Buy,
|
||||||
symbol: "BTC".to_string(),
|
symbol: "BTC".to_string(),
|
||||||
param: types::SignalParameter::TAP,
|
param: types::SignalParameter::Tap,
|
||||||
price: 120_000.0,
|
price: 120_000.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
signals.push(Signal {
|
signals.push(Signal {
|
||||||
kind: types::SignalKind::BUY,
|
kind: types::SignalKind::Buy,
|
||||||
symbol: "BTC".to_string(),
|
symbol: "BTC".to_string(),
|
||||||
param: types::SignalParameter::STL,
|
param: types::SignalParameter::Stl,
|
||||||
price: 118_000.0,
|
price: 118_000.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut logs = self.logs.lock().await;
|
let mut logs = self.logs.lock().await;
|
||||||
|
|
||||||
logs.push(EventLog {
|
logs.push(EventLog {
|
||||||
kind: types::LogKind::WARN,
|
kind: types::LogKind::Warn,
|
||||||
name: "pulse.init",
|
name: "pulse.init",
|
||||||
message: "We're still not done yet ;)".to_string(),
|
message: "We're still not done yet ;)".to_string(),
|
||||||
});
|
});
|
||||||
@@ -119,17 +119,17 @@ impl App for PulseTradeApp {
|
|||||||
let mut market_overview = self.market_overview.lock().await;
|
let mut market_overview = self.market_overview.lock().await;
|
||||||
|
|
||||||
market_overview.alerts.push(Alert {
|
market_overview.alerts.push(Alert {
|
||||||
level: types::AlertLevel::H,
|
level: types::AlertLevel::High,
|
||||||
message: "BTC funding rate elevated".to_string(),
|
message: "BTC funding rate elevated".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
market_overview.alerts.push(Alert {
|
market_overview.alerts.push(Alert {
|
||||||
level: types::AlertLevel::M,
|
level: types::AlertLevel::Medium,
|
||||||
message: "Market volatility increasing".to_string(),
|
message: "Market volatility increasing".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
market_overview.alerts.push(Alert {
|
market_overview.alerts.push(Alert {
|
||||||
level: types::AlertLevel::L,
|
level: types::AlertLevel::Low,
|
||||||
message: "ETH volatility returning to normal".to_string(),
|
message: "ETH volatility returning to normal".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -224,11 +224,11 @@ impl App for PulseTradeApp {
|
|||||||
),
|
),
|
||||||
(LayoutItem::Widget(Size::Flex(1)), {
|
(LayoutItem::Widget(Size::Flex(1)), {
|
||||||
let mo = self.market_overview.lock().await;
|
let mo = self.market_overview.lock().await;
|
||||||
Box::new(format![
|
Box::new(format!(
|
||||||
" MARKET OVERVIEW\n{}\n\n{}",
|
" MARKET OVERVIEW\n{}\n\n{}",
|
||||||
apply_padding(mo.get_formatted()).join("\n"),
|
apply_padding(mo.get_formatted()).join("\n"),
|
||||||
apply_padding(mo.alerts.get_formatted(),).join("\n")
|
apply_padding(mo.alerts.get_formatted()).join("\n")
|
||||||
])
|
))
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
@@ -252,20 +252,20 @@ impl App for PulseTradeApp {
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
LayoutItem::Widget(Size::Flex(1)),
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
Box::new(format![
|
Box::new(format!(
|
||||||
" STATUS\n{}",
|
" STATUS\n{}",
|
||||||
apply_padding(self.status.lock().await.get_formatted()).join("\n")
|
apply_padding(self.status.lock().await.get_formatted()).join("\n")
|
||||||
]),
|
)),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
layout.draw(
|
layout.draw(
|
||||||
5,
|
5,
|
||||||
format![
|
format!(
|
||||||
" EVENT LOGS\n{}",
|
" EVENT LOGS\n{}",
|
||||||
apply_padding(self.logs.lock().await.get_formatted()).join("\n")
|
apply_padding(self.logs.lock().await.get_formatted()).join("\n")
|
||||||
],
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
layout.draw(6, Input(" > ", &*self.command.lock().await));
|
layout.draw(6, Input(" > ", &*self.command.lock().await));
|
||||||
|
|||||||
+82
-43
@@ -1,9 +1,11 @@
|
|||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct WatchListItem {
|
pub struct WatchListItem {
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
pub price: f64,
|
pub price: f64,
|
||||||
pub trend: f64,
|
pub trend: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct ActivePosition {
|
pub struct ActivePosition {
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
pub profit: f64,
|
pub profit: f64,
|
||||||
@@ -17,6 +19,16 @@ pub enum MarketTrend {
|
|||||||
Neutral,
|
Neutral,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for MarketTrend {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Bullish => write!(f, "Bullish"),
|
||||||
|
Self::Bearish => write!(f, "Bearish"),
|
||||||
|
Self::Neutral => write!(f, "Neutral"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Volatility {
|
pub enum Volatility {
|
||||||
Low,
|
Low,
|
||||||
@@ -24,6 +36,17 @@ pub enum Volatility {
|
|||||||
High,
|
High,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Volatility {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Low => write!(f, "Low"),
|
||||||
|
Self::Medium => write!(f, "Medium"),
|
||||||
|
Self::High => write!(f, "High"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct MarketOverview {
|
pub struct MarketOverview {
|
||||||
pub trend: MarketTrend,
|
pub trend: MarketTrend,
|
||||||
pub volatility: Volatility,
|
pub volatility: Volatility,
|
||||||
@@ -49,18 +72,39 @@ pub struct Status {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum SignalKind {
|
pub enum SignalKind {
|
||||||
BUY,
|
Buy,
|
||||||
SELL,
|
Sell,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for SignalKind {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Buy => write!(f, "BUY"),
|
||||||
|
Self::Sell => write!(f, "SELL"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum SignalParameter {
|
pub enum SignalParameter {
|
||||||
LIM,
|
Lim,
|
||||||
STL,
|
Stl,
|
||||||
TAP,
|
Tap,
|
||||||
CHK,
|
Chk,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for SignalParameter {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Lim => write!(f, "LIM"),
|
||||||
|
Self::Stl => write!(f, "STL"),
|
||||||
|
Self::Tap => write!(f, "TAP"),
|
||||||
|
Self::Chk => write!(f, "CHK"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct Signal {
|
pub struct Signal {
|
||||||
pub kind: SignalKind,
|
pub kind: SignalKind,
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
@@ -70,10 +114,21 @@ pub struct Signal {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum LogKind {
|
pub enum LogKind {
|
||||||
INFO,
|
Info,
|
||||||
WARN,
|
Warn,
|
||||||
ERR,
|
Err,
|
||||||
DEBUG,
|
Debug,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for LogKind {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Info => write!(f, "INFO"),
|
||||||
|
Self::Warn => write!(f, "WARN"),
|
||||||
|
Self::Err => write!(f, "ERR"),
|
||||||
|
Self::Debug => write!(f, "DEBUG"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -85,9 +140,19 @@ pub struct EventLog {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum AlertLevel {
|
pub enum AlertLevel {
|
||||||
H,
|
High,
|
||||||
M,
|
Medium,
|
||||||
L,
|
Low,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for AlertLevel {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::High => write!(f, "H"),
|
||||||
|
Self::Medium => write!(f, "M"),
|
||||||
|
Self::Low => write!(f, "L"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -99,34 +164,8 @@ pub struct Alert {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum InspectTarget {
|
pub enum InspectTarget {
|
||||||
None,
|
None,
|
||||||
|
Symbol(Box<(WatchListItem, MarketOverview)>),
|
||||||
Symbol {
|
Position(ActivePosition),
|
||||||
symbol: String,
|
Signal(Signal),
|
||||||
price: f64,
|
Alert(Alert),
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user