core/rustybot/src/events.rs
2021-02-17 15:57:52 +00:00

71 lines
1.5 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, metadata: Option<EventMetadata>) -> Self {
Event {
kind,
tick,
metadata,
}
}
fn has_metadata(&self) -> bool {
self.metadata.is_some()
}
}