147 lines
2.6 KiB
Rust
147 lines
2.6 KiB
Rust
use crate::{
|
|
PulseWire,
|
|
general::{EventLog, MarketTrend, Position, Signal},
|
|
strategy::{RiskManifest, StrategyManifest},
|
|
units::{Symbol, TimeFrame, USD, Volatility},
|
|
};
|
|
use pulse_macros::pwp;
|
|
|
|
#[pwp]
|
|
pub enum TerminalServerMessage {
|
|
// WatchList
|
|
WatchListUpdated(Vec<MarketItem>),
|
|
|
|
// Positions
|
|
PositionsUpdated(Vec<Position>),
|
|
|
|
// Strategy
|
|
StrategyUpdated(Strategy),
|
|
|
|
// Signals
|
|
SignalsUpdated(Vec<Signal>),
|
|
|
|
// Inspector
|
|
Inspect(InspectTarget),
|
|
|
|
// Status
|
|
StatusUpdated(Status),
|
|
|
|
// Logs
|
|
SetLogs(Vec<EventLog>),
|
|
AddLog(EventLog),
|
|
}
|
|
|
|
#[pwp]
|
|
pub enum TerminalClientMessage {
|
|
ExecuteCommand(String),
|
|
}
|
|
|
|
#[pwp]
|
|
pub struct MarketItem {
|
|
pub symbol: Symbol,
|
|
pub price: USD,
|
|
pub trend: f64,
|
|
pub volume_24h: USD,
|
|
}
|
|
|
|
#[pwp]
|
|
pub struct MarketOverview {
|
|
pub trend: MarketTrend,
|
|
pub volatility: Volatility,
|
|
pub pressure: f64,
|
|
pub alerts: Vec<Alert>,
|
|
}
|
|
|
|
#[pwp]
|
|
pub enum AlertLevel {
|
|
High,
|
|
Medium,
|
|
Low,
|
|
}
|
|
#[pwp]
|
|
pub struct Alert {
|
|
level: AlertLevel,
|
|
message: String,
|
|
}
|
|
|
|
#[pwp]
|
|
pub struct Balance {
|
|
pub asset: String,
|
|
pub amount: f64,
|
|
pub value: f64,
|
|
}
|
|
|
|
#[pwp]
|
|
pub enum InspectTarget {
|
|
None,
|
|
Some(Vec<InspectItem>),
|
|
}
|
|
|
|
#[pwp]
|
|
pub enum InspectItem {
|
|
String(String),
|
|
Symbol(String),
|
|
USD(f64),
|
|
F64(f64),
|
|
}
|
|
|
|
#[pwp]
|
|
pub struct Status {
|
|
feed: Mode,
|
|
exchange: String,
|
|
dex: String,
|
|
latency: u16,
|
|
}
|
|
|
|
#[pwp]
|
|
pub enum Mode {
|
|
Auto,
|
|
Manual,
|
|
}
|
|
|
|
#[pwp]
|
|
pub enum ItemState {
|
|
Running,
|
|
Off,
|
|
Error,
|
|
}
|
|
|
|
#[pwp]
|
|
pub struct Strategy {
|
|
strategy: StrategyManifest,
|
|
risk: RiskManifest,
|
|
|
|
mode: Mode,
|
|
state: ItemState,
|
|
cooldown: TimeFrame,
|
|
}
|
|
|
|
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"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for Mode {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Auto => write!(f, "\x1b[96mAUTO\x1b[0m"),
|
|
Self::Manual => write!(f, "\x1b[97mMANUAL\x1b[0m"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for ItemState {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Running => write!(f, "\x1b[92mRUNNING\x1b[0m"),
|
|
Self::Off => write!(f, "\x1b[90mOFF\x1b[0m"),
|
|
Self::Error => write!(f, "\x1b[91mERROR\x1b[0m"),
|
|
}
|
|
}
|
|
}
|