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::{
|
use crate::{
|
||||||
general::{EngineStatus, EventLog, Position, Signal},
|
general::{Allocation, EngineStatus, EventLog, Position, Signal},
|
||||||
strategy::StrategyManifest,
|
strategy::StrategyManifest,
|
||||||
};
|
};
|
||||||
use hypersdk::Decimal;
|
use hypersdk::Decimal;
|
||||||
@@ -65,4 +65,8 @@ pub enum InspectItem {
|
|||||||
pub struct EngineConfig {
|
pub struct EngineConfig {
|
||||||
pub preset: String,
|
pub preset: String,
|
||||||
pub strategy: StrategyManifest,
|
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
|
self.terminal_server
|
||||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||||
self.get_config_status().await,
|
self.get_config_status().await?,
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
@@ -235,7 +235,7 @@ impl Engine {
|
|||||||
|
|
||||||
self.terminal_server
|
self.terminal_server
|
||||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||||
self.get_config_status().await,
|
self.get_config_status().await?,
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,11 +102,18 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_config_status(&self) -> EngineConfig {
|
pub async fn get_config_status(&self) -> tokio::io::Result<EngineConfig> {
|
||||||
EngineConfig {
|
let manager = self.config.lock().await;
|
||||||
preset: self.config.lock().await.preset.clone(),
|
let config = manager.get_ref()?;
|
||||||
|
|
||||||
|
Ok(EngineConfig {
|
||||||
|
preset: manager.preset.clone(),
|
||||||
strategy: self.strategy_engine.strategy.lock().await.manifest.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<()> {
|
pub async fn update_status(&self) -> tokio::io::Result<()> {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ impl TerminalServer {
|
|||||||
|
|
||||||
self.send_to(
|
self.send_to(
|
||||||
id,
|
id,
|
||||||
TerminalServerMessage::ConfigUpdated(engine.get_config_status().await),
|
TerminalServerMessage::ConfigUpdated(engine.get_config_status().await?),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -219,9 +219,13 @@ impl Formatted for EngineConfig {
|
|||||||
Triple(
|
Triple(
|
||||||
"\x1b[2mPreset\x1b[0m",
|
"\x1b[2mPreset\x1b[0m",
|
||||||
"\x1b[2mStrategy\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()
|
.get_formatted()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user