Renamed plugins to strategies
This commit is contained in:
@@ -47,7 +47,7 @@ impl Engine {
|
|||||||
set_cfg!(id, {
|
set_cfg!(id, {
|
||||||
let id: String = id;
|
let id: String = id;
|
||||||
|
|
||||||
if !crate::store::pulse_plugin(&id)?
|
if !crate::store::pulse_strategy(&id)?
|
||||||
.join("strategy.toml")
|
.join("strategy.toml")
|
||||||
.exists()
|
.exists()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use tokio::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
engine::Engine,
|
engine::Engine,
|
||||||
store::{strategy::StrategyChild, pulse_plugin},
|
store::{pulse_strategy, strategy::StrategyChild},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct StrategyEngine {
|
pub struct StrategyEngine {
|
||||||
@@ -28,9 +28,9 @@ pub struct StrategyEngine {
|
|||||||
|
|
||||||
impl StrategyEngine {
|
impl StrategyEngine {
|
||||||
pub async fn new(strategy_id: &str) -> tokio::io::Result<Self> {
|
pub async fn new(strategy_id: &str) -> tokio::io::Result<Self> {
|
||||||
let strategy = pulse_plugin(strategy_id)?;
|
let strategy = pulse_strategy(strategy_id)?;
|
||||||
|
|
||||||
let (strategy, strategy_manifest) = get_manifest_plugin_pair(
|
let (strategy, strategy_manifest) = get_manifest(
|
||||||
&strategy,
|
&strategy,
|
||||||
&strategy.join("strategy.bash"),
|
&strategy.join("strategy.bash"),
|
||||||
&fs::read(strategy.join("strategy.toml")).await?,
|
&fs::read(strategy.join("strategy.toml")).await?,
|
||||||
@@ -168,12 +168,12 @@ impl StrategyEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn reload_strategy(self: &Arc<Self>, id: &str) -> tokio::io::Result<()> {
|
pub async fn reload_strategy(self: &Arc<Self>, id: &str) -> tokio::io::Result<()> {
|
||||||
let plugin = pulse_plugin(id)?;
|
let strategy = pulse_strategy(id)?;
|
||||||
|
|
||||||
let (child, manifest) = get_manifest_plugin_pair(
|
let (child, manifest) = get_manifest(
|
||||||
&plugin,
|
&strategy,
|
||||||
&plugin.join("strategy.bash"),
|
&strategy.join("strategy.bash"),
|
||||||
&fs::read(plugin.join("strategy.toml")).await?,
|
&fs::read(strategy.join("strategy.toml")).await?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.strategy.reload(child, manifest).await?;
|
self.strategy.reload(child, manifest).await?;
|
||||||
@@ -185,15 +185,15 @@ impl StrategyEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_manifest_plugin_pair<'de, M: serde::Deserialize<'de>>(
|
fn get_manifest<'de, M: serde::Deserialize<'de>>(
|
||||||
plugin_dir: &PathBuf,
|
strategy_dir: &PathBuf,
|
||||||
plugin_path: &PathBuf,
|
strategy_path: &PathBuf,
|
||||||
manifest: &'de [u8],
|
manifest: &'de [u8],
|
||||||
) -> tokio::io::Result<(Child, M)> {
|
) -> tokio::io::Result<(Child, M)> {
|
||||||
Ok((
|
Ok((
|
||||||
Command::new("bash")
|
Command::new("bash")
|
||||||
.arg(plugin_path)
|
.arg(strategy_path)
|
||||||
.current_dir(plugin_dir)
|
.current_dir(strategy_dir)
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ pub fn pulse_directory() -> tokio::io::Result<PathBuf> {
|
|||||||
Ok(home_dir()?.join(".config").join("pulse-trader"))
|
Ok(home_dir()?.join(".config").join("pulse-trader"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pulse_plugins_directory() -> tokio::io::Result<PathBuf> {
|
pub fn pulse_strategies_directory() -> tokio::io::Result<PathBuf> {
|
||||||
Ok(pulse_directory()?.join("plugins"))
|
Ok(pulse_directory()?.join("strategies"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pulse_plugin(id: &str) -> tokio::io::Result<PathBuf> {
|
pub fn pulse_strategy(id: &str) -> tokio::io::Result<PathBuf> {
|
||||||
Ok(pulse_directory()?.join("plugins").join(id))
|
Ok(pulse_directory()?.join("strategies").join(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pulse_config_file() -> tokio::io::Result<PathBuf> {
|
pub fn pulse_config_file() -> tokio::io::Result<PathBuf> {
|
||||||
|
|||||||
Reference in New Issue
Block a user