Engine status
This commit is contained in:
@@ -179,12 +179,18 @@ impl Engine {
|
||||
return self.invalid_command_usage("strategy").await;
|
||||
};
|
||||
|
||||
self.strategy_engine
|
||||
.send(&StrategyEngineMessage::Command {
|
||||
command: strategy_command.to_owned(),
|
||||
args: args.into_iter().map(Into::into).collect(),
|
||||
})
|
||||
.await?;
|
||||
match strategy_command {
|
||||
"start" => {}
|
||||
|
||||
_ => {
|
||||
self.strategy_engine
|
||||
.send(&StrategyEngineMessage::Command {
|
||||
command: strategy_command.to_owned(),
|
||||
args: args.into_iter().map(Into::into).collect(),
|
||||
})
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
||||
@@ -28,6 +28,9 @@ pub struct Engine {
|
||||
// data
|
||||
pub config: Arc<Mutex<Config>>,
|
||||
pub accounts: Arc<Mutex<AccountList>>,
|
||||
|
||||
// live data / status
|
||||
pub status: Arc<Mutex<EngineStatus>>,
|
||||
pub watch_list: Arc<Mutex<WatchList>>,
|
||||
pub signals: Arc<Mutex<Vec<SignalStatus>>>,
|
||||
}
|
||||
@@ -44,11 +47,20 @@ impl Engine {
|
||||
let config = Arc::new(Mutex::new(config));
|
||||
|
||||
Ok(Arc::new_cyclic(|engine| Self {
|
||||
config,
|
||||
accounts,
|
||||
ws_stream: Arc::new(Mutex::new(ws_stream)),
|
||||
// engine
|
||||
terminal_server: TerminalServer::new(engine.clone()),
|
||||
strategy_engine: strategy.initialize(engine.clone()),
|
||||
ws_stream: Arc::new(Mutex::new(ws_stream)),
|
||||
|
||||
// data
|
||||
config,
|
||||
accounts,
|
||||
|
||||
// live data / status
|
||||
status: Arc::new(Mutex::new(EngineStatus {
|
||||
strategy_mode: Mode::Auto,
|
||||
strategy_state: ItemState::Stopped,
|
||||
})),
|
||||
watch_list: Arc::new(Mutex::new(WatchList {
|
||||
name_to_index: HashMap::new(),
|
||||
items: Vec::new(),
|
||||
@@ -61,10 +73,16 @@ impl Engine {
|
||||
/// When a strategy is reloaded it restarts automatically
|
||||
pub async fn run(&self) -> anyhow::Result<()> {
|
||||
loop {
|
||||
self.terminal_server
|
||||
.info("engine::main", "Strategy starting")
|
||||
.await?;
|
||||
|
||||
self.status.lock().await.strategy_state = ItemState::Starting;
|
||||
|
||||
self.strategy_engine.run().await?;
|
||||
|
||||
self.terminal_server
|
||||
.info("engine::main", "Strategy stopped, restarting")
|
||||
.info("engine::main", "Strategy stopped")
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,13 @@ impl StrategyEngine {
|
||||
|
||||
self.send(&StrategyEngineMessage::Initialize).await?;
|
||||
|
||||
engine
|
||||
.terminal_server
|
||||
.info("engine::main", "Strategy Started")
|
||||
.await?;
|
||||
|
||||
engine.status.lock().await.strategy_state = ItemState::Running;
|
||||
|
||||
loop {
|
||||
match StrategyChild::read(&mut stdout).await? {
|
||||
None => {}
|
||||
|
||||
Reference in New Issue
Block a user