Strategy
This commit is contained in:
+11
-1
@@ -5,13 +5,14 @@ pub use hypersdk;
|
|||||||
|
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::strategy::StrategyEngineMessage;
|
use crate::{general::LogKind, strategy::StrategyEngineMessage};
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::general::*;
|
pub use crate::general::*;
|
||||||
pub use crate::server_path;
|
pub use crate::server_path;
|
||||||
pub use crate::strategy::*;
|
pub use crate::strategy::*;
|
||||||
pub use crate::terminal::*;
|
pub use crate::terminal::*;
|
||||||
|
pub use crate::Strategy;
|
||||||
|
|
||||||
pub use hypersdk;
|
pub use hypersdk;
|
||||||
pub use postcard;
|
pub use postcard;
|
||||||
@@ -63,6 +64,15 @@ pub trait Strategy {
|
|||||||
send_raw(&map_postcard_err(prelude::postcard::to_allocvec(msg))?).await
|
send_raw(&map_postcard_err(prelude::postcard::to_allocvec(msg))?).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn log(&self, kind: LogKind, name: &str, message: &str) -> tokio::io::Result<()> {
|
||||||
|
self.send(&prelude::StrategyMessage::Log(prelude::EventLog {
|
||||||
|
kind,
|
||||||
|
name: name.to_owned(),
|
||||||
|
message: message.to_owned(),
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn on_raw(&self, data: &[u8]) -> tokio::io::Result<()> {
|
async fn on_raw(&self, data: &[u8]) -> tokio::io::Result<()> {
|
||||||
match map_postcard_err(postcard::from_bytes(&data))? {
|
match map_postcard_err(postcard::from_bytes(&data))? {
|
||||||
StrategyEngineMessage::Initialize => self.initialize().await,
|
StrategyEngineMessage::Initialize => self.initialize().await,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub enum TerminalServerMessage {
|
|||||||
PositionsUpdated(Vec<Position>),
|
PositionsUpdated(Vec<Position>),
|
||||||
|
|
||||||
// Strategy
|
// Strategy
|
||||||
StrategyUpdated(Strategy),
|
StrategyUpdated(StrategyStatus),
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
SignalsUpdated(Vec<SignalStatus>),
|
SignalsUpdated(Vec<SignalStatus>),
|
||||||
@@ -80,7 +80,7 @@ pub enum ItemState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Strategy {
|
pub struct StrategyStatus {
|
||||||
pub strategy: StrategyManifest,
|
pub strategy: StrategyManifest,
|
||||||
|
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{engine::Engine, store::config::Config};
|
use crate::{engine::Engine, store::config::Config};
|
||||||
|
|
||||||
use pulse_sdk::terminal::{ItemState, Mode, Strategy};
|
use pulse_sdk::terminal::{ItemState, Mode, StrategyStatus};
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
@@ -74,7 +74,7 @@ impl Engine {
|
|||||||
self.config.lock().await.cooldown = cooldown;
|
self.config.lock().await.cooldown = cooldown;
|
||||||
|
|
||||||
self.terminal_server.broadcast(
|
self.terminal_server.broadcast(
|
||||||
pulse_sdk::terminal::TerminalServerMessage::StrategyUpdated(Strategy {
|
pulse_sdk::terminal::TerminalServerMessage::StrategyUpdated(StrategyStatus {
|
||||||
strategy: self.strategy_engine.strategy.lock().await.manifest.clone(),
|
strategy: self.strategy_engine.strategy.lock().await.manifest.clone(),
|
||||||
|
|
||||||
mode: Mode::Auto,
|
mode: Mode::Auto,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ impl TerminalServer {
|
|||||||
|
|
||||||
self.send_to(
|
self.send_to(
|
||||||
id,
|
id,
|
||||||
pulse_sdk::terminal::TerminalServerMessage::StrategyUpdated(Strategy {
|
pulse_sdk::terminal::TerminalServerMessage::StrategyUpdated(StrategyStatus {
|
||||||
strategy: engine
|
strategy: engine
|
||||||
.strategy_engine
|
.strategy_engine
|
||||||
.strategy
|
.strategy
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ impl<T: Formatted> Formatted for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Formatted for Strategy {
|
impl Formatted for StrategyStatus {
|
||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
Triple(
|
Triple(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub struct PulseTradeApp {
|
|||||||
command: State<InputState>,
|
command: State<InputState>,
|
||||||
scroll: State<ScrollState<7>>,
|
scroll: State<ScrollState<7>>,
|
||||||
|
|
||||||
strategy: State<Option<Strategy>>,
|
strategy: State<Option<StrategyStatus>>,
|
||||||
status: State<Option<Status>>,
|
status: State<Option<Status>>,
|
||||||
|
|
||||||
watch_list: State<Vec<MarketItem>>,
|
watch_list: State<Vec<MarketItem>>,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ impl TerminalClient {
|
|||||||
active_positions: State<Vec<Position>>,
|
active_positions: State<Vec<Position>>,
|
||||||
logs: State<Vec<EventLog>>,
|
logs: State<Vec<EventLog>>,
|
||||||
signals: State<Vec<SignalStatus>>,
|
signals: State<Vec<SignalStatus>>,
|
||||||
market_overview: State<Option<Strategy>>,
|
market_overview: State<Option<StrategyStatus>>,
|
||||||
status: State<Option<Status>>,
|
status: State<Option<Status>>,
|
||||||
inspect: State<InspectTarget>,
|
inspect: State<InspectTarget>,
|
||||||
) -> tokio::io::Result<()> {
|
) -> tokio::io::Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user