From 76e95f28594e73b4d5fde5589f941c6c905d1648 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 4 Jan 2021 13:27:30 +0000 Subject: [PATCH] fixed registers --- rustybot/src/events.rs | 24 ++++++++++++++++-------- rustybot/src/positions.rs | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) 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 {