109 lines
2.4 KiB
Rust
109 lines
2.4 KiB
Rust
use crate::{
|
|
general::{EventLog, Position, Signal},
|
|
strategy::StrategyManifest,
|
|
};
|
|
use hypersdk::{Decimal, hypercore::CandleInterval};
|
|
|
|
pub type SignalStatus = Result<Signal, Signal>;
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub enum TerminalServerMessage {
|
|
// WatchList
|
|
WatchListUpdated(Vec<MarketItem>),
|
|
|
|
// Positions
|
|
PositionsUpdated(Vec<Position>),
|
|
|
|
// Strategy
|
|
StrategyUpdated(StrategyStatus),
|
|
|
|
// Signals
|
|
SignalsUpdated(Vec<SignalStatus>),
|
|
|
|
// Inspector
|
|
Inspect(InspectTarget),
|
|
|
|
// Status
|
|
StatusUpdated(Status),
|
|
|
|
// Logs
|
|
SetLogs(Vec<EventLog>),
|
|
AddLog(EventLog),
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub enum TerminalClientMessage {
|
|
ExecuteCommand(String),
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct MarketItem {
|
|
pub symbol: String,
|
|
pub price: Decimal,
|
|
pub trend: Decimal,
|
|
pub volume_24h: Decimal,
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub enum InspectTarget {
|
|
None,
|
|
Some(Vec<InspectItem>),
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub enum InspectItem {
|
|
String(String),
|
|
Symbol(String),
|
|
USD(f64),
|
|
F64(f64),
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct Status {
|
|
pub feed: Mode,
|
|
pub exchange: String,
|
|
pub dex: String,
|
|
pub latency: u16,
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub enum Mode {
|
|
Auto,
|
|
Manual,
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub enum ItemState {
|
|
Running,
|
|
Stopped,
|
|
Error,
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct StrategyStatus {
|
|
pub strategy: StrategyManifest,
|
|
|
|
pub mode: Mode,
|
|
pub state: ItemState,
|
|
pub cooldown: CandleInterval,
|
|
}
|
|
|
|
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::Stopped => write!(f, "\x1b[90mSTOPPED\x1b[0m"),
|
|
Self::Error => write!(f, "\x1b[91mERROR\x1b[0m"),
|
|
}
|
|
}
|
|
}
|