Engine config status
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use crate::{
|
||||
general::{EventLog, ItemState, Mode, Position, Signal}, strategy::StrategyManifest,
|
||||
general::{EngineStatus, EventLog, Position, Signal},
|
||||
strategy::StrategyManifest,
|
||||
};
|
||||
use hypersdk::{Decimal, hypercore::CandleInterval};
|
||||
use hypersdk::Decimal;
|
||||
|
||||
pub type SignalStatus = Result<Signal, Signal>;
|
||||
|
||||
@@ -13,8 +14,8 @@ pub enum TerminalServerMessage {
|
||||
// Positions
|
||||
PositionsUpdated(Vec<Position>),
|
||||
|
||||
// Strategy
|
||||
StrategyUpdated(StrategyStatus),
|
||||
// Configuration
|
||||
ConfigUpdated(EngineConfig),
|
||||
|
||||
// Signals
|
||||
SignalsUpdated(Vec<SignalStatus>),
|
||||
@@ -23,7 +24,7 @@ pub enum TerminalServerMessage {
|
||||
Inspect(InspectTarget),
|
||||
|
||||
// Status
|
||||
StatusUpdated(Status),
|
||||
StatusUpdated(EngineStatus),
|
||||
|
||||
// Logs
|
||||
SetLogs(Vec<EventLog>),
|
||||
@@ -58,18 +59,6 @@ pub enum InspectItem {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Status {
|
||||
pub feed: Mode,
|
||||
pub exchange: String,
|
||||
pub dex: String,
|
||||
pub latency: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct StrategyStatus {
|
||||
pub struct EngineConfig {
|
||||
pub strategy: StrategyManifest,
|
||||
|
||||
pub mode: Mode,
|
||||
pub state: ItemState,
|
||||
pub cooldown: CandleInterval,
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ impl Engine {
|
||||
self.terminal_server
|
||||
.info("config::set", "watchlist set successfully, use `config save` to persist changes")
|
||||
.await?;
|
||||
|
||||
self.terminal_server
|
||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||
self.get_config_status().await,
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
|
||||
"strategy" | "strat" | "sg" => {
|
||||
@@ -75,23 +81,24 @@ impl Engine {
|
||||
self.terminal_server
|
||||
.info("config::set", "strategy set successfully, use `config save` to persist changes")
|
||||
.await?;
|
||||
|
||||
self.terminal_server
|
||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||
self.get_config_status().await,
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
|
||||
"cooldown" | "cool" | "cd" => {
|
||||
set_cfg!(cooldown, {
|
||||
self.config.lock().await.cooldown = cooldown;
|
||||
|
||||
self.terminal_server.broadcast(
|
||||
pulse_sdk::terminal::TerminalServerMessage::StrategyUpdated(StrategyStatus {
|
||||
strategy: self.strategy_engine.strategy.lock().await.manifest.clone(),
|
||||
|
||||
mode: Mode::Auto,
|
||||
state: ItemState::Running,
|
||||
cooldown,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
});
|
||||
|
||||
self.terminal_server
|
||||
.broadcast(TerminalServerMessage::ConfigUpdated(
|
||||
self.get_config_status().await,
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
||||
@@ -86,4 +86,10 @@ impl Engine {
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_config_status(&self) -> EngineConfig {
|
||||
EngineConfig {
|
||||
strategy: self.strategy_engine.strategy.lock().await.manifest.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,18 +71,7 @@ impl TerminalServer {
|
||||
|
||||
self.send_to(
|
||||
id,
|
||||
pulse_sdk::terminal::TerminalServerMessage::StrategyUpdated(StrategyStatus {
|
||||
strategy: engine
|
||||
.strategy_engine
|
||||
.strategy
|
||||
.lock()
|
||||
.await
|
||||
.manifest
|
||||
.clone(),
|
||||
mode: Mode::Auto,
|
||||
state: ItemState::Running,
|
||||
cooldown: engine.config.lock().await.cooldown,
|
||||
}),
|
||||
TerminalServerMessage::ConfigUpdated(engine.get_config_status().await),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
+22
-28
@@ -114,28 +114,8 @@ impl Formatted for Position {
|
||||
}
|
||||
}
|
||||
|
||||
struct Pair<'a>(&'a str, &'a str);
|
||||
|
||||
struct Triple<'a>(&'a str, &'a str, &'a str);
|
||||
|
||||
impl Formatted for Status {
|
||||
fn get_formatted(&self) -> Vec<String> {
|
||||
vec![
|
||||
Pair("Feed", &format!("{:?}", self.feed)),
|
||||
Pair("Exchange", &self.exchange.clone()),
|
||||
Pair("DEX", &self.dex.clone()),
|
||||
Pair("Latency", &format!("{} ms", self.latency)),
|
||||
]
|
||||
.get_formatted()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Formatted for Pair<'a> {
|
||||
fn get_formatted(&self) -> Vec<String> {
|
||||
vec![self.0.to_string(), self.1.to_string()]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Formatted for Triple<'a> {
|
||||
fn get_formatted(&self) -> Vec<String> {
|
||||
vec![self.0.to_string(), self.1.to_string(), self.2.to_string()]
|
||||
@@ -206,19 +186,33 @@ impl<T: Formatted> Formatted for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Formatted for StrategyStatus {
|
||||
impl Formatted for EngineStatus {
|
||||
fn get_formatted(&self) -> Vec<String> {
|
||||
vec![
|
||||
Triple(
|
||||
"\x1b[2mState\x1b[0m",
|
||||
"\x1b[2mMode\x1b[0m",
|
||||
"\x1b[2m..\x1b[0m",
|
||||
),
|
||||
Triple(
|
||||
&self.strategy_state.to_string(),
|
||||
&self.strategy_mode.to_string(),
|
||||
"..",
|
||||
),
|
||||
]
|
||||
.get_formatted()
|
||||
}
|
||||
}
|
||||
|
||||
impl Formatted for EngineConfig {
|
||||
fn get_formatted(&self) -> Vec<String> {
|
||||
vec![
|
||||
Triple(
|
||||
"\x1b[2mStrategy\x1b[0m",
|
||||
"\x1b[2mState\x1b[0m",
|
||||
"\x1b[2mMode\x1b[0m",
|
||||
),
|
||||
Triple(
|
||||
&format!("\x1b[97m{}\x1b[0m", self.strategy.name),
|
||||
&self.state.to_string(),
|
||||
&self.mode.to_string(),
|
||||
"\x1b[2m..\x1b[0m",
|
||||
"\x1b[2m..\x1b[0m",
|
||||
),
|
||||
Triple(&self.strategy.name, "..", ".."),
|
||||
]
|
||||
.get_formatted()
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ pub struct PulseTradeApp {
|
||||
command: State<InputState>,
|
||||
scroll: State<ScrollState<7>>,
|
||||
|
||||
strategy: State<Option<StrategyStatus>>,
|
||||
status: State<Option<Status>>,
|
||||
config: State<Option<EngineConfig>>,
|
||||
status: State<Option<EngineStatus>>,
|
||||
|
||||
watch_list: State<Vec<MarketItem>>,
|
||||
active_positions: State<Vec<Position>>,
|
||||
@@ -144,8 +144,7 @@ impl App for PulseTradeApp {
|
||||
(
|
||||
LayoutItem::Widget(Size::Flex(1)),
|
||||
Box::new(
|
||||
advanced_option_draw(&self.scroll, 3, "CONFIGURATION", &self.strategy)
|
||||
.await,
|
||||
advanced_option_draw(&self.scroll, 3, "CONFIGURATION", &self.config).await,
|
||||
),
|
||||
),
|
||||
(
|
||||
@@ -182,7 +181,7 @@ async fn main() -> tokio::io::Result<()> {
|
||||
signals: ctx.use_state(Vec::new()),
|
||||
logs: ctx.use_state(Vec::new()),
|
||||
inspect: ctx.use_state(InspectTarget::None),
|
||||
strategy: ctx.use_state(None),
|
||||
config: ctx.use_state(None),
|
||||
status: ctx.use_state(None),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ impl TerminalClient {
|
||||
let active_positions = app.active_positions.clone();
|
||||
let logs = app.logs.clone();
|
||||
let signals = app.signals.clone();
|
||||
let market_overview = app.strategy.clone();
|
||||
let market_overview = app.config.clone();
|
||||
let status = app.status.clone();
|
||||
let inspect = app.inspect.clone();
|
||||
|
||||
@@ -82,8 +82,8 @@ impl TerminalClient {
|
||||
active_positions: State<Vec<Position>>,
|
||||
logs: State<Vec<EventLog>>,
|
||||
signals: State<Vec<SignalStatus>>,
|
||||
market_overview: State<Option<StrategyStatus>>,
|
||||
status: State<Option<Status>>,
|
||||
config: State<Option<EngineConfig>>,
|
||||
status: State<Option<EngineStatus>>,
|
||||
inspect: State<InspectTarget>,
|
||||
) -> tokio::io::Result<()> {
|
||||
loop {
|
||||
@@ -111,8 +111,8 @@ impl TerminalClient {
|
||||
*active_positions.lock().await = v;
|
||||
}
|
||||
|
||||
TerminalServerMessage::StrategyUpdated(v) => {
|
||||
*market_overview.lock().await = Some(v);
|
||||
TerminalServerMessage::ConfigUpdated(v) => {
|
||||
*config.lock().await = Some(v);
|
||||
}
|
||||
|
||||
TerminalServerMessage::SignalsUpdated(v) => {
|
||||
|
||||
Reference in New Issue
Block a user