From db2f0660fa1185be32b57ea92f97ec701222cf71 Mon Sep 17 00:00:00 2001 From: Reigo Reinmets Date: Sat, 18 Dec 2021 11:15:59 +0200 Subject: [PATCH] Some more compatibility fixes. --- freqtrade/freqtradebot.py | 3 ++- freqtrade/optimize/backtesting.py | 6 +++--- tests/optimize/test_backtesting_adjust_position.py | 2 +- tests/strategy/strats/strategy_test_v2.py | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 5a94dcb1f..8aca76a5f 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -598,7 +598,7 @@ class FreqtradeBot(LoggingMixin): # Fee is applied twice because we make a LIMIT_BUY and LIMIT_SELL fee = self.exchange.get_fee(symbol=pair, taker_or_maker='maker') - if not pos_adjust: + if trade is None: trade = Trade( pair=pair, stake_amount=stake_amount, @@ -616,6 +616,7 @@ class FreqtradeBot(LoggingMixin): buy_tag=buy_tag, timeframe=timeframe_to_minutes(self.config['timeframe']) ) + trade.fee_open_currency = None trade.fee_open_currency = order_id trade.orders.append(order_obj) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 2c6d509f7..e5585463c 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -24,7 +24,7 @@ from freqtrade.mixins import LoggingMixin from freqtrade.optimize.bt_progress import BTProgress from freqtrade.optimize.optimize_reports import (generate_backtest_stats, show_backtest_results, store_backtest_stats) -from freqtrade.persistence import LocalTrade, PairLocks, Trade, Order +from freqtrade.persistence import LocalTrade, Order, PairLocks, Trade from freqtrade.plugins.pairlistmanager import PairListManager from freqtrade.plugins.protectionmanager import ProtectionManager from freqtrade.resolvers import ExchangeResolver, StrategyResolver @@ -352,7 +352,7 @@ class Backtesting: return sell_row[OPEN_IDX] def _get_adjust_trade_entry_for_candle(self, trade: LocalTrade, row: Tuple - ) -> Optional[LocalTrade]: + ) -> LocalTrade: current_profit = trade.calc_profit_ratio(row[OPEN_IDX]) @@ -368,7 +368,7 @@ class Backtesting: return trade def _execute_trade_position_change(self, trade: LocalTrade, row: Tuple, - stake_amount: float) -> Optional[LocalTrade]: + stake_amount: float) -> LocalTrade: current_price = row[OPEN_IDX] propose_rate = min(max(current_price, row[LOW_IDX]), row[HIGH_IDX]) available_amount = self.wallets.get_available_stake_amount() diff --git a/tests/optimize/test_backtesting_adjust_position.py b/tests/optimize/test_backtesting_adjust_position.py index 4d87da503..03a3339d4 100644 --- a/tests/optimize/test_backtesting_adjust_position.py +++ b/tests/optimize/test_backtesting_adjust_position.py @@ -8,7 +8,7 @@ from freqtrade.data import history from freqtrade.data.history import get_timerange from freqtrade.enums import SellType from freqtrade.optimize.backtesting import Backtesting -from tests.conftest import (patch_exchange) +from tests.conftest import patch_exchange def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) -> None: diff --git a/tests/strategy/strats/strategy_test_v2.py b/tests/strategy/strats/strategy_test_v2.py index 6dce14f42..6371c1029 100644 --- a/tests/strategy/strats/strategy_test_v2.py +++ b/tests/strategy/strats/strategy_test_v2.py @@ -1,12 +1,13 @@ # pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement +from datetime import datetime + import talib.abstract as ta from pandas import DataFrame import freqtrade.vendor.qtpylib.indicators as qtpylib -from freqtrade.strategy.interface import IStrategy from freqtrade.persistence import Trade -from datetime import datetime +from freqtrade.strategy.interface import IStrategy class StrategyTestV2(IStrategy):