Updated EngineConfig
This commit is contained in:
@@ -170,3 +170,12 @@ impl Allocation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Allocation {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Fixed(v) => write!(f, "${v}"),
|
||||
Self::Percent(p) => write!(f, "{p}%"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
general::{EngineStatus, EventLog, Position, Signal},
|
||||
general::{Allocation, EngineStatus, EventLog, Position, Signal},
|
||||
strategy::StrategyManifest,
|
||||
};
|
||||
use hypersdk::Decimal;
|
||||
@@ -65,4 +65,8 @@ pub enum InspectItem {
|
||||
pub struct EngineConfig {
|
||||
pub preset: String,
|
||||
pub strategy: StrategyManifest,
|
||||
|
||||
pub risk_per_trade: Allocation,
|
||||
pub max_open_positions: u32,
|
||||
pub max_daily_loss: Allocation,
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ impl Engine {
|
||||
|
||||
self.terminal_server
|
||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||
self.get_config_status().await,
|
||||
self.get_config_status().await?,
|
||||
))
|
||||
.await?;
|
||||
} else {
|
||||
@@ -235,7 +235,7 @@ impl Engine {
|
||||
|
||||
self.terminal_server
|
||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||
self.get_config_status().await,
|
||||
self.get_config_status().await?,
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -102,11 +102,18 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_config_status(&self) -> EngineConfig {
|
||||
EngineConfig {
|
||||
preset: self.config.lock().await.preset.clone(),
|
||||
pub async fn get_config_status(&self) -> tokio::io::Result<EngineConfig> {
|
||||
let manager = self.config.lock().await;
|
||||
let config = manager.get_ref()?;
|
||||
|
||||
Ok(EngineConfig {
|
||||
preset: manager.preset.clone(),
|
||||
strategy: self.strategy_engine.strategy.lock().await.manifest.clone(),
|
||||
}
|
||||
|
||||
risk_per_trade: config.risk.risk_per_trade,
|
||||
max_daily_loss: config.risk.max_daily_loss,
|
||||
max_open_positions: config.risk.max_open_positions,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn update_status(&self) -> tokio::io::Result<()> {
|
||||
|
||||
@@ -91,7 +91,7 @@ impl TerminalServer {
|
||||
|
||||
self.send_to(
|
||||
id,
|
||||
TerminalServerMessage::ConfigUpdated(engine.get_config_status().await),
|
||||
TerminalServerMessage::ConfigUpdated(engine.get_config_status().await?),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -219,9 +219,13 @@ impl Formatted for EngineConfig {
|
||||
Triple(
|
||||
"\x1b[2mPreset\x1b[0m",
|
||||
"\x1b[2mStrategy\x1b[0m",
|
||||
"\x1b[2m..\x1b[0m",
|
||||
"\x1b[2mRisk\x1b[0m",
|
||||
),
|
||||
Triple(
|
||||
&self.preset,
|
||||
&self.strategy.name,
|
||||
&self.risk_per_trade.to_string(),
|
||||
),
|
||||
Triple(&self.preset, &self.strategy.name, ".."),
|
||||
]
|
||||
.get_formatted()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user