Update SellCheckTuple to new naming
This commit is contained in:
@@ -18,7 +18,7 @@ from freqtrade.persistence import PairLocks, Trade
|
||||
from freqtrade.resolvers import StrategyResolver
|
||||
from freqtrade.strategy.hyper import (BaseParameter, BooleanParameter, CategoricalParameter,
|
||||
DecimalParameter, IntParameter, RealParameter)
|
||||
from freqtrade.strategy.interface import SellCheckTuple
|
||||
from freqtrade.strategy.interface import ExitCheckTuple
|
||||
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
||||
from tests.conftest import CURRENT_TEST_STRATEGY, TRADE_SIDES, log_has, log_has_re
|
||||
|
||||
@@ -455,23 +455,23 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
|
||||
sl_flag = strategy.stop_loss_reached(current_rate=current_rate, trade=trade,
|
||||
current_time=now, current_profit=profit,
|
||||
force_stoploss=0, high=None)
|
||||
assert isinstance(sl_flag, SellCheckTuple)
|
||||
assert sl_flag.sell_type == expected
|
||||
assert isinstance(sl_flag, ExitCheckTuple)
|
||||
assert sl_flag.exit_type == expected
|
||||
if expected == SellType.NONE:
|
||||
assert sl_flag.sell_flag is False
|
||||
assert sl_flag.exit_flag is False
|
||||
else:
|
||||
assert sl_flag.sell_flag is True
|
||||
assert sl_flag.exit_flag is True
|
||||
assert round(trade.stop_loss, 2) == adjusted
|
||||
current_rate2 = trade.open_rate * (1 + profit2)
|
||||
|
||||
sl_flag = strategy.stop_loss_reached(current_rate=current_rate2, trade=trade,
|
||||
current_time=now, current_profit=profit2,
|
||||
force_stoploss=0, high=None)
|
||||
assert sl_flag.sell_type == expected2
|
||||
assert sl_flag.exit_type == expected2
|
||||
if expected2 == SellType.NONE:
|
||||
assert sl_flag.sell_flag is False
|
||||
assert sl_flag.exit_flag is False
|
||||
else:
|
||||
assert sl_flag.sell_flag is True
|
||||
assert sl_flag.exit_flag is True
|
||||
assert round(trade.stop_loss, 2) == adjusted2
|
||||
|
||||
strategy.custom_stoploss = original_stopvalue
|
||||
@@ -496,34 +496,34 @@ def test_custom_exit(default_conf, fee, caplog) -> None:
|
||||
enter=False, exit_=False,
|
||||
low=None, high=None)
|
||||
|
||||
assert res.sell_flag is False
|
||||
assert res.sell_type == SellType.NONE
|
||||
assert res.exit_flag is False
|
||||
assert res.exit_type == SellType.NONE
|
||||
|
||||
strategy.custom_exit = MagicMock(return_value=True)
|
||||
res = strategy.should_exit(trade, 1, now,
|
||||
enter=False, exit_=False,
|
||||
low=None, high=None)
|
||||
assert res.sell_flag is True
|
||||
assert res.sell_type == SellType.CUSTOM_SELL
|
||||
assert res.sell_reason == 'custom_sell'
|
||||
assert res.exit_flag is True
|
||||
assert res.exit_type == SellType.CUSTOM_SELL
|
||||
assert res.exit_reason == 'custom_sell'
|
||||
|
||||
strategy.custom_exit = MagicMock(return_value='hello world')
|
||||
|
||||
res = strategy.should_exit(trade, 1, now,
|
||||
enter=False, exit_=False,
|
||||
low=None, high=None)
|
||||
assert res.sell_type == SellType.CUSTOM_SELL
|
||||
assert res.sell_flag is True
|
||||
assert res.sell_reason == 'hello world'
|
||||
assert res.exit_type == SellType.CUSTOM_SELL
|
||||
assert res.exit_flag is True
|
||||
assert res.exit_reason == 'hello world'
|
||||
|
||||
caplog.clear()
|
||||
strategy.custom_exit = MagicMock(return_value='h' * 100)
|
||||
res = strategy.should_exit(trade, 1, now,
|
||||
enter=False, exit_=False,
|
||||
low=None, high=None)
|
||||
assert res.sell_type == SellType.CUSTOM_SELL
|
||||
assert res.sell_flag is True
|
||||
assert res.sell_reason == 'h' * 64
|
||||
assert res.exit_type == SellType.CUSTOM_SELL
|
||||
assert res.exit_flag is True
|
||||
assert res.exit_reason == 'h' * 64
|
||||
assert log_has_re('Custom sell reason returned from custom_exit is too long.*', caplog)
|
||||
|
||||
|
||||
|
@@ -20,7 +20,7 @@ from freqtrade.exceptions import (DependencyException, ExchangeError, Insufficie
|
||||
from freqtrade.freqtradebot import FreqtradeBot
|
||||
from freqtrade.persistence import Order, PairLocks, Trade
|
||||
from freqtrade.persistence.models import PairLock
|
||||
from freqtrade.strategy.interface import SellCheckTuple
|
||||
from freqtrade.strategy.interface import ExitCheckTuple
|
||||
from freqtrade.worker import Worker
|
||||
from tests.conftest import (create_mock_trades, get_patched_freqtradebot, get_patched_worker,
|
||||
log_has, log_has_re, patch_edge, patch_exchange, patch_get_signal,
|
||||
@@ -3100,7 +3100,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=(ticker_usdt_sell_down()['ask'] if is_short else ticker_usdt_sell_up()['bid']),
|
||||
exit_check=SellCheckTuple(sell_type=SellType.ROI)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.ROI)
|
||||
)
|
||||
assert rpc_mock.call_count == 0
|
||||
assert freqtrade.strategy.confirm_trade_exit.call_count == 1
|
||||
@@ -3112,7 +3112,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=(ticker_usdt_sell_down()['ask'] if is_short else ticker_usdt_sell_up()['bid']),
|
||||
exit_check=SellCheckTuple(sell_type=SellType.ROI)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.ROI)
|
||||
)
|
||||
assert freqtrade.strategy.confirm_trade_exit.call_count == 1
|
||||
|
||||
@@ -3173,7 +3173,7 @@ def test_execute_trade_exit_down(default_conf_usdt, ticker_usdt, fee, ticker_usd
|
||||
)
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade, limit=(ticker_usdt_sell_up if is_short else ticker_usdt_sell_down)()['bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS))
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.STOP_LOSS))
|
||||
|
||||
assert rpc_mock.call_count == 2
|
||||
last_msg = rpc_mock.call_args_list[-1][0][0]
|
||||
@@ -3248,7 +3248,7 @@ def test_execute_trade_exit_custom_exit_price(
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.SELL_SIGNAL)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.SELL_SIGNAL)
|
||||
)
|
||||
|
||||
# Sell price must be different to default bid price
|
||||
@@ -3319,7 +3319,7 @@ def test_execute_trade_exit_down_stoploss_on_exchange_dry_run(
|
||||
trade.stop_loss = 2.0 * 1.01 if is_short else 2.0 * 0.99
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade, limit=(ticker_usdt_sell_up if is_short else ticker_usdt_sell_down())['bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS))
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.STOP_LOSS))
|
||||
|
||||
assert rpc_mock.call_count == 2
|
||||
last_msg = rpc_mock.call_args_list[-1][0][0]
|
||||
@@ -3379,7 +3379,7 @@ def test_execute_trade_exit_sloe_cancel_exception(
|
||||
trade.stoploss_order_id = "abcd"
|
||||
|
||||
freqtrade.execute_trade_exit(trade=trade, limit=1234,
|
||||
exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS))
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.STOP_LOSS))
|
||||
assert create_order_mock.call_count == 2
|
||||
assert log_has('Could not cancel stoploss order abcd', caplog)
|
||||
|
||||
@@ -3434,7 +3434,7 @@ def test_execute_trade_exit_with_stoploss_on_exchange(
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.STOP_LOSS)
|
||||
)
|
||||
|
||||
trade = Trade.query.first()
|
||||
@@ -3579,7 +3579,7 @@ def test_execute_trade_exit_market_order(
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.ROI)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.ROI)
|
||||
)
|
||||
|
||||
assert not trade.is_open
|
||||
@@ -3643,7 +3643,7 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u
|
||||
fetch_ticker=ticker_usdt_sell_up
|
||||
)
|
||||
|
||||
sell_reason = SellCheckTuple(sell_type=SellType.ROI)
|
||||
sell_reason = ExitCheckTuple(exit_type=SellType.ROI)
|
||||
assert not freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
|
||||
@@ -3696,8 +3696,8 @@ def test_sell_profit_only(
|
||||
if sell_type == SellType.SELL_SIGNAL.value:
|
||||
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
||||
else:
|
||||
freqtrade.strategy.stop_loss_reached = MagicMock(return_value=SellCheckTuple(
|
||||
sell_type=SellType.NONE))
|
||||
freqtrade.strategy.stop_loss_reached = MagicMock(return_value=ExitCheckTuple(
|
||||
exit_type=SellType.NONE))
|
||||
freqtrade.enter_positions()
|
||||
|
||||
trade = Trade.query.first()
|
||||
@@ -3816,7 +3816,7 @@ def test_locked_pairs(default_conf_usdt, ticker_usdt, fee,
|
||||
freqtrade.execute_trade_exit(
|
||||
trade=trade,
|
||||
limit=ticker_usdt_sell_down()['ask' if is_short else 'bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.STOP_LOSS)
|
||||
)
|
||||
trade.close(ticker_usdt_sell_down()['bid'])
|
||||
assert freqtrade.strategy.is_pair_locked(trade.pair)
|
||||
@@ -5145,7 +5145,7 @@ def test_update_funding_fees(
|
||||
trade=trade,
|
||||
# The values of the next 2 params are irrelevant for this test
|
||||
limit=ticker_usdt_sell_up()['bid'],
|
||||
exit_check=SellCheckTuple(sell_type=SellType.ROI)
|
||||
exit_check=ExitCheckTuple(exit_type=SellType.ROI)
|
||||
)
|
||||
assert trade.funding_fees == pytest.approx(sum(
|
||||
trade.amount *
|
||||
|
@@ -6,7 +6,7 @@ from freqtrade.enums import SellType
|
||||
from freqtrade.persistence import Trade
|
||||
from freqtrade.persistence.models import Order
|
||||
from freqtrade.rpc.rpc import RPC
|
||||
from freqtrade.strategy.interface import SellCheckTuple
|
||||
from freqtrade.strategy.interface import ExitCheckTuple
|
||||
from tests.conftest import get_patched_freqtradebot, patch_get_signal
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
||||
side_effect=[stoploss_order_closed, stoploss_order_open, stoploss_order_open])
|
||||
# Sell 3rd trade (not called for the first trade)
|
||||
should_sell_mock = MagicMock(side_effect=[
|
||||
SellCheckTuple(sell_type=SellType.NONE),
|
||||
SellCheckTuple(sell_type=SellType.SELL_SIGNAL)]
|
||||
ExitCheckTuple(exit_type=SellType.NONE),
|
||||
ExitCheckTuple(exit_type=SellType.SELL_SIGNAL)]
|
||||
)
|
||||
cancel_order_mock = MagicMock()
|
||||
mocker.patch('freqtrade.exchange.Binance.stoploss', stoploss)
|
||||
@@ -161,11 +161,11 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, mocker, balance_rati
|
||||
_notify_exit=MagicMock(),
|
||||
)
|
||||
should_sell_mock = MagicMock(side_effect=[
|
||||
SellCheckTuple(sell_type=SellType.NONE),
|
||||
SellCheckTuple(sell_type=SellType.SELL_SIGNAL),
|
||||
SellCheckTuple(sell_type=SellType.NONE),
|
||||
SellCheckTuple(sell_type=SellType.NONE),
|
||||
SellCheckTuple(sell_type=SellType.NONE)]
|
||||
ExitCheckTuple(exit_type=SellType.NONE),
|
||||
ExitCheckTuple(exit_type=SellType.SELL_SIGNAL),
|
||||
ExitCheckTuple(exit_type=SellType.NONE),
|
||||
ExitCheckTuple(exit_type=SellType.NONE),
|
||||
ExitCheckTuple(exit_type=SellType.NONE)]
|
||||
)
|
||||
mocker.patch("freqtrade.strategy.interface.IStrategy.should_exit", should_sell_mock)
|
||||
|
||||
|
Reference in New Issue
Block a user