Refactored types
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
use pulse_macros::pwp;
|
||||
|
||||
use crate::PulseWire;
|
||||
|
||||
#[pwp]
|
||||
pub enum MarketTrend {
|
||||
Bullish,
|
||||
Bearish,
|
||||
Neutral,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum Volatility {
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum Direction {
|
||||
Buy,
|
||||
Sell,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct Signal {
|
||||
pub symbol: String,
|
||||
pub kind: Direction,
|
||||
pub confidence: f32,
|
||||
pub size: f64,
|
||||
pub price: f64,
|
||||
pub take_profit: f64,
|
||||
pub take_stop_loss: f64,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum LogKind {
|
||||
Info,
|
||||
Warn,
|
||||
Err,
|
||||
Debug,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct EventLog {
|
||||
pub kind: LogKind,
|
||||
pub name: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct Position {
|
||||
pub symbol: String,
|
||||
pub size: f64,
|
||||
pub entry_price: f64,
|
||||
pub profit: f64,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Direction {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Buy => write!(f, "BUY"),
|
||||
Self::Sell => write!(f, "SELL"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod terminal;
|
||||
pub mod general;
|
||||
|
||||
pub fn server_path() -> PathBuf {
|
||||
PathBuf::from("/tmp/pulse-engine.sock")
|
||||
|
||||
+35
-137
@@ -1,13 +1,16 @@
|
||||
use crate::PulseWire;
|
||||
use crate::{
|
||||
PulseWire,
|
||||
general::{EventLog, MarketTrend, Position, Signal, Volatility},
|
||||
};
|
||||
use pulse_macros::pwp;
|
||||
|
||||
#[pwp]
|
||||
pub enum TerminalServerMessage {
|
||||
// WatchList
|
||||
WatchListUpdated(Vec<WatchListItem>),
|
||||
WatchListUpdated(Vec<MarketItem>),
|
||||
|
||||
// Positions
|
||||
PositionsUpdated(Vec<ActivePosition>),
|
||||
PositionsUpdated(Vec<Position>),
|
||||
|
||||
// Overview
|
||||
OverviewUpdated(MarketOverview),
|
||||
@@ -32,95 +35,19 @@ pub enum TerminalClientMessage {
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct WatchListItem {
|
||||
symbol: String,
|
||||
price: f64,
|
||||
trend: f64,
|
||||
volume_24h: f64,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct ActivePosition {
|
||||
pub struct MarketItem {
|
||||
pub symbol: String,
|
||||
pub size: f64,
|
||||
pub entry_price: f64,
|
||||
pub profit: f64,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum MarketTrend {
|
||||
Bullish,
|
||||
Bearish,
|
||||
Neutral,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum Volatility {
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
pub price: f64,
|
||||
pub trend: f64,
|
||||
pub volume_24h: f64,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct MarketOverview {
|
||||
trend: MarketTrend,
|
||||
volatility: Volatility,
|
||||
pressure: f64,
|
||||
|
||||
alerts: Vec<Alert>,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum Feed {
|
||||
Connected,
|
||||
Disconnected,
|
||||
Connecting,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct Status {
|
||||
feed: Feed,
|
||||
exchange: String,
|
||||
dex: String,
|
||||
latency: u16,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum SignalKind {
|
||||
Buy,
|
||||
Sell,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum SignalParameter {
|
||||
Lim,
|
||||
Stl,
|
||||
Tap,
|
||||
Chk,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct Signal {
|
||||
kind: SignalKind,
|
||||
symbol: String,
|
||||
param: SignalParameter,
|
||||
price: f64,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum LogKind {
|
||||
Info,
|
||||
Warn,
|
||||
Err,
|
||||
Debug,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct EventLog {
|
||||
kind: LogKind,
|
||||
name: String,
|
||||
message: String,
|
||||
pub trend: MarketTrend,
|
||||
pub volatility: Volatility,
|
||||
pub pressure: f64,
|
||||
pub alerts: Vec<Alert>,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
@@ -129,13 +56,19 @@ pub enum AlertLevel {
|
||||
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,
|
||||
@@ -150,14 +83,20 @@ pub enum InspectItem {
|
||||
F64(f64),
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
#[pwp]
|
||||
pub struct Status {
|
||||
feed: Feed,
|
||||
exchange: String,
|
||||
dex: String,
|
||||
latency: u16,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum Feed {
|
||||
Connected,
|
||||
Disconnected,
|
||||
Connecting,
|
||||
Failed,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AlertLevel {
|
||||
@@ -169,44 +108,3 @@ impl std::fmt::Display for AlertLevel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user