Refactored codebase to Strategy instead of plugin

This commit is contained in:
2026-07-30 03:42:59 +02:00
parent 72a0145860
commit 660a0cb66a
7 changed files with 25 additions and 25 deletions
+3 -3
View File
@@ -1,16 +1,16 @@
pub mod general;
pub mod plugin;
pub mod strategy;
pub mod terminal;
pub mod units;
pub use hypersdk;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use crate::plugin::StrategyEngineMessage;
use crate::strategy::StrategyEngineMessage;
pub mod prelude {
pub use crate::general::*;
pub use crate::plugin::*;
pub use crate::strategy::*;
pub use crate::server_path;
pub use crate::terminal::*;
pub use crate::units::*;
+1 -1
View File
@@ -1,6 +1,6 @@
use crate::{
general::{EventLog, MarketTrend, Position, Signal},
plugin::StrategyManifest,
strategy::StrategyManifest,
units::{Symbol, USD, Volatility},
};
use hypersdk::{Decimal, hypercore::CandleInterval};
+2 -2
View File
@@ -1,9 +1,9 @@
pub mod command;
pub mod execution;
pub mod plugin;
pub mod strategy;
use crate::{
engine::plugin::StrategyEngine,
engine::strategy::StrategyEngine,
store::{accounts::AccountList, config::Config},
terminal::TerminalServer,
};
@@ -15,11 +15,11 @@ use tokio::{
use crate::{
engine::Engine,
store::{plugin::Plugin, pulse_plugin},
store::{strategy::StrategyChild, pulse_plugin},
};
pub struct StrategyEngine {
pub strategy: Arc<Plugin<StrategyEngineMessage, StrategyMessage, StrategyManifest>>,
pub strategy: Arc<StrategyChild>,
pub engine: Weak<Engine>,
pub ws: WebSocket,
@@ -37,7 +37,7 @@ impl StrategyEngine {
)?;
Ok(Self {
strategy: Arc::new(Plugin::new(strategy, strategy_manifest)),
strategy: Arc::new(StrategyChild::new(strategy, strategy_manifest)),
engine: Weak::new(),
ws: hypercore::mainnet_ws(),
subscriptions: Mutex::new(HashSet::new()),
+1 -1
View File
@@ -2,7 +2,7 @@ use std::path::PathBuf;
pub mod accounts;
pub mod config;
pub mod plugin;
pub mod strategy;
pub fn home_dir() -> tokio::io::Result<PathBuf> {
std::env::home_dir().ok_or_else(|| {
@@ -1,33 +1,29 @@
use std::marker::PhantomData;
use pulse_sdk::map_postcard_err;
use serde::{Deserialize, Serialize};
use pulse_sdk::{
map_postcard_err,
strategy::{StrategyEngineMessage, StrategyManifest, StrategyMessage},
};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
process::{Child, ChildStdout},
sync::Mutex,
};
#[derive(Debug)]
pub struct Plugin<S: Serialize, R: for<'de> Deserialize<'de>, M: for<'de> Deserialize<'de>> {
pub manifest: Mutex<M>,
pub struct StrategyChild {
pub manifest: Mutex<StrategyManifest>,
pub stdout: Mutex<ChildStdout>,
pub process: Mutex<Child>,
pub _p: (PhantomData<S>, PhantomData<R>),
}
impl<S: Serialize, R: for<'de> Deserialize<'de>, M: for<'de> Deserialize<'de>> Plugin<S, R, M> {
pub fn new(mut child: Child, manifest: M) -> Self {
impl StrategyChild {
pub fn new(mut child: Child, manifest: StrategyManifest) -> Self {
Self {
stdout: Mutex::new(child.stdout.take().expect("Failed to obtain child stdout")),
process: Mutex::new(child),
manifest: Mutex::new(manifest),
_p: (PhantomData, PhantomData),
}
}
pub async fn recv(&self) -> tokio::io::Result<Option<R>> {
pub async fn recv(&self) -> tokio::io::Result<Option<StrategyMessage>> {
let mut stdout = self.stdout.lock().await;
let mut len_buf = [0u8; size_of::<usize>()];
@@ -46,7 +42,7 @@ impl<S: Serialize, R: for<'de> Deserialize<'de>, M: for<'de> Deserialize<'de>> P
Ok(Some(map_postcard_err(postcard::from_bytes(&buffer))?))
}
pub async fn send(&self, msg: &S) -> tokio::io::Result<()> {
pub async fn send(&self, msg: &StrategyEngineMessage) -> tokio::io::Result<()> {
self.send_raw(&map_postcard_err(postcard::to_allocvec(msg))?)
.await
}
@@ -62,7 +58,11 @@ impl<S: Serialize, R: for<'de> Deserialize<'de>, M: for<'de> Deserialize<'de>> P
Ok(())
}
pub async fn reload(&self, mut child: Child, manifest: M) -> tokio::io::Result<()> {
pub async fn reload(
&self,
mut child: Child,
manifest: StrategyManifest,
) -> tokio::io::Result<()> {
let mut process = self.process.lock().await;
process.kill().await?;