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 {
|
pub trait Formatted {
|
||||||
fn get_formatted(&self) -> Vec<String>;
|
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 {
|
impl Formatted for WatchListItem {
|
||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
format!("\x1b[35m{}\x1b[0m", self.symbol.to_string()),
|
format!("\x1b[35m{}\x1b[0m", self.symbol),
|
||||||
format_f64(self.price),
|
format_f64(self.price),
|
||||||
format!(
|
format!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
@@ -25,7 +40,7 @@ impl Formatted for WatchListItem {
|
|||||||
impl Formatted for ActivePosition {
|
impl Formatted for ActivePosition {
|
||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
format!("\x1b[35m{}\x1b[0m", self.symbol.to_string()),
|
format!("\x1b[35m{}\x1b[0m", self.symbol),
|
||||||
format_f64(self.amount),
|
format_f64(self.amount),
|
||||||
format!(
|
format!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
|
|||||||
+32
-11
@@ -18,13 +18,14 @@ use pulse_ui::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
formatting::{Formatted, apply_padding},
|
formatting::{Formatted, apply_padding},
|
||||||
types::{Account, ActivePosition, System, WatchListItem},
|
types::{Account, ActivePosition, Signal, System, WatchListItem},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PulseTradeApp {
|
pub struct PulseTradeApp {
|
||||||
command: State<InputState>,
|
command: State<InputState>,
|
||||||
watch_list: State<Vec<WatchListItem>>,
|
watch_list: State<Vec<WatchListItem>>,
|
||||||
active_positions: State<Vec<ActivePosition>>,
|
active_positions: State<Vec<ActivePosition>>,
|
||||||
|
signals: State<Vec<Signal>>,
|
||||||
account: State<Account>,
|
account: State<Account>,
|
||||||
system: State<System>,
|
system: State<System>,
|
||||||
}
|
}
|
||||||
@@ -76,6 +77,29 @@ impl App for PulseTradeApp {
|
|||||||
profit: 12.30,
|
profit: 12.30,
|
||||||
amount: 0.75,
|
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>) {
|
async fn update(&mut self, ctx: &pulse_ui::state::Context, event: Box<dyn Any + Send + Sync>) {
|
||||||
@@ -167,22 +191,18 @@ impl App for PulseTradeApp {
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
LayoutItem::Widget(Size::Flex(1)),
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
Box::new(
|
Box::new(format!(
|
||||||
vec![
|
" SIGNALS\n{}",
|
||||||
" SIGNALS",
|
apply_padding(self.signals.lock().await.get_formatted())
|
||||||
" BUY BTC LIM 118,800.12",
|
.join("\n")
|
||||||
" BUY BTC STL 118,000.00",
|
)),
|
||||||
" BUY BTC TAP 120,000.00",
|
|
||||||
]
|
|
||||||
.join("\n"),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
LayoutItem::Widget(Size::Flex(1)),
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
Box::new(format![
|
Box::new(format![
|
||||||
" SYSTEM\n{}",
|
" SYSTEM\n{}",
|
||||||
apply_padding(self.system.lock().await.get_formatted()).join("\n")
|
apply_padding(self.system.lock().await.get_formatted()).join("\n")
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
@@ -197,6 +217,7 @@ async fn main() {
|
|||||||
command: ctx.use_state(InputState::new()),
|
command: ctx.use_state(InputState::new()),
|
||||||
watch_list: ctx.use_state(Vec::new()),
|
watch_list: ctx.use_state(Vec::new()),
|
||||||
active_positions: ctx.use_state(Vec::new()),
|
active_positions: ctx.use_state(Vec::new()),
|
||||||
|
signals: ctx.use_state(Vec::new()),
|
||||||
account: ctx.use_state(Account {
|
account: ctx.use_state(Account {
|
||||||
equity: 25_483.21,
|
equity: 25_483.21,
|
||||||
liquid: 11_928.43,
|
liquid: 11_928.43,
|
||||||
|
|||||||
@@ -32,3 +32,24 @@ pub struct System {
|
|||||||
pub dex: String,
|
pub dex: String,
|
||||||
pub latency: u16,
|
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