sell_type -> exit_type

This commit is contained in:
Sam Germain
2022-01-04 22:57:59 -06:00
parent e9d3903827
commit 0037754969
7 changed files with 56 additions and 56 deletions

View File

@@ -440,7 +440,7 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
current_time=now, current_profit=profit,
force_stoploss=0, high=None)
assert isinstance(sl_flag, SellCheckTuple)
assert sl_flag.sell_type == expected
assert sl_flag.exit_type == expected
if expected == ExitType.NONE:
assert sl_flag.sell_flag is False
else:
@@ -450,7 +450,7 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
sl_flag = strategy.stop_loss_reached(current_rate=trade.open_rate * (1 + profit2), 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 == ExitType.NONE:
assert sl_flag.sell_flag is False
else:
@@ -480,14 +480,14 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
low=None, high=None)
assert res.sell_flag is False
assert res.sell_type == ExitType.NONE
assert res.exit_type == ExitType.NONE
strategy.custom_sell = 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 == ExitType.CUSTOM_SELL
assert res.exit_type == ExitType.CUSTOM_SELL
assert res.exit_reason == 'custom_sell'
strategy.custom_sell = MagicMock(return_value='hello world')
@@ -495,7 +495,7 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
res = strategy.should_exit(trade, 1, now,
enter=False, exit_=False,
low=None, high=None)
assert res.sell_type == ExitType.CUSTOM_SELL
assert res.exit_type == ExitType.CUSTOM_SELL
assert res.sell_flag is True
assert res.exit_reason == 'hello world'
@@ -504,7 +504,7 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
res = strategy.should_exit(trade, 1, now,
enter=False, exit_=False,
low=None, high=None)
assert res.sell_type == ExitType.CUSTOM_SELL
assert res.exit_type == ExitType.CUSTOM_SELL
assert res.sell_flag is True
assert res.exit_reason == 'h' * 64
assert log_has_re('Custom sell reason returned from custom_sell is too long.*', caplog)

View File

