core/src/events.rs

76 lines
1.6 KiB
Rust
Raw Normal View History

use tokio::sync::oneshot;
2021-01-02 12:16:48 +00:00
2021-01-24 20:53:33 +00:00
use crate::managers::OptionUpdate;
use crate::models::OrderForm;
#[derive(Debug)]
pub struct ActorMessage {
2021-02-17 15:57:52 +00:00
pub(crate) message: ActionMessage,
pub(crate) respond_to: oneshot::Sender<OptionUpdate>,
}
#[derive(Debug)]
2021-02-17 15:57:52 +00:00
pub enum ActionMessage {
Update { tick: u64 },
ClosePosition { position_id: u64 },
SubmitOrder { order: OrderForm },
2021-02-17 15:57:52 +00:00
ClosePositionOrders { position_id: u64 },
2021-01-02 12:16:48 +00:00
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
2021-01-02 15:22:48 +00:00
pub struct EventMetadata {
2021-01-02 12:16:48 +00:00
position_id: Option<u64>,
order_id: Option<u64>,
}
2021-01-04 19:29:01 +00:00
impl EventMetadata {
pub fn new(position_id: Option<u64>, order_id: Option<u64>) -> Self {
EventMetadata {
position_id,
order_id,
}
}
}
2021-01-05 19:50:14 +00:00
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
2021-01-02 15:22:48 +00:00
pub enum EventKind {
2021-01-02 12:16:48 +00:00
NewMinimum,
NewMaximum,
ReachedLoss,
ReachedBreakEven,
ReachedMinProfit,
ReachedGoodProfit,
ReachedMaxLoss,
TrailingStopSet,
TrailingStopMoved,
OrderSubmitted,
NewTick,
2021-01-26 17:12:39 +00:00
PositionClosed { position_id: u64 },
2021-01-02 12:16:48 +00:00
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
2021-01-02 14:10:16 +00:00
pub struct Event {
2021-01-02 12:16:48 +00:00
kind: EventKind,
tick: u64,
metadata: Option<EventMetadata>,
}
impl Event {
pub fn new(kind: EventKind, tick: u64) -> Self {
2021-01-02 12:16:48 +00:00
Event {
kind,
tick,
metadata: None,
2021-01-02 12:16:48 +00:00
}
}
pub fn with_metadata(mut self, metadata: Option<EventMetadata>) -> Self {
self.metadata = metadata;
self
}
2021-01-02 12:16:48 +00:00
fn has_metadata(&self) -> bool {
self.metadata.is_some()
}
}