order manager on its own

This commit is contained in:
Giulio De Pasquale 2021-01-27 17:00:47 +00:00
parent 7230b7c67d
commit 382f9c8106
2 changed files with 22 additions and 6 deletions

View File

@ -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<OptionUpdate, BoxError> {
trace!("\t[OrderManager] Updating {}", self.pair);

View File

@ -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 {