clippy + reformat

This commit is contained in:
Giulio De Pasquale 2021-02-26 16:23:50 +00:00
parent f4431f26c0
commit a3ce3682ad
6 changed files with 18 additions and 12 deletions

View File

@ -123,7 +123,7 @@ impl Client {
.active_orders(pair) .active_orders(pair)
.await? .await?
.into_iter() .into_iter()
.filter(|x| &x.pair() == &pair) .filter(|x| x.pair() == pair)
.collect()) .collect())
} }

View File

@ -48,8 +48,8 @@ async fn main() -> Result<(), BoxError> {
.ok_or("API_SECRET not set!")?; .ok_or("API_SECRET not set!")?;
let bitfinex = ExchangeDetails::Bitfinex { let bitfinex = ExchangeDetails::Bitfinex {
api_key: api_key.into(), api_key,
api_secret: api_secret.into(), api_secret,
}; };
let mut bot = BfxBot::new( let mut bot = BfxBot::new(

View File

@ -416,7 +416,7 @@ impl OrderManager {
None => { self.orders_map.clear(); } None => { self.orders_map.clear(); }
Some(positions) => { Some(positions) => {
// retain only positions that are open remotely as well // 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 { for position in positions {
// mapping tracked orders to their ids // 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())) { 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, // the only check to bind an active order to an open position,
// is to check for their amount which should be identical // 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()); trace!("Adding order {} to internal mapping from remote.", remote_order.id());
self.add_to_orders_map(position.id(), remote_order.clone()); self.add_to_orders_map(position.id(), remote_order.clone());
} }
@ -439,7 +439,7 @@ impl OrderManager {
// removing local orders that are not in remote // removing local orders that are not in remote
for local_orders in self.orders_map.values_mut() { 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 // clean-up empty positions in local mapping

View File

@ -432,7 +432,7 @@ pub struct OrderMetadata {
impl Clone for OrderMetadata { impl Clone for OrderMetadata {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
position_id: self.position_id.clone(), position_id: self.position_id,
strategy: self.strategy.as_ref().map(|x| clone_box(&**x)), 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 * Positions
***************/ ***************/

View File

@ -23,14 +23,14 @@ pub trait PositionStrategy: DynClone + Send + Sync {
position: Position, position: Position,
current_tick: u64, current_tick: u64,
positions_history: &HashMap<u64, Position>, positions_history: &HashMap<u64, Position>,
fees: &Vec<TradingFees>, fees: &[TradingFees],
) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>); ) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>);
fn post_tick( fn post_tick(
&mut self, &mut self,
position: Position, position: Position,
current_tick: u64, current_tick: u64,
positions_history: &HashMap<u64, Position>, positions_history: &HashMap<u64, Position>,
fees: &Vec<TradingFees>, fees: &[TradingFees],
) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>); ) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>);
} }
@ -223,7 +223,7 @@ impl PositionStrategy for TrailingStop {
position: Position, position: Position,
current_tick: u64, current_tick: u64,
positions_history: &HashMap<u64, Position>, positions_history: &HashMap<u64, Position>,
_: &Vec<TradingFees>, _: &[TradingFees],
) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>) { ) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>) {
let pl_perc = position.pl_perc(); let pl_perc = position.pl_perc();
@ -300,7 +300,7 @@ impl PositionStrategy for TrailingStop {
position: Position, position: Position,
_: u64, _: u64,
_: &HashMap<u64, Position>, _: &HashMap<u64, Position>,
fees: &Vec<TradingFees>, fees: &[TradingFees],
) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>) { ) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>) {
let taker_fee = fees let taker_fee = fees
.iter() .iter()

View File

@ -4,7 +4,7 @@ mod common {
use crate::models::{Position, PositionState, TradingPlatform}; use crate::models::{Position, PositionState, TradingPlatform};
use crate::models::PositionProfitState::Loss; 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". // Generates two short positions with different profit/loss ratios. Both are position in "Loss".
pub fn get_short_loss_positions(pair: SymbolPair) -> (Position, Position) { pub fn get_short_loss_positions(pair: SymbolPair) -> (Position, Position) {