This commit is contained in:
2026-07-30 04:44:21 +02:00
parent 8dcf6b2a41
commit 87e3c2b964
8 changed files with 95 additions and 236 deletions
+9 -11
View File
@@ -1,7 +1,6 @@
use hypersdk::hypercore::Side;
use rust_decimal::Decimal;
use crate::units::{Direction, Symbol, USD};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum MarketTrend {
Bullish,
@@ -20,12 +19,11 @@ pub enum LogKind {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Signal {
pub symbol: String,
pub kind: Direction,
pub side: Side,
pub confidence: f32,
pub size: Decimal,
pub price: USD,
pub take_profit: USD,
pub stop_loss: USD,
pub price: Decimal,
pub take_profit: Decimal,
pub stop_loss: Decimal,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -37,10 +35,10 @@ pub struct EventLog {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Position {
pub symbol: Symbol,
pub size: f64,
pub entry_price: USD,
pub profit: USD,
pub symbol: String,
pub size: Decimal,
pub entry_price: Decimal,
pub pnl: Decimal,
}
impl std::fmt::Display for MarketTrend {
+1 -3
View File
@@ -1,7 +1,6 @@
pub mod general;
pub mod strategy;
pub mod terminal;
pub mod units;
pub use hypersdk;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -10,10 +9,9 @@ use crate::strategy::StrategyEngineMessage;
pub mod prelude {
pub use crate::general::*;
pub use crate::strategy::*;
pub use crate::server_path;
pub use crate::strategy::*;
pub use crate::terminal::*;
pub use crate::units::*;
pub use hypersdk;
pub use postcard;
+4 -42
View File
@@ -1,7 +1,6 @@
use crate::{
general::{EventLog, MarketTrend, Position, Signal},
general::{EventLog, Position, Signal},
strategy::StrategyManifest,
units::{Symbol, USD, Volatility},
};
use hypersdk::{Decimal, hypercore::CandleInterval};
@@ -39,37 +38,10 @@ pub enum TerminalClientMessage {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MarketItem {
pub symbol: Symbol,
pub price: USD,
pub symbol: String,
pub price: Decimal,
pub trend: Decimal,
pub volume_24h: USD,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MarketOverview {
pub trend: MarketTrend,
pub volatility: Volatility,
pub pressure: f64,
pub alerts: Vec<Alert>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum AlertLevel {
High,
Medium,
Low,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Alert {
pub level: AlertLevel,
pub message: String,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Balance {
pub asset: String,
pub amount: f64,
pub value: f64,
pub volume_24h: Decimal,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -116,16 +88,6 @@ pub struct Strategy {
pub cooldown: CandleInterval,
}
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 {
-110
View File
@@ -1,110 +0,0 @@
use rust_decimal::Decimal;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Symbol(pub String);
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub struct USD(pub Decimal);
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum Direction {
Buy,
Sell,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
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)
}
}
impl std::fmt::Display for USD {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0.is_sign_positive() {
write!(f, "\x1b[32m${}\x1b[0m", format_f64(self.0.as_f64()))
} else {
write!(f, "\x1b[31m${}\x1b[0m", format_f64(self.0.as_f64()))
}
}
}
pub fn format_f64(value: f64) -> String {
let abs = value.abs();
let (divisor, suffix) = if abs >= 1_000_000_000.0 {
(1_000_000_000.0, "B")
} else if abs >= 1_000_000.0 {
(1_000_000.0, "M")
} else if abs >= 1_000.0 {
(1_000.0, "K")
} else {
(1.0, "")
};
if divisor != 1.0 {
let formatted = value / divisor;
// Remove unnecessary trailing zeros
let s = format!("{:.2}", formatted)
.trim_end_matches('0')
.trim_end_matches('.')
.to_string();
return format!("{}{}", s, suffix);
}
let val = format!("{:.3}", value);
let parts: Vec<&str> = val.split('.').collect();
let int = parts[0].to_string();
let negative = int.starts_with('-');
let start = if negative { 1 } else { 0 };
let mut result = String::new();
for (i, c) in int[start..].chars().rev().enumerate() {
if i > 0 && i % 3 == 0 {
result.push(',');
}
result.push(c);
}
let mut formatted: String = result.chars().rev().collect();
if negative {
formatted.insert(0, '-');
}
if parts.len() > 1 {
formatted.push('.');
formatted.push_str(parts[1]);
}
formatted
}
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"),
}
}
}