use tokio::sync::oneshot; use crate::managers::OptionUpdate; use crate::models::OrderForm; #[derive(Debug)] pub struct ActorMessage { pub(crate) message: Message, pub(crate) respond_to: oneshot::Sender, } #[derive(Debug)] pub enum Message { Update { tick: u64 }, ClosePosition { position_id: u64 }, SubmitOrder { order: OrderForm }, } #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub struct EventMetadata { position_id: Option, order_id: Option, } impl EventMetadata { pub fn new(position_id: Option, order_id: Option) -> Self { EventMetadata { position_id, order_id, } } } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum EventKind { NewMinimum, NewMaximum, ReachedLoss, ReachedBreakEven, ReachedMinProfit, ReachedGoodProfit, ReachedMaxLoss, TrailingStopSet, TrailingStopMoved, OrderSubmitted, NewTick, } #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub struct Event { kind: EventKind, tick: u64, metadata: Option, } impl Event { pub fn new(kind: EventKind, tick: u64, metadata: Option) -> Self { Event { kind, tick, metadata, } } fn has_metadata(&self) -> bool { self.metadata.is_some() } }