From 9600039686edbe960b2f83856a410acae63fee92 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 16 Feb 2023 19:47:12 +0100 Subject: [PATCH] Update dry-run fill method naming --- freqtrade/exchange/exchange.py | 8 +++----- tests/exchange/test_exchange.py | 6 +++--- tests/rpc/test_rpc.py | 10 +++++----- tests/rpc/test_rpc_apiserver.py | 2 +- tests/rpc/test_rpc_telegram.py | 10 +++++----- tests/test_freqtradebot.py | 22 +++++++++++----------- tests/test_integration.py | 8 ++++---- 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 22cce626e..c1b24b461 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -942,8 +942,8 @@ class Exchange: return rate - def _is_dry_limit_order_filled(self, pair: str, side: str, limit: float, - orderbook: Optional[OrderBook] = None) -> bool: + def _dry_is_price_crossed(self, pair: str, side: str, limit: float, + orderbook: Optional[OrderBook] = None) -> bool: if not self.exchange_has('fetchL2OrderBook'): return True if not orderbook: @@ -951,12 +951,10 @@ class Exchange: try: if side == 'buy': price = orderbook['asks'][0][0] - logger.debug(f"{pair} checking dry buy-order: price={price}, limit={limit}") if limit >= price: return True else: price = orderbook['bids'][0][0] - logger.debug(f"{pair} checking dry sell-order: price={price}, limit={limit}") if limit <= price: return True except IndexError: @@ -974,7 +972,7 @@ class Exchange: and order['type'] in ["limit"] and not order.get('ft_order_type')): pair = order['symbol'] - if self._is_dry_limit_order_filled(pair, order['side'], order['price'], orderbook): + if self._dry_is_price_crossed(pair, order['side'], order['price'], orderbook): order.update({ 'status': 'closed', 'filled': order['amount'], diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index dc97bcfde..01a5060bb 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -1223,7 +1223,7 @@ def test_create_dry_run_order_fees( 'freqtrade.exchange.Exchange.get_fee', side_effect=lambda symbol, taker_or_maker: 2.0 if taker_or_maker == 'taker' else 1.0 ) - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=price_side == 'other') exchange = get_patched_exchange(mocker, default_conf) @@ -1241,7 +1241,7 @@ def test_create_dry_run_order_fees( else: assert order['fee'] is None - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=price_side != 'other') order1 = exchange.fetch_dry_run_order(order['id']) @@ -3018,7 +3018,7 @@ def test_get_historic_trades_notsupported(default_conf, mocker, caplog, exchange def test_cancel_order_dry_run(default_conf, mocker, exchange_name): default_conf['dry_run'] = True exchange = get_patched_exchange(mocker, default_conf, id=exchange_name) - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=True) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True) assert exchange.cancel_order(order_id='123', pair='TKN/BTC') == {} assert exchange.cancel_stoploss_order(order_id='123', pair='TKN/BTC') == {} diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 4871d9b24..31e19ce3f 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -112,7 +112,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'freqtrade.exchange.Exchange', fetch_ticker=ticker, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(side_effect=[False, True]), + _dry_is_price_crossed=MagicMock(side_effect=[False, True]), ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) @@ -226,7 +226,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: freqtradebot.state = State.RUNNING with pytest.raises(RPCException, match=r'.*no active trade*'): rpc._rpc_status_table(default_conf['stake_currency'], 'USD') - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=False) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=False) freqtradebot.enter_positions() result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') @@ -237,7 +237,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: assert '0.00' == result[0][3] assert isnan(fiat_profit_sum) - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=True) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True) freqtradebot.process() result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') @@ -688,7 +688,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None: 'filled': 0.0, } ), - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), get_fee=fee, ) mocker.patch('freqtrade.wallets.Wallets.get_free', return_value=1000) @@ -726,7 +726,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None: freqtradebot.state = State.RUNNING assert cancel_order_mock.call_count == 0 mocker.patch( - 'freqtrade.exchange.Exchange._is_dry_limit_order_filled', MagicMock(return_value=False)) + 'freqtrade.exchange.Exchange._dry_is_price_crossed', MagicMock(return_value=False)) freqtradebot.enter_positions() # make an limit-buy open trade trade = Trade.query.filter(Trade.id == '3').first() diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 89a1b791d..94b210c76 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -1280,7 +1280,7 @@ def test_api_forceexit(botclient, mocker, ticker, fee, markets): fetch_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets), - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), ) patch_get_signal(ftbot) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 5e3c2bd18..855062af0 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -313,7 +313,7 @@ def test_status_handle(default_conf, update, ticker, fee, mocker) -> None: 'freqtrade.exchange.Exchange', fetch_ticker=ticker, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), ) status_table = MagicMock() mocker.patch.multiple( @@ -930,7 +930,7 @@ def test_telegram_forceexit_handle(default_conf, update, ticker, fee, 'freqtrade.exchange.Exchange', fetch_ticker=ticker, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), ) freqtradebot = FreqtradeBot(default_conf) @@ -999,7 +999,7 @@ def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee, 'freqtrade.exchange.Exchange', fetch_ticker=ticker, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), ) freqtradebot = FreqtradeBot(default_conf) @@ -1070,7 +1070,7 @@ def test_forceexit_all_handle(default_conf, update, ticker, fee, mocker) -> None 'freqtrade.exchange.Exchange', fetch_ticker=ticker, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), ) default_conf['max_open_trades'] = 4 freqtradebot = FreqtradeBot(default_conf) @@ -1155,7 +1155,7 @@ def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None: 'freqtrade.exchange.Exchange', fetch_ticker=ticker, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), ) femock = mocker.patch('freqtrade.rpc.rpc.RPC._rpc_force_exit') telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index d51a1d49f..dc4539401 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -272,7 +272,7 @@ def test_total_open_trades_stakes(mocker, default_conf_usdt, ticker_usdt, fee) - 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) freqtrade = FreqtradeBot(default_conf_usdt) patch_get_signal(freqtrade) @@ -307,7 +307,7 @@ def test_create_trade(default_conf_usdt, ticker_usdt, limit_order, 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) # Save state of current whitelist @@ -3257,7 +3257,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_ 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) patch_whitelist(mocker, default_conf_usdt) freqtrade = FreqtradeBot(default_conf_usdt) @@ -3340,7 +3340,7 @@ def test_execute_trade_exit_down(default_conf_usdt, ticker_usdt, fee, ticker_usd 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) patch_whitelist(mocker, default_conf_usdt) freqtrade = FreqtradeBot(default_conf_usdt) @@ -3409,7 +3409,7 @@ def test_execute_trade_exit_custom_exit_price( 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) config = deepcopy(default_conf_usdt) config['custom_price_max_distance_ratio'] = 0.1 @@ -3490,7 +3490,7 @@ def test_execute_trade_exit_down_stoploss_on_exchange_dry_run( 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) patch_whitelist(mocker, default_conf_usdt) freqtrade = FreqtradeBot(default_conf_usdt) @@ -3609,7 +3609,7 @@ def test_execute_trade_exit_with_stoploss_on_exchange( price_to_precision=lambda s, x, y: y, create_stoploss=stoploss, cancel_stoploss_order=cancel_order, - _is_dry_limit_order_filled=MagicMock(side_effect=[True, False]), + _dry_is_price_crossed=MagicMock(side_effect=[True, False]), ) freqtrade = FreqtradeBot(default_conf_usdt) @@ -3658,7 +3658,7 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit( get_fee=fee, amount_to_precision=lambda s, x, y: y, price_to_precision=lambda s, x, y: y, - _is_dry_limit_order_filled=MagicMock(side_effect=[False, True]), + _dry_is_price_crossed=MagicMock(side_effect=[False, True]), ) stoploss = MagicMock(return_value={ @@ -3753,7 +3753,7 @@ def test_execute_trade_exit_market_order( 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt, get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=True), + _dry_is_price_crossed=MagicMock(return_value=True), get_funding_fees=MagicMock(side_effect=ExchangeError()), ) patch_whitelist(mocker, default_conf_usdt) @@ -3771,7 +3771,7 @@ def test_execute_trade_exit_market_order( mocker.patch.multiple( 'freqtrade.exchange.Exchange', fetch_ticker=ticker_usdt_sell_up, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) freqtrade.config['order_types']['exit'] = 'market' @@ -4283,7 +4283,7 @@ def test_disable_ignore_roi_if_entry_signal(default_conf_usdt, limit_order, limi {'id': 1234553383} ]), get_fee=fee, - _is_dry_limit_order_filled=MagicMock(return_value=False), + _dry_is_price_crossed=MagicMock(return_value=False), ) default_conf_usdt['exit_pricing'] = { 'ignore_roi_if_entry_signal': False diff --git a/tests/test_integration.py b/tests/test_integration.py index 3680ddf46..4d8b282c9 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -367,7 +367,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker) amount_to_precision=lambda s, x, y: y, price_to_precision=lambda s, x, y: y, ) - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=False) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=False) mocker.patch("freqtrade.exchange.Exchange.get_max_leverage", return_value=10) mocker.patch("freqtrade.exchange.Exchange.get_funding_fees", return_value=0) mocker.patch("freqtrade.exchange.Exchange.get_maintenance_ratio_and_amt", return_value=(0, 0)) @@ -413,7 +413,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker) assert trade.initial_stop_loss_pct is None # Fill order - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=True) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True) freqtrade.process() trade = Trade.get_trades().first() assert len(trade.orders) == 2 @@ -428,7 +428,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker) # 2nd order - not filling freqtrade.strategy.adjust_trade_position = MagicMock(return_value=120) - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=False) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=False) freqtrade.process() trade = Trade.get_trades().first() @@ -452,7 +452,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker) # Fill DCA order freqtrade.strategy.adjust_trade_position = MagicMock(return_value=None) - mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=True) + mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True) freqtrade.strategy.adjust_entry_price = MagicMock(side_effect=ValueError) freqtrade.process()