Strategy engine

This commit is contained in:
2026-07-26 01:56:46 +02:00
parent ff5704ec88
commit 270a0f1833
2 changed files with 43 additions and 5 deletions
+40
View File
@@ -7,10 +7,13 @@ use pulse_wire::{
StrategyMessage,
},
};
use tokio::{
fs,
io::{AsyncReadExt, AsyncWriteExt},
process::Command,
sync::Mutex,
task::JoinHandle,
};
use crate::store::pulse_plugin;
@@ -100,3 +103,40 @@ impl StrategyPair {
})
}
}
#[derive(Debug)]
pub struct StrategyEngine {
pub pair: Mutex<StrategyPair>,
pub strategy_handle: Mutex<Option<JoinHandle<()>>>,
pub risk_handle: Mutex<Option<JoinHandle<()>>>,
}
impl StrategyEngine {
pub async fn new(strategy_id: &str, risk_id: &str) -> tokio::io::Result<Self> {
Ok(Self {
pair: Mutex::new(StrategyPair::new(strategy_id, risk_id).await?),
strategy_handle: Mutex::new(None),
risk_handle: Mutex::new(None),
})
}
pub async fn reload(&self, strategy_id: &str, risk_id: &str) -> tokio::io::Result<()> {
if let Some(handle) = &*self.strategy_handle.lock().await {
handle.abort();
}
if let Some(handle) = &*self.risk_handle.lock().await {
handle.abort();
}
let mut pair = self.pair.lock().await;
pair.strategy.process.kill().await?;
pair.risk.process.kill().await?;
*pair = StrategyPair::new(strategy_id, risk_id).await?;
Ok(())
}
}