diff --git a/src/connectors.rs b/src/connectors.rs index fc2214e..0980143 100644 --- a/src/connectors.rs +++ b/src/connectors.rs @@ -123,7 +123,7 @@ impl Client { .active_orders(pair) .await? .into_iter() - .filter(|x| &x.pair() == &pair) + .filter(|x| x.pair() == pair) .collect()) } diff --git a/src/main.rs b/src/main.rs index 76f7dd7..d9673e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,8 +48,8 @@ async fn main() -> Result<(), BoxError> { .ok_or("API_SECRET not set!")?; let bitfinex = ExchangeDetails::Bitfinex { - api_key: api_key.into(), - api_secret: api_secret.into(), + api_key, + api_secret, }; let mut bot = BfxBot::new( diff --git a/src/managers.rs b/src/managers.rs index 7c9cdb5..5605a13 100644 --- a/src/managers.rs +++ b/src/managers.rs @@ -416,7 +416,7 @@ impl OrderManager { None => { self.orders_map.clear(); } Some(positions) => { // retain only positions that are open remotely as well - self.orders_map.retain(|local_id, _| positions.iter().find(|r| r.id() == *local_id).is_some()); + self.orders_map.retain(|local_id, _| positions.iter().any(|r| r.id() == *local_id)); for position in positions { // mapping tracked orders to their ids @@ -431,7 +431,7 @@ impl OrderManager { for remote_order in remote_orders.iter().filter(|x| !tracked_orders.contains(&x.id())) { // the only check to bind an active order to an open position, // is to check for their amount which should be identical - if remote_order.order_form().amount().abs() == position.amount().abs() { + if (remote_order.order_form().amount().abs() - position.amount().abs()).abs() < 0.0001 { trace!("Adding order {} to internal mapping from remote.", remote_order.id()); self.add_to_orders_map(position.id(), remote_order.clone()); } @@ -439,7 +439,7 @@ impl OrderManager { // removing local orders that are not in remote for local_orders in self.orders_map.values_mut() { - local_orders.retain(|l| remote_orders.iter().find(|r| r.id() == l.id()).is_some()); + local_orders.retain(|l| remote_orders.iter().any(|r| r.id() == l.id())); } // clean-up empty positions in local mapping diff --git a/src/models.rs b/src/models.rs index cb602fb..8f2628d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -432,7 +432,7 @@ pub struct OrderMetadata { impl Clone for OrderMetadata { fn clone(&self) -> Self { Self { - position_id: self.position_id.clone(), + position_id: self.position_id, strategy: self.strategy.as_ref().map(|x| clone_box(&**x)), } } @@ -469,6 +469,12 @@ impl OrderMetadata { } } +impl Default for OrderMetadata { + fn default() -> Self { + Self::new() + } +} + /*************** * Positions ***************/ diff --git a/src/strategy.rs b/src/strategy.rs index 6a83f6b..8342d64 100644 --- a/src/strategy.rs +++ b/src/strategy.rs @@ -23,14 +23,14 @@ pub trait PositionStrategy: DynClone + Send + Sync { position: Position, current_tick: u64, positions_history: &HashMap, - fees: &Vec, + fees: &[TradingFees], ) -> (Position, Option>, Option>); fn post_tick( &mut self, position: Position, current_tick: u64, positions_history: &HashMap, - fees: &Vec, + fees: &[TradingFees], ) -> (Position, Option>, Option>); } @@ -223,7 +223,7 @@ impl PositionStrategy for TrailingStop { position: Position, current_tick: u64, positions_history: &HashMap, - _: &Vec, + _: &[TradingFees], ) -> (Position, Option>, Option>) { let pl_perc = position.pl_perc(); @@ -300,7 +300,7 @@ impl PositionStrategy for TrailingStop { position: Position, _: u64, _: &HashMap, - fees: &Vec, + fees: &[TradingFees], ) -> (Position, Option>, Option>) { let taker_fee = fees .iter() diff --git a/src/tests.rs b/src/tests.rs index 4fefeaa..ac220b7 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -4,7 +4,7 @@ mod common { use crate::models::{Position, PositionState, TradingPlatform}; use crate::models::PositionProfitState::Loss; - // TODO: generate other helper generator functions like the one below +// TODO: generate other helper generator functions like the one below // Generates two short positions with different profit/loss ratios. Both are position in "Loss". pub fn get_short_loss_positions(pair: SymbolPair) -> (Position, Position) {