76 lines
1.6 KiB
Rust
76 lines
1.6 KiB
Rust
use tokio::sync::oneshot;
|
|
|
|
use crate::managers::OptionUpdate;
|
|
use crate::models::OrderForm;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ActorMessage {
|
|
pub(crate) message: ActionMessage,
|
|
pub(crate) respond_to: oneshot::Sender<OptionUpdate>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum ActionMessage {
|
|
Update { tick: u64 },
|
|
ClosePosition { position_id: u64 },
|
|
SubmitOrder { order: OrderForm },
|
|
ClosePositionOrders { position_id: u64 },
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
pub struct EventMetadata {
|
|
position_id: Option<u64>,
|
|
order_id: Option<u64>,
|
|
}
|
|
|
|
impl EventMetadata {
|
|
pub fn new(position_id: Option<u64>, order_id: Option<u64>) -> 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,
|
|
PositionClosed { position_id: u64 },
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
pub struct Event {
|
|
kind: EventKind,
|
|
tick: u64,
|
|
metadata: Option<EventMetadata>,
|
|
}
|
|
|
|
impl Event {
|
|
pub fn new(kind: EventKind, tick: u64) -> Self {
|
|
Event {
|
|
kind,
|
|
tick,
|
|
metadata: None,
|
|
}
|
|
}
|
|
|
|
pub fn with_metadata(mut self, metadata: Option<EventMetadata>) -> Self {
|
|
self.metadata = metadata;
|
|
self
|
|
}
|
|
|
|
fn has_metadata(&self) -> bool {
|
|
self.metadata.is_some()
|
|
}
|
|
}
|