Signals
This commit is contained in:
+18
-3
@@ -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<String>;
|
||||
}
|
||||
|
||||
impl Formatted for Signal {
|
||||
fn get_formatted(&self) -> Vec<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
vec![
|
||||
format!("\x1b[35m{}\x1b[0m", self.symbol.to_string()),
|
||||
format!("\x1b[35m{}\x1b[0m", self.symbol),
|
||||
format_f64(self.amount),
|
||||
format!(
|
||||
"{} {}",
|
||||
|
||||
+31
-10
@@ -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<InputState>,
|
||||
watch_list: State<Vec<WatchListItem>>,
|
||||
active_positions: State<Vec<ActivePosition>>,
|
||||
signals: State<Vec<Signal>>,
|
||||
account: State<Account>,
|
||||
system: State<System>,
|
||||
}
|
||||
@@ -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<dyn Any + Send + Sync>) {
|
||||
@@ -167,15 +191,11 @@ 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)),
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user