From 382f9c81064841e60a0ee5c56573ca5a0d24a5b8 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 27 Jan 2021 17:00:47 +0000 Subject: [PATCH] order manager on its own --- rustybot/src/managers.rs | 22 +++++++++++++++++++--- rustybot/src/strategy.rs | 6 +++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/rustybot/src/managers.rs b/rustybot/src/managers.rs index cba7211..3ea28d4 100644 --- a/rustybot/src/managers.rs +++ b/rustybot/src/managers.rs @@ -8,6 +8,7 @@ use merge::Merge; use tokio::sync::mpsc::channel; use tokio::sync::mpsc::{Receiver, Sender}; use tokio::sync::oneshot; +use tokio::time::Duration; use crate::connectors::{Client, ExchangeDetails}; use crate::currency::SymbolPair; @@ -318,9 +319,25 @@ pub struct OrderManagerHandle { } impl OrderManagerHandle { + const SLEEP_DURATION: u64 = 5; + async fn run_order_manager(mut manager: OrderManager) { - while let Some(msg) = manager.receiver.recv().await { - manager.handle_message(msg).await.unwrap(); + let mut sleep = tokio::time::interval(Duration::from_secs(5)); + + loop { + tokio::select! { + opt_msg= manager.receiver.recv() => { + if let Some(msg) = opt_msg { + manager.handle_message(msg).await.unwrap() + + } + + + }, + _ = sleep.tick() => { + manager.update().await.unwrap(); + } + } } } @@ -456,7 +473,6 @@ impl OrderManager { Ok((None, None)) } - // TODO: finish me pub async fn update(&self) -> Result { trace!("\t[OrderManager] Updating {}", self.pair); diff --git a/rustybot/src/strategy.rs b/rustybot/src/strategy.rs index 3ac2f03..8b88d48 100644 --- a/rustybot/src/strategy.rs +++ b/rustybot/src/strategy.rs @@ -75,9 +75,9 @@ pub struct TrailingStop { impl TrailingStop { const BREAK_EVEN_PERC: f64 = 0.1; - const MIN_PROFIT_PERC: f64 = 0.4; - const GOOD_PROFIT_PERC: f64 = TrailingStop::MIN_PROFIT_PERC * 2.5; - const MAX_LOSS_PERC: f64 = -1.0; + const MIN_PROFIT_PERC: f64 = 0.7; + const GOOD_PROFIT_PERC: f64 = TrailingStop::MIN_PROFIT_PERC * 1.75; + const MAX_LOSS_PERC: f64 = -1.75; pub fn new() -> Self { TrailingStop {