From ab7cdca68e74aae558a2ced642f3c7fa6798e5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Sat, 26 Mar 2022 10:44:59 +0530 Subject: [PATCH] updated requested changes in PR #6545 --- freqtrade/exchange/exchange.py | 7 ++++--- freqtrade/freqtradebot.py | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 9cac00045..454d426c5 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1139,7 +1139,7 @@ class Exchange: conf_strategy = self._config.get(strat_name, {}) - if conf_strategy.get('use_order_book', False) and ('use_order_book' in conf_strategy): + if conf_strategy.get('use_order_book', False): order_book_top = conf_strategy.get('order_book_top', 1) if order_book is None: @@ -1178,14 +1178,15 @@ class Exchange: return rate def get_rates(self, pair: str, refresh: bool) -> Tuple[float, float]: - buy_rate = sell_rate = None + buy_rate = None + sell_rate = None if not refresh: buy_rate, sell_rate = self._buy_rate_cache.get(pair), self._sell_rate_cache.get(pair) bid_strategy = self._config.get('bid_strategy', {}) ask_strategy = self._config.get('ask_strategy', {}) order_book = ticker = None - if bid_strategy.get('use_order_book', False) and ('use_order_book' in bid_strategy): + if bid_strategy.get('use_order_book', False): order_book_top = max(bid_strategy.get('order_book_top', 1), ask_strategy.get('order_book_top', 1)) order_book = self.fetch_l2_order_book(pair, order_book_top) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 8a1c272ed..44e3867be 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -454,20 +454,27 @@ class FreqtradeBot(LoggingMixin): Once that completes, the existing trade is modified to match new data. """ current_entry_rate, current_exit_rate = self.exchange.get_rates(trade.pair, True) - current_rate = current_entry_rate # backward compatibilty - current_profit = trade.calc_profit_ratio(current_rate) - min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair, - current_rate, - self.strategy.stoploss) - max_stake_amount = self.wallets.get_available_stake_amount() + current_entry_profit = trade.calc_profit_ratio(current_entry_rate) + current_exit_profit = trade.calc_profit_ratio(current_exit_rate) + + min_entry_stake = self.exchange.get_min_pair_stake_amount(trade.pair, + current_entry_rate, + self.strategy.stoploss) + min_exit_stake = self.exchange.get_min_pair_stake_amount(trade.pair, + current_exit_rate, + self.strategy.stoploss) + max_stake = self.wallets.get_available_stake_amount() logger.debug(f"Calling adjust_trade_position for pair {trade.pair}") stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position, default_retval=None)( - trade=trade, current_time=datetime.now(timezone.utc), current_rate=current_rate, - current_profit=current_profit, min_stake=min_stake_amount, - max_stake=max_stake_amount, current_entry_rate=current_entry_rate, - current_exit_rate=current_exit_rate) + trade=trade, current_time=datetime.now(timezone.utc), current_rate=current_entry_rate, + current_profit=current_entry_profit, min_stake=min_entry_stake, + max_stake=max_stake, + current_entry_rate=current_entry_rate, current_exit_rate=current_exit_rate, + current_entry_profit=current_entry_profit, current_exit_profit=current_exit_profit, + min_entry_stake=min_entry_stake, min_exit_stake=min_exit_stake + ) if stake_amount is not None and stake_amount > 0.0: # We should increase our position @@ -484,7 +491,7 @@ class FreqtradeBot(LoggingMixin): # We should decrease our position # Strategy should return value as Decimal for accuracy. amount = abs(float(Decimal(stake_amount) / Decimal(current_exit_rate))) - if trade.amount - amount < min_stake_amount: + if trade.amount - amount < min_exit_stake_amount: logger.info('Remaining amount would be too small') return if amount > trade.amount: