diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index e731f7552..6a5991157 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -374,7 +374,7 @@ class LocalTrade: use_db: bool = False # Trades container for backtesting trades: List["LocalTrade"] = [] - trades_open: List["LocalTrade"] = [] + bt_trades_open: List["LocalTrade"] = [] # Copy of trades_open - but indexed by pair bt_trades_open_pp: Dict[str, List["LocalTrade"]] = defaultdict(list) bt_open_open_trade_count: int = 0 @@ -741,7 +741,7 @@ class LocalTrade: Resets all trades. Only active for backtesting mode. """ LocalTrade.trades = [] - LocalTrade.trades_open = [] + LocalTrade.bt_trades_open = [] LocalTrade.bt_trades_open_pp = defaultdict(list) LocalTrade.bt_open_open_trade_count = 0 LocalTrade.total_profit = 0 @@ -1418,13 +1418,13 @@ class LocalTrade: # Offline mode - without database if is_open is not None: if is_open: - sel_trades = LocalTrade.trades_open + sel_trades = LocalTrade.bt_trades_open else: sel_trades = LocalTrade.trades else: # Not used during backtesting, but might be used by a strategy - sel_trades = list(LocalTrade.trades + LocalTrade.trades_open) + sel_trades = list(LocalTrade.trades + LocalTrade.bt_trades_open) if pair: sel_trades = [trade for trade in sel_trades if trade.pair == pair] @@ -1439,7 +1439,7 @@ class LocalTrade: @staticmethod def close_bt_trade(trade): - LocalTrade.trades_open.remove(trade) + LocalTrade.bt_trades_open.remove(trade) LocalTrade.bt_trades_open_pp[trade.pair].remove(trade) LocalTrade.bt_open_open_trade_count -= 1 LocalTrade.trades.append(trade) @@ -1448,7 +1448,7 @@ class LocalTrade: @staticmethod def add_bt_trade(trade): if trade.is_open: - LocalTrade.trades_open.append(trade) + LocalTrade.bt_trades_open.append(trade) LocalTrade.bt_trades_open_pp[trade.pair].append(trade) LocalTrade.bt_open_open_trade_count += 1 else: @@ -1456,7 +1456,7 @@ class LocalTrade: @staticmethod def remove_bt_trade(trade): - LocalTrade.trades_open.remove(trade) + LocalTrade.bt_trades_open.remove(trade) LocalTrade.bt_trades_open_pp[trade.pair].remove(trade) LocalTrade.bt_open_open_trade_count -= 1 diff --git a/tests/optimize/test_backtest_detail.py b/tests/optimize/test_backtest_detail.py index edaedb81e..05f8908ee 100644 --- a/tests/optimize/test_backtest_detail.py +++ b/tests/optimize/test_backtest_detail.py @@ -1250,6 +1250,6 @@ def test_backtest_results(default_conf, mocker, caplog, data: BTContainer) -> No assert res.close_date == _get_frame_time_from_offset(trade.close_tick) assert res.is_short == trade.is_short assert len(LocalTrade.trades) == len(data.trades) - assert len(LocalTrade.trades_open) == 0 + assert len(LocalTrade.bt_trades_open) == 0 backtesting.cleanup() del backtesting diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index 1dce93112..98912b059 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -529,39 +529,39 @@ def test_backtest__enter_trade(default_conf, fee, mocker) -> None: assert trade.stake_amount == 495 # Fake 2 trades, so there's not enough amount for the next trade left. - LocalTrade.trades_open.append(trade) + LocalTrade.bt_trades_open.append(trade) backtesting.wallets.update() trade = backtesting._enter_trade(pair, row=row, direction="long") assert trade is None - LocalTrade.trades_open.pop() + LocalTrade.bt_trades_open.pop() trade = backtesting._enter_trade(pair, row=row, direction="long") assert trade is not None - LocalTrade.trades_open.pop() + LocalTrade.bt_trades_open.pop() backtesting.strategy.custom_stake_amount = lambda **kwargs: 123.5 backtesting.wallets.update() trade = backtesting._enter_trade(pair, row=row, direction="long") - LocalTrade.trades_open.pop() + LocalTrade.bt_trades_open.pop() assert trade assert trade.stake_amount == 123.5 # In case of error - use proposed stake backtesting.strategy.custom_stake_amount = lambda **kwargs: 20 / 0 trade = backtesting._enter_trade(pair, row=row, direction="long") - LocalTrade.trades_open.pop() + LocalTrade.bt_trades_open.pop() assert trade assert trade.stake_amount == 495 assert trade.is_short is False trade = backtesting._enter_trade(pair, row=row, direction="short") - LocalTrade.trades_open.pop() + LocalTrade.bt_trades_open.pop() assert trade assert trade.stake_amount == 495 assert trade.is_short is True mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=300.0) trade = backtesting._enter_trade(pair, row=row, direction="long") - LocalTrade.trades_open.pop() + LocalTrade.bt_trades_open.pop() assert trade assert trade.stake_amount == 300.0 diff --git a/tests/persistence/test_persistence.py b/tests/persistence/test_persistence.py index 0545ac861..ac153deaf 100644 --- a/tests/persistence/test_persistence.py +++ b/tests/persistence/test_persistence.py @@ -2137,7 +2137,7 @@ def test_Trade_object_idem(): ) EXCLUDES2 = ( "trades", - "trades_open", + "bt_trades_open", "bt_trades_open_pp", "bt_open_open_trade_count", "total_profit",