Strategy
This commit is contained in:
+11
-1
@@ -5,13 +5,14 @@ pub use hypersdk;
|
||||
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
use crate::strategy::StrategyEngineMessage;
|
||||
use crate::{general::LogKind, strategy::StrategyEngineMessage};
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::general::*;
|
||||
pub use crate::server_path;
|
||||
pub use crate::strategy::*;
|
||||
pub use crate::terminal::*;
|
||||
pub use crate::Strategy;
|
||||
|
||||
pub use hypersdk;
|
||||
pub use postcard;
|
||||
@@ -63,6 +64,15 @@ pub trait Strategy {
|
||||
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<()> {
|
||||
match map_postcard_err(postcard::from_bytes(&data))? {
|
||||
StrategyEngineMessage::Initialize => self.initialize().await,
|
||||
|
||||
@@ -15,7 +15,7 @@ pub enum TerminalServerMessage {
|
||||
PositionsUpdated(Vec<Position>),
|
||||
|
||||
// Strategy
|
||||
StrategyUpdated(Strategy),
|
||||
StrategyUpdated(StrategyStatus),
|
||||
|
||||
// Signals
|
||||
SignalsUpdated(Vec<SignalStatus>),
|
||||
@@ -80,7 +80,7 @@ pub enum ItemState {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Strategy {
|
||||
pub struct StrategyStatus {
|
||||
pub strategy: StrategyManifest,
|
||||
|
||||
pub mode: Mode,
|
||||
|
||||
Reference in New Issue
Block a user