From 64a687445df77ffd5a1e6b219e8d97f7e53c511e Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Sun, 24 Jan 2021 20:50:54 +0000 Subject: [PATCH] started moving logic from close position to update in order manager --- rustybot/src/managers.rs | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/rustybot/src/managers.rs b/rustybot/src/managers.rs index 79b6133..7ebdfdf 100644 --- a/rustybot/src/managers.rs +++ b/rustybot/src/managers.rs @@ -3,8 +3,10 @@ use std::ops::{Deref, Neg}; use bitfinex::ticker::TradingPairTicker; use futures_util::stream::FuturesUnordered; -use log::{debug, error, info}; +use log::{debug, error, info, trace}; +use merge::Merge; use tokio::signal::unix::Signal; +use tokio::stream::StreamExt; use tokio::sync::mpsc::channel; use tokio::sync::mpsc::{Receiver, Sender}; use tokio::sync::{oneshot, RwLock}; @@ -17,15 +19,9 @@ use crate::models::{ }; use crate::strategy::{FastOrderStrategy, OrderStrategy, PositionStrategy, TrailingStop}; use crate::BoxError; -use merge::Merge; -use tokio::stream::StreamExt; pub type OptionUpdate = (Option>, Option>); -pub struct EventManager { - events: Vec, -} - /****************** * PRICES ******************/ @@ -108,20 +104,9 @@ impl PriceManager { current_prices, self.pair.clone(), None, - // None, )) } - // fn add_event(&mut self, event: Event) { - // self.events.push(event); - // - // self.dispatcher.call_event_handlers(&event, &self); - // } - // - // fn add_signal(&mut self, signal: SignalKind) { - // self.signals.insert(self.current_tick(), signal); - // } - pub fn pair(&self) -> &SymbolPair { &self.pair } @@ -133,7 +118,6 @@ pub struct PriceEntry { pair: SymbolPair, price: PriceTicker, events: Option>, - // signals: Option>, } impl PriceEntry { @@ -142,14 +126,12 @@ impl PriceEntry { price: PriceTicker, pair: SymbolPair, events: Option>, - // signals: Option>, ) -> Self { PriceEntry { tick, pair, price, events, - // signals, } } @@ -165,9 +147,6 @@ impl PriceEntry { pub fn events(&self) -> &Option> { &self.events } - // pub fn signals(&self) -> &Option> { - // &self.signals - // } } /****************** @@ -510,7 +489,7 @@ impl OrderManager { let (_, strat_messages) = self.strategy - .on_position_close(active_order, &position, &order_book)?; + .on_position_order(active_order, &position, &order_book)?; if let Some(messages) = strat_messages { for m in messages { @@ -535,8 +514,16 @@ impl OrderManager { Ok(()) } + // TODO: finish me pub async fn update(&self) -> Result { - // TODO: implement me + trace!("\tUpdating {} order manager.", self.pair); + + let (open_orders, opt_open_positions) = tokio::join!( + self.client.active_orders(&self.pair), + self.client.active_positions(&self.pair) + ); + let (open_orders, opt_open_positions) = (open_orders?, opt_open_positions?); + Ok((None, None)) }