Improve timeframe and other stuff
This commit is contained in:
@@ -5,4 +5,4 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
pulse-macros = { workspace = true }
|
||||
serde = { version = "1.0.229", features = ["serde_derive"] }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user