Smarter risk and strategy, and logging
This commit is contained in:
@@ -16,6 +16,10 @@ impl Engine {
|
|||||||
*self.config.lock().await = Config::new().await?;
|
*self.config.lock().await = Config::new().await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"save" => {
|
||||||
|
self.config.lock().await.save().await?;
|
||||||
|
}
|
||||||
|
|
||||||
"set" => {
|
"set" => {
|
||||||
macro_rules! set_cfg {
|
macro_rules! set_cfg {
|
||||||
($n:ident, $v:expr) => {
|
($n:ident, $v:expr) => {
|
||||||
@@ -33,22 +37,62 @@ impl Engine {
|
|||||||
match args[1] {
|
match args[1] {
|
||||||
"watchlist" | "watch" | "wl" => {
|
"watchlist" | "watch" | "wl" => {
|
||||||
set_cfg!(v, self.config.lock().await.watchlist = v);
|
set_cfg!(v, self.config.lock().await.watchlist = v);
|
||||||
|
|
||||||
|
self.terminal_server
|
||||||
|
.info("config::set", "watchlist set successfully, use `config save` to persist changes")
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"strategy" | "strat" | "str" | "sg" => {
|
"strategy" | "strat" | "str" | "sg" => {
|
||||||
set_cfg!(id, {
|
set_cfg!(id, {
|
||||||
let id: String = id;
|
let id: String = id;
|
||||||
|
|
||||||
|
if !crate::store::pulse_plugin(&id)?
|
||||||
|
.join("strategy.toml")
|
||||||
|
.exists()
|
||||||
|
{
|
||||||
|
return self
|
||||||
|
.terminal_server
|
||||||
|
.error(
|
||||||
|
"config::set::strategy",
|
||||||
|
&format!("Non existent strategy `{id}`"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
self.strategy.reload_strategy(id.as_str()).await?;
|
self.strategy.reload_strategy(id.as_str()).await?;
|
||||||
self.config.lock().await.strategy = id;
|
self.config.lock().await.strategy = id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.terminal_server
|
||||||
|
.info("config::set", "strategy set successfully, use `config save` to persist changes")
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"risk" | "rs" => {
|
"risk" | "rs" => {
|
||||||
set_cfg!(id, {
|
set_cfg!(id, {
|
||||||
let id: String = id;
|
let id: String = id;
|
||||||
|
|
||||||
|
if !crate::store::pulse_plugin(&id)?
|
||||||
|
.join("risk.toml")
|
||||||
|
.exists()
|
||||||
|
{
|
||||||
|
return self
|
||||||
|
.terminal_server
|
||||||
|
.error(
|
||||||
|
"config::set::risk",
|
||||||
|
&format!("Non existent risk `{id}`"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
self.strategy.reload_risk(id.as_str()).await?;
|
self.strategy.reload_risk(id.as_str()).await?;
|
||||||
self.config.lock().await.risk = id;
|
self.config.lock().await.risk = id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.terminal_server
|
||||||
|
.info("config::set", "risk set successfully, use `config save` to persist changes")
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"cooldown" | "cool" | "cd" => {
|
"cooldown" | "cool" | "cd" => {
|
||||||
|
|||||||
@@ -37,6 +37,14 @@ impl Config {
|
|||||||
Self::from_str(&output)
|
Self::from_str(&output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn save(&self) -> tokio::io::Result<()> {
|
||||||
|
let path = crate::store::pulse_config_file()?;
|
||||||
|
|
||||||
|
tokio::fs::write(path, self.to_string()?).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_str(s: &str) -> tokio::io::Result<Self> {
|
pub fn from_str(s: &str) -> tokio::io::Result<Self> {
|
||||||
toml::from_str(s)
|
toml::from_str(s)
|
||||||
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::InvalidInput, v.to_string()))
|
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::InvalidInput, v.to_string()))
|
||||||
|
|||||||
Reference in New Issue
Block a user