From acb81b4f27db5f487f76d75c7c6336eecfb15bd5 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 25 Jul 2026 17:32:19 +0200 Subject: [PATCH] Improve timeframe and other stuff --- Cargo.toml | 3 +- pulse-wire/Cargo.toml | 2 +- pulse-wire/src/general.rs | 25 --------------- pulse-wire/src/terminal.rs | 4 +-- pulse-wire/src/units.rs | 64 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f70095e..8780172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ hypersdk = "0.2.14" serde_json = "1" rand = "0.8.7" toml = "1.1.3" -serde = { version = "1.0.229", features = ["serde_derive"] } +serde = { workspace = true } [workspace] members = ["pulse-macros", "pulse-ui", "pulse-wire"] @@ -33,6 +33,7 @@ pulse-wire = { path = "pulse-wire", version = "0.1.0-alpha.0" } tokio = "1.52.3" crossterm = "0.29.0" +serde = { version = "1.0.229", features = ["serde_derive"] } [[bin]] name = "pulse-trader" diff --git a/pulse-wire/Cargo.toml b/pulse-wire/Cargo.toml index 10ed64f..81b1d0c 100644 --- a/pulse-wire/Cargo.toml +++ b/pulse-wire/Cargo.toml @@ -5,4 +5,4 @@ edition = "2024" [dependencies] pulse-macros = { workspace = true } -serde = { version = "1.0.229", features = ["serde_derive"] } +serde = { workspace = true } diff --git a/pulse-wire/src/general.rs b/pulse-wire/src/general.rs index 78ca796..353cb24 100644 --- a/pulse-wire/src/general.rs +++ b/pulse-wire/src/general.rs @@ -12,13 +12,6 @@ pub enum MarketTrend { Neutral, } -#[pwp] -pub enum Volatility { - Low, - Medium, - High, -} - #[pwp] pub enum LogKind { Info, @@ -53,15 +46,6 @@ pub struct Position { pub profit: USD, } -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 { @@ -72,15 +56,6 @@ impl std::fmt::Display for MarketTrend { } } -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 { diff --git a/pulse-wire/src/terminal.rs b/pulse-wire/src/terminal.rs index 6851c2d..c137889 100644 --- a/pulse-wire/src/terminal.rs +++ b/pulse-wire/src/terminal.rs @@ -1,8 +1,8 @@ use crate::{ PulseWire, - general::{EventLog, MarketTrend, Position, Signal, Volatility}, + general::{EventLog, MarketTrend, Position, Signal}, strategy::{Risk, Strategy}, - units::{Symbol, USD}, + units::{Symbol, USD, Volatility}, }; use pulse_macros::pwp; diff --git a/pulse-wire/src/units.rs b/pulse-wire/src/units.rs index a59c668..06e84ae 100644 --- a/pulse-wire/src/units.rs +++ b/pulse-wire/src/units.rs @@ -11,22 +11,36 @@ pub struct USD(pub f64); #[pwp] #[derive(Copy, serde::Deserialize, serde::Serialize)] pub enum TimeFrame { + #[serde(rename = "1m")] M1, + #[serde(rename = "3m")] M3, + #[serde(rename = "5m")] M5, + #[serde(rename = "15m")] M15, + #[serde(rename = "30m")] M30, + #[serde(rename = "1h")] H1, + #[serde(rename = "2h")] H2, + #[serde(rename = "4h")] H4, + #[serde(rename = "8h")] H8, + #[serde(rename = "12h")] H12, + #[serde(rename = "1d")] D1, + #[serde(rename = "3d")] D3, + #[serde(rename = "1w")] W1, + #[serde(rename = "1M")] Month1, } @@ -36,6 +50,13 @@ pub enum Direction { Sell, } +#[pwp] +pub enum Volatility { + Low, + Medium, + High, +} + impl std::fmt::Display for Symbol { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "\x1b[35m{}\x1b[0m", self.0) @@ -126,3 +147,46 @@ pub fn format_f64(value: f64) -> String { formatted } + +impl TimeFrame { + pub fn as_str(&self) -> &'static str { + match self { + Self::M1 => "1m", + Self::M3 => "3m", + Self::M5 => "5m", + Self::M15 => "15m", + Self::M30 => "30m", + + Self::H1 => "1h", + Self::H2 => "2h", + Self::H4 => "4h", + Self::H8 => "8h", + Self::H12 => "12h", + + Self::D1 => "1d", + Self::D3 => "3d", + + Self::W1 => "1w", + Self::Month1 => "1M", + } + } +} + +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 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"), + } + } +}