@@ -2093,7 +2093,7 @@ def test_handle_trade_roi(default_conf_usdt, ticker_usdt, limit_order_open, fee,
caplog.clear()
patch_get_signal(freqtrade)
assert freqtrade.handle_trade(trade)
assert log_has("ETH/USDT - Required profit reached. sell_type=ExitType.ROI",
assert log_has("ETH/USDT - Required profit reached. exit_type=ExitType.ROI",
caplog)
@@ -2135,7 +2135,7 @@ def test_handle_trade_use_exit_signal(
else:
patch_get_signal(freqtrade, enter_long=False, exit_long=True)
assert freqtrade.handle_trade(trade)
assert log_has("ETH/USDT - Sell signal received. sell_type=ExitType.SELL_SIGNAL",
assert log_has("ETH/USDT - Sell signal received. exit_type=ExitType.SELL_SIGNAL",
caplog)
@@ -2855,7 +2855,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_reason=SellCheckTuple(sell_type=ExitType.ROI)
exit_reason=SellCheckTuple(exit_type=ExitType.ROI)
)
assert rpc_mock.call_count == 0
assert freqtrade.strategy.confirm_trade_exit.call_count == 1
@@ -2867,7 +2867,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_reason=SellCheckTuple(sell_type=ExitType.ROI)
exit_reason=SellCheckTuple(exit_type=ExitType.ROI)
)
assert freqtrade.strategy.confirm_trade_exit.call_count == 1
@@ -2928,7 +2928,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_reason=SellCheckTuple(sell_type=ExitType.STOP_LOSS))
exit_reason=SellCheckTuple(exit_type=ExitType.STOP_LOSS))
assert rpc_mock.call_count == 2
last_msg = rpc_mock.call_args_list[-1][0][0]
@@ -3003,7 +3003,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_reason=SellCheckTuple(sell_type=ExitType.SELL_SIGNAL)
exit_reason=SellCheckTuple(exit_type=ExitType.SELL_SIGNAL)
)
# Sell price must be different to default bid price
@@ -3074,7 +3074,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_reason=SellCheckTuple(sell_type=ExitType.STOP_LOSS))
exit_reason=SellCheckTuple(exit_type=ExitType.STOP_LOSS))
assert rpc_mock.call_count == 2
last_msg = rpc_mock.call_args_list[-1][0][0]
@@ -3134,7 +3134,7 @@ def test_execute_trade_exit_sloe_cancel_exception(
trade.stoploss_order_id = "abcd"
freqtrade.execute_trade_exit(trade=trade, limit=1234,
exit_reason=SellCheckTuple(sell_type=ExitType.STOP_LOSS))
exit_reason=SellCheckTuple(exit_type=ExitType.STOP_LOSS))
assert create_order_mock.call_count == 2
assert log_has('Could not cancel stoploss order abcd', caplog)
@@ -3189,7 +3189,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_reason=SellCheckTuple(sell_type=ExitType.STOP_LOSS)
exit_reason=SellCheckTuple(exit_type=ExitType.STOP_LOSS)
)
trade = Trade.query.first()
@@ -3328,7 +3328,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_reason=SellCheckTuple(sell_type=ExitType.ROI)
exit_reason=SellCheckTuple(exit_type=ExitType.ROI)
)
assert not trade.is_open
@@ -3392,7 +3392,7 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u
fetch_ticker=ticker_usdt_sell_up
)
exit_reason = SellCheckTuple(sell_type=ExitType.ROI)
exit_reason = SellCheckTuple(exit_type=ExitType.ROI)
assert not freqtrade.execute_trade_exit(
trade=trade,
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
@@ -3401,7 +3401,7 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u
assert mock_insuf.call_count == 1
@pytest.mark.parametrize('profit_only,bid,ask,handle_first,handle_second,sell_type,is_short', [
@pytest.mark.parametrize('profit_only,bid,ask,handle_first,handle_second,exit_type,is_short', [
# Enable profit
(True, 2.18, 2.2, False, True, ExitType.SELL_SIGNAL.value, False),
(True, 2.18, 2.2, False, True, ExitType.SELL_SIGNAL.value, True),
@@ -3418,7 +3418,7 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u
])
def test_sell_profit_only(
default_conf_usdt, limit_order, limit_order_open, is_short,
fee, mocker, profit_only, bid, ask, handle_first, handle_second, sell_type) -> None:
fee, mocker, profit_only, bid, ask, handle_first, handle_second, exit_type) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)
mocker.patch.multiple(
@@ -3441,11 +3441,11 @@ def test_sell_profit_only(
})
freqtrade = FreqtradeBot(default_conf_usdt)
patch_get_signal(freqtrade, enter_short=is_short, enter_long=not is_short)
if sell_type == ExitType.SELL_SIGNAL.value:
if exit_type == ExitType.SELL_SIGNAL.value:
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
else:
freqtrade.strategy.stop_loss_reached = MagicMock(return_value=SellCheckTuple(
sell_type=ExitType.NONE))
exit_type=ExitType.NONE))
freqtrade.enter_positions()
trade = Trade.query.first()
@@ -3561,7 +3561,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_reason=SellCheckTuple(sell_type=ExitType.STOP_LOSS)
exit_reason=SellCheckTuple(exit_type=ExitType.STOP_LOSS)
)
trade.close(ticker_usdt_sell_down()['bid'])
assert freqtrade.strategy.is_pair_locked(trade.pair)
@@ -4920,7 +4920,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_reason=SellCheckTuple(sell_type=ExitType.ROI)
exit_reason=SellCheckTuple(exit_type=ExitType.ROI)
)
assert trade.funding_fees == pytest.approx(sum(
trade.amount *

View File

@@ -52,8 +52,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=ExitType.NONE),
SellCheckTuple(sell_type=ExitType.SELL_SIGNAL)]
SellCheckTuple(exit_type=ExitType.NONE),
SellCheckTuple(exit_type=ExitType.SELL_SIGNAL)]
)
cancel_order_mock = MagicMock()
mocker.patch('freqtrade.exchange.Binance.stoploss', stoploss)
@@ -157,11 +157,11 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, limit_buy_order, moc
_notify_exit=MagicMock(),
)
should_sell_mock = MagicMock(side_effect=[
SellCheckTuple(sell_type=ExitType.NONE),
SellCheckTuple(sell_type=ExitType.SELL_SIGNAL),
SellCheckTuple(sell_type=ExitType.NONE),
SellCheckTuple(sell_type=ExitType.NONE),
SellCheckTuple(sell_type=ExitType.NONE)]
SellCheckTuple(exit_type=ExitType.NONE),
SellCheckTuple(exit_type=ExitType.SELL_SIGNAL),
SellCheckTuple(exit_type=ExitType.NONE),
SellCheckTuple(exit_type=ExitType.NONE),
SellCheckTuple(exit_type=ExitType.NONE)]
)
mocker.patch("freqtrade.strategy.interface.IStrategy.should_exit", should_sell_mock)