diff --git a/rustybot/src/events.rs b/rustybot/src/events.rs index ac96749..ad66e63 100644 --- a/rustybot/src/events.rs +++ b/rustybot/src/events.rs @@ -119,10 +119,12 @@ impl EventDispatcher { F: Fn(&Event, &PairStatus) -> Fut, Fut: Future + Send, { - self.event_handlers - .entry(event) - .or_default() - .push(Box::new(move |e, s| tokio::spawn(f(&e, s)))); + let f = Box::new(move |e, s| tokio::spawn(f(&e, s))); + + match event { + EventKind::Any => self.on_any_event_handlers.push(f), + _ => self.event_handlers.entry(event).or_default().push(f), + } } pub fn register_positionstate_handler( @@ -133,9 +135,15 @@ impl EventDispatcher { F: Fn(&PositionWrapper, &PairStatus) -> Fut, Fut: Future + Send, { - self.position_state_handlers - .entry(state) - .or_default() - .push(Box::new(move |pw, s| tokio::spawn(f(&pw, s)))); + let f = Box::new(move |pw, s| tokio::spawn(f(&pw, s))); + + match state { + PositionState::Any => self.on_any_position_state_handlers.push(f), + _ => self + .position_state_handlers + .entry(state) + .or_default() + .push(f), + } } } diff --git a/rustybot/src/positions.rs b/rustybot/src/positions.rs index 8c896ff..f588cb5 100644 --- a/rustybot/src/positions.rs +++ b/rustybot/src/positions.rs @@ -7,6 +7,7 @@ pub enum PositionState { BreakEven, MinimumProfit, Profit, + Any, } impl PositionState {