Pulse terminal communication
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{PulseTradeApp, types::EventLog};
|
||||
use crate::{PulseTradeApp, ptc::EventLog};
|
||||
|
||||
impl PulseTradeApp {
|
||||
pub async fn execute_command(&mut self, ctx: &pulse_ui::state::Context, command: &str) {
|
||||
@@ -19,7 +19,7 @@ impl PulseTradeApp {
|
||||
|
||||
_ => {
|
||||
self.logs.lock().await.push(EventLog {
|
||||
kind: crate::types::LogKind::Err,
|
||||
kind: crate::ptc::LogKind::Err,
|
||||
name: "cmd",
|
||||
message: format!("Command '{}' not found", command),
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::types::{
|
||||
use crate::ptc::{
|
||||
ActivePosition, Alert, AlertLevel, EventLog, InspectTarget, LogKind, MarketOverview, Signal,
|
||||
SignalKind, Status, WatchListItem,
|
||||
};
|
||||
|
||||
+15
-15
@@ -1,6 +1,6 @@
|
||||
pub mod command;
|
||||
pub mod formatting;
|
||||
pub mod types;
|
||||
pub mod ptc;
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
@@ -20,7 +20,7 @@ use pulse_ui::{
|
||||
|
||||
use crate::{
|
||||
formatting::{Formatted, apply_padding},
|
||||
types::{
|
||||
ptc::{
|
||||
ActivePosition, Alert, EventLog, InspectTarget, MarketOverview, Signal, Status,
|
||||
WatchListItem,
|
||||
},
|
||||
@@ -88,30 +88,30 @@ impl App for PulseTradeApp {
|
||||
let mut signals = self.signals.lock().await;
|
||||
|
||||
signals.push(Signal {
|
||||
kind: types::SignalKind::Buy,
|
||||
kind: ptc::SignalKind::Buy,
|
||||
symbol: "BTC".to_string(),
|
||||
param: types::SignalParameter::Lim,
|
||||
param: ptc::SignalParameter::Lim,
|
||||
price: 118_800.0,
|
||||
});
|
||||
|
||||
signals.push(Signal {
|
||||
kind: types::SignalKind::Buy,
|
||||
kind: ptc::SignalKind::Buy,
|
||||
symbol: "BTC".to_string(),
|
||||
param: types::SignalParameter::Tap,
|
||||
param: ptc::SignalParameter::Tap,
|
||||
price: 120_000.0,
|
||||
});
|
||||
|
||||
signals.push(Signal {
|
||||
kind: types::SignalKind::Buy,
|
||||
kind: ptc::SignalKind::Buy,
|
||||
symbol: "BTC".to_string(),
|
||||
param: types::SignalParameter::Stl,
|
||||
param: ptc::SignalParameter::Stl,
|
||||
price: 118_000.0,
|
||||
});
|
||||
|
||||
let mut logs = self.logs.lock().await;
|
||||
|
||||
logs.push(EventLog {
|
||||
kind: types::LogKind::Warn,
|
||||
kind: ptc::LogKind::Warn,
|
||||
name: "pulse.init",
|
||||
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;
|
||||
|
||||
market_overview.alerts.push(Alert {
|
||||
level: types::AlertLevel::High,
|
||||
level: ptc::AlertLevel::High,
|
||||
message: "BTC funding rate elevated".to_string(),
|
||||
});
|
||||
|
||||
market_overview.alerts.push(Alert {
|
||||
level: types::AlertLevel::Medium,
|
||||
level: ptc::AlertLevel::Medium,
|
||||
message: "Market volatility increasing".to_string(),
|
||||
});
|
||||
|
||||
market_overview.alerts.push(Alert {
|
||||
level: types::AlertLevel::Low,
|
||||
level: ptc::AlertLevel::Low,
|
||||
message: "ETH volatility returning to normal".to_string(),
|
||||
});
|
||||
}
|
||||
@@ -282,13 +282,13 @@ async fn main() {
|
||||
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,
|
||||
trend: ptc::MarketTrend::Bullish,
|
||||
volatility: ptc::Volatility::High,
|
||||
pressure: 0.324,
|
||||
alerts: Vec::new(),
|
||||
}),
|
||||
status: ctx.use_state(Status {
|
||||
feed: types::Feed::Connected,
|
||||
feed: ptc::Feed::Connected,
|
||||
exchange: "Binance".to_string(),
|
||||
dex: "DEX SCREENER".to_string(),
|
||||
latency: 18,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
include!("../ptc.rs");
|
||||
@@ -1,171 +0,0 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WatchListItem {
|
||||
pub symbol: String,
|
||||
pub price: f64,
|
||||
pub trend: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ActivePosition {
|
||||
pub symbol: String,
|
||||
pub profit: f64,
|
||||
pub amount: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum MarketTrend {
|
||||
Bullish,
|
||||
Bearish,
|
||||
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)]
|
||||
pub enum Volatility {
|
||||
Low,
|
||||
Medium,
|
||||
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 trend: MarketTrend,
|
||||
pub volatility: Volatility,
|
||||
pub pressure: f64,
|
||||
|
||||
pub alerts: Vec<Alert>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Feed {
|
||||
Connected,
|
||||
Disconnected,
|
||||
Connecting,
|
||||
Failed,
|
||||
}
|
||||
|
||||
pub struct Status {
|
||||
pub feed: Feed,
|
||||
pub exchange: String,
|
||||
pub dex: String,
|
||||
pub latency: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum SignalKind {
|
||||
Buy,
|
||||
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)]
|
||||
pub enum SignalParameter {
|
||||
Lim,
|
||||
Stl,
|
||||
Tap,
|
||||
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 kind: SignalKind,
|
||||
pub symbol: String,
|
||||
pub param: SignalParameter,
|
||||
pub price: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum LogKind {
|
||||
Info,
|
||||
Warn,
|
||||
Err,
|
||||
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)]
|
||||
pub struct EventLog {
|
||||
pub kind: LogKind,
|
||||
pub name: &'static str,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum AlertLevel {
|
||||
High,
|
||||
Medium,
|
||||
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)]
|
||||
pub struct Alert {
|
||||
pub level: AlertLevel,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum InspectTarget {
|
||||
None,
|
||||
Symbol(Box<(WatchListItem, MarketOverview)>),
|
||||
Position(ActivePosition),
|
||||
Signal(Signal),
|
||||
Alert(Alert),
|
||||
}
|
||||
Reference in New Issue
Block a user