mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
move "add_bt_trade" call for entries into enter_trade function
This commit is contained in:
@@ -964,6 +964,7 @@ class Backtesting:
|
||||
contract_size=contract_size,
|
||||
orders=[],
|
||||
)
|
||||
LocalTrade.add_bt_trade(trade)
|
||||
|
||||
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True)
|
||||
|
||||
@@ -1196,8 +1197,6 @@ class Backtesting:
|
||||
# This emulates previous behavior - not sure if this is correct
|
||||
# Prevents entering if the trade-slot was freed in this candle
|
||||
open_trade_count_start += 1
|
||||
# logger.debug(f"{pair} - Emulate creation of new trade: {trade}.")
|
||||
LocalTrade.add_bt_trade(trade)
|
||||
self.wallets.update()
|
||||
else:
|
||||
self._collate_rejected(pair, row)
|
||||
|
||||
@@ -501,34 +501,38 @@ def test_backtest__enter_trade(default_conf, fee, mocker) -> None:
|
||||
|
||||
# Fake 2 trades, so there's not enough amount for the next trade left.
|
||||
LocalTrade.trades_open.append(trade)
|
||||
LocalTrade.trades_open.append(trade)
|
||||
backtesting.wallets.update()
|
||||
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
||||
assert trade is None
|
||||
LocalTrade.trades_open.pop()
|
||||
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
||||
assert trade is not None
|
||||
LocalTrade.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()
|
||||
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()
|
||||
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()
|
||||
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()
|
||||
assert trade
|
||||
assert trade.stake_amount == 300.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user