From a37d21afd1868e0c4c0f873db362b6ba130f4f7a Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 15 Jul 2026 08:34:20 -0400 Subject: [PATCH] Signals --- src/formatting.rs | 21 ++++++++++++++++++--- src/main.rs | 43 ++++++++++++++++++++++++++++++++----------- src/types.rs | 21 +++++++++++++++++++++ 3 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index c05f91f..d01c9c3 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,13 +1,28 @@ -use crate::types::{Account, ActivePosition, System, WatchListItem}; +use crate::types::{Account, ActivePosition, Signal, SignalKind, System, WatchListItem}; pub trait Formatted { fn get_formatted(&self) -> Vec; } +impl Formatted for Signal { + fn get_formatted(&self) -> Vec { + vec![ + if matches!(self.kind, SignalKind::BUY) { + format!("\x1b[32m{:?}\x1b[0m", self.kind) + } else { + format!("\x1b[31m{:?}\x1b[0m", self.kind) + }, + format!("\x1b[35m{}\x1b[0m", self.symbol), + format!("\x1b[34m{:?}\x1b[0m", self.param), + format_f64(self.price), + ] + } +} + impl Formatted for WatchListItem { fn get_formatted(&self) -> Vec { vec![ - format!("\x1b[35m{}\x1b[0m", self.symbol.to_string()), + format!("\x1b[35m{}\x1b[0m", self.symbol), format_f64(self.price), format!( "{} {}", @@ -25,7 +40,7 @@ impl Formatted for WatchListItem { impl Formatted for ActivePosition { fn get_formatted(&self) -> Vec { vec![ - format!("\x1b[35m{}\x1b[0m", self.symbol.to_string()), + format!("\x1b[35m{}\x1b[0m", self.symbol), format_f64(self.amount), format!( "{} {}", diff --git a/src/main.rs b/src/main.rs index 646219a..0406138 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,13 +18,14 @@ use pulse_ui::{ use crate::{ formatting::{Formatted, apply_padding}, - types::{Account, ActivePosition, System, WatchListItem}, + types::{Account, ActivePosition, Signal, System, WatchListItem}, }; pub struct PulseTradeApp { command: State, watch_list: State>, active_positions: State>, + signals: State>, account: State, system: State, } @@ -76,6 +77,29 @@ impl App for PulseTradeApp { profit: 12.30, amount: 0.75, }); + + let mut signals = self.signals.lock().await; + + signals.push(Signal { + kind: types::SignalKind::BUY, + symbol: "BTC".to_string(), + param: types::SignalParameter::LIM, + price: 118_800.0, + }); + + signals.push(Signal { + kind: types::SignalKind::BUY, + symbol: "BTC".to_string(), + param: types::SignalParameter::TAP, + price: 120_000.0, + }); + + signals.push(Signal { + kind: types::SignalKind::BUY, + symbol: "BTC".to_string(), + param: types::SignalParameter::STL, + price: 118_000.0, + }); } async fn update(&mut self, ctx: &pulse_ui::state::Context, event: Box) { @@ -167,22 +191,18 @@ impl App for PulseTradeApp { ), ( LayoutItem::Widget(Size::Flex(1)), - Box::new( - vec![ - " SIGNALS", - " BUY BTC LIM 118,800.12", - " BUY BTC STL 118,000.00", - " BUY BTC TAP 120,000.00", - ] - .join("\n"), - ), + Box::new(format!( + " SIGNALS\n{}", + apply_padding(self.signals.lock().await.get_formatted()) + .join("\n") + )), ), ( LayoutItem::Widget(Size::Flex(1)), Box::new(format![ " SYSTEM\n{}", apply_padding(self.system.lock().await.get_formatted()).join("\n") - ]), + ]), ), ]), ); @@ -197,6 +217,7 @@ async fn main() { command: ctx.use_state(InputState::new()), watch_list: ctx.use_state(Vec::new()), active_positions: ctx.use_state(Vec::new()), + signals: ctx.use_state(Vec::new()), account: ctx.use_state(Account { equity: 25_483.21, liquid: 11_928.43, diff --git a/src/types.rs b/src/types.rs index 7167380..d294fe9 100644 --- a/src/types.rs +++ b/src/types.rs @@ -32,3 +32,24 @@ pub struct System { pub dex: String, pub latency: u16, } + +#[derive(Debug, Clone, Copy)] +pub enum SignalKind { + BUY, + SELL, +} + +#[derive(Debug, Clone, Copy)] +pub enum SignalParameter { + LIM, + STL, + TAP, + CHK, +} + +pub struct Signal { + pub kind: SignalKind, + pub symbol: String, + pub param: SignalParameter, + pub price: f64, +}