Strategy messaging
This commit is contained in:
@@ -52,6 +52,24 @@ impl<T: PulseWire> PulseWire for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PulseWire> PulseWire for Option<T> {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
if let Some(v) = self {
|
||||
v.to_com()
|
||||
} else {
|
||||
vec![0]
|
||||
}
|
||||
}
|
||||
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
if com[0] > 0 {
|
||||
Some(T::from_com(com))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for String {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
let bytes = self.as_bytes();
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
use crate::{PulseWire, units::TimeFrame};
|
||||
use crate::{
|
||||
PulseWire,
|
||||
general::{EventLog, Signal},
|
||||
terminal::MarketItem,
|
||||
units::{Direction, TimeFrame},
|
||||
};
|
||||
use pulse_macros::pwp;
|
||||
|
||||
#[pwp]
|
||||
@@ -23,3 +28,69 @@ pub struct RiskManifest {
|
||||
max_loss: u8,
|
||||
cooldown: TimeFrame,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum StrategyMessage {
|
||||
RequestOHLC {
|
||||
symbol: String,
|
||||
timeframe: TimeFrame,
|
||||
count: u32,
|
||||
},
|
||||
|
||||
SubscribeCandle {
|
||||
symbol: String,
|
||||
timeframe: TimeFrame,
|
||||
},
|
||||
|
||||
Signal(StrategySignal),
|
||||
|
||||
Log(EventLog),
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum StrategyEngineMessage {
|
||||
Initialize {
|
||||
watchlist: Vec<MarketItem>,
|
||||
},
|
||||
|
||||
CandleUpdate {
|
||||
symbol: String,
|
||||
candle: String,
|
||||
},
|
||||
|
||||
OHLC {
|
||||
symbol: String,
|
||||
timeframe: TimeFrame,
|
||||
candles: Vec<String>,
|
||||
},
|
||||
|
||||
Start,
|
||||
|
||||
Stop,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum RiskMessage {
|
||||
Approve(Signal),
|
||||
|
||||
Reject { reason: String },
|
||||
|
||||
Log(EventLog),
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum RiskEngineMessage {
|
||||
Initialize { strategy: String },
|
||||
|
||||
Signal(StrategySignal),
|
||||
|
||||
MarketUpdate { symbol: String, price: f64 },
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct StrategySignal {
|
||||
pub symbol: String,
|
||||
pub side: Direction,
|
||||
pub confidence: f32,
|
||||
pub price: Option<f64>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user