diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 2b8bd1e2b..35e524f69 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -197,6 +197,7 @@ class Backtesting: if not pair_data.empty: pair_data.loc[:, 'buy'] = 0 # cleanup if buy_signal is exist pair_data.loc[:, 'sell'] = 0 # cleanup if sell_signal is exist + pair_data.loc[:, 'buy_signal_name'] = '' # cleanup if buy_signal_name is exist df_analyzed = self.strategy.advise_sell( self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair})[headers].copy() @@ -205,6 +206,7 @@ class Backtesting: # from the previous candle df_analyzed.loc[:, 'buy'] = df_analyzed.loc[:, 'buy'].shift(1) df_analyzed.loc[:, 'sell'] = df_analyzed.loc[:, 'sell'].shift(1) + df_analyzed.loc[:, 'buy_signal_name'] = df_analyzed.loc[:, 'buy_signal_name'].shift(1) df_analyzed.drop(df_analyzed.head(1).index, inplace=True) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index cbd19e156..6ff499199 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -404,6 +404,7 @@ class IStrategy(ABC, HyperStrategyMixin): logger.debug("Skipping TA Analysis for already analyzed candle") dataframe['buy'] = 0 dataframe['sell'] = 0 + dataframe['buy_signal_name'] = '' # Other Defs in strategy that want to be called every loop here # twitter_sell = self.watch_twitter_feed(dataframe, metadata) diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index 30d86f979..102d62273 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -482,6 +482,7 @@ def test_backtest__enter_trade(default_conf, fee, mocker) -> None: 0, # Sell 0.00099, # Low 0.0012, # High + '', # Buy Signal Name ] trade = backtesting._enter_trade(pair, row=row) assert isinstance(trade, LocalTrade) diff --git a/tests/plugins/test_pairlist.py b/tests/plugins/test_pairlist.py index ae8f6e958..3dee47599 100644 --- a/tests/plugins/test_pairlist.py +++ b/tests/plugins/test_pairlist.py @@ -769,20 +769,20 @@ def test_spreadfilter_invalid_data(mocker, default_conf, markets, tickers, caplo get_tickers=tickers ) - ftbot = get_patched_freqtradebot(mocker, default_conf) - ftbot.pairlists.refresh_pairlist() + freqtrade = get_patched_freqtradebot(mocker, default_conf) + freqtrade.pairlists.refresh_pairlist() - assert len(ftbot.pairlists.whitelist) == 5 + assert len(freqtrade.pairlists.whitelist) == 5 tickers.return_value['ETH/BTC']['ask'] = 0.0 del tickers.return_value['TKN/BTC'] del tickers.return_value['LTC/BTC'] mocker.patch.multiple('freqtrade.exchange.Exchange', get_tickers=tickers) - ftbot.pairlists.refresh_pairlist() + freqtrade.pairlists.refresh_pairlist() assert log_has_re(r'Removed .* invalid ticker data.*', caplog) - assert len(ftbot.pairlists.whitelist) == 2 + assert len(freqtrade.pairlists.whitelist) == 2 @pytest.mark.parametrize("pairlistconfig,desc_expected,exception_expected", [ diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index cc29dc157..3d1896a4d 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -35,7 +35,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) freqtradebot.state = State.RUNNING @@ -69,6 +69,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'min_rate': ANY, 'max_rate': ANY, 'strategy': ANY, + 'buy_signal_name': ANY, 'timeframe': 5, 'open_order_id': ANY, 'close_date': None, @@ -135,6 +136,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'min_rate': ANY, 'max_rate': ANY, 'strategy': ANY, + 'buy_signal_name': ANY, 'timeframe': ANY, 'open_order_id': ANY, 'close_date': None, @@ -190,7 +192,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: ) del default_conf['fiat_display_currency'] freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) freqtradebot.state = State.RUNNING @@ -237,7 +239,7 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee, ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) stake_currency = default_conf['stake_currency'] fiat_display_currency = default_conf['fiat_display_currency'] @@ -369,7 +371,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee, ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) stake_currency = default_conf['stake_currency'] fiat_display_currency = default_conf['fiat_display_currency'] @@ -457,7 +459,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee, ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) stake_currency = default_conf['stake_currency'] fiat_display_currency = default_conf['fiat_display_currency'] @@ -524,7 +526,7 @@ def test_rpc_balance_handle_error(default_conf, mocker): ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) rpc._fiat_converter = CryptoToFiatConverter() with pytest.raises(RPCException, match="Error getting current tickers."): @@ -565,7 +567,7 @@ def test_rpc_balance_handle(default_conf, mocker, tickers): ) default_conf['dry_run'] = False freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) rpc._fiat_converter = CryptoToFiatConverter() @@ -610,7 +612,7 @@ def test_rpc_start(mocker, default_conf) -> None: ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) freqtradebot.state = State.STOPPED @@ -631,7 +633,7 @@ def test_rpc_stop(mocker, default_conf) -> None: ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) freqtradebot.state = State.RUNNING @@ -653,7 +655,7 @@ def test_rpc_stopbuy(mocker, default_conf) -> None: ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) freqtradebot.state = State.RUNNING @@ -685,7 +687,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None: mocker.patch('freqtrade.wallets.Wallets.get_free', return_value=1000) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) freqtradebot.state = State.STOPPED @@ -803,7 +805,7 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee, ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) # Create some test data @@ -836,7 +838,7 @@ def test_rpc_count(mocker, default_conf, ticker, fee) -> None: ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) counts = rpc._rpc_count() @@ -861,7 +863,7 @@ def test_rpcforcebuy(mocker, default_conf, ticker, fee, limit_buy_order_open) -> ) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) pair = 'ETH/BTC' trade = rpc._rpc_forcebuy(pair, None) @@ -887,7 +889,7 @@ def test_rpcforcebuy(mocker, default_conf, ticker, fee, limit_buy_order_open) -> # Test not buying freqtradebot = get_patched_freqtradebot(mocker, default_conf) freqtradebot.config['stake_amount'] = 0.0000001 - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) pair = 'TKN/BTC' trade = rpc._rpc_forcebuy(pair, None) @@ -900,7 +902,7 @@ def test_rpcforcebuy_stopped(mocker, default_conf) -> None: mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) pair = 'ETH/BTC' with pytest.raises(RPCException, match=r'trader is not running'): @@ -911,7 +913,7 @@ def test_rpcforcebuy_disabled(mocker, default_conf) -> None: mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) freqtradebot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) rpc = RPC(freqtradebot) pair = 'ETH/BTC' with pytest.raises(RPCException, match=r'Forcebuy not enabled.'): diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index b8dd112c9..1ab7f178e 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -45,11 +45,11 @@ def botclient(default_conf, mocker): "password": _TEST_PASS, }}) - ftbot = get_patched_freqtradebot(mocker, default_conf) - rpc = RPC(ftbot) + freqtrade = get_patched_freqtradebot(mocker, default_conf) + rpc = RPC(freqtrade) mocker.patch('freqtrade.rpc.api_server.ApiServer.start_api', MagicMock()) apiserver = ApiServer(rpc, default_conf) - yield ftbot, TestClient(apiserver.app) + yield freqtrade, TestClient(apiserver.app) # Cleanup ... ? @@ -83,7 +83,7 @@ def assert_response(response, expected_code=200, needs_cors=True): def test_api_not_found(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/invalid_url") assert_response(rc, 404) @@ -91,7 +91,7 @@ def test_api_not_found(botclient): def test_api_ui_fallback(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, "/favicon.ico") assert rc.status_code == 200 @@ -126,7 +126,7 @@ def test_api_auth(): def test_api_unauthorized(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client.get(f"{BASE_URI}/ping") assert_response(rc, needs_cors=False) assert rc.json() == {'status': 'pong'} @@ -137,20 +137,20 @@ def test_api_unauthorized(botclient): assert rc.json() == {'detail': 'Unauthorized'} # Change only username - ftbot.config['api_server']['username'] = 'Ftrader' + freqtrade.config['api_server']['username'] = 'Ftrader' rc = client_get(client, f"{BASE_URI}/version") assert_response(rc, 401) assert rc.json() == {'detail': 'Unauthorized'} # Change only password - ftbot.config['api_server']['username'] = _TEST_USER - ftbot.config['api_server']['password'] = 'WrongPassword' + freqtrade.config['api_server']['username'] = _TEST_USER + freqtrade.config['api_server']['password'] = 'WrongPassword' rc = client_get(client, f"{BASE_URI}/version") assert_response(rc, 401) assert rc.json() == {'detail': 'Unauthorized'} - ftbot.config['api_server']['username'] = 'Ftrader' - ftbot.config['api_server']['password'] = 'WrongPassword' + freqtrade.config['api_server']['username'] = 'Ftrader' + freqtrade.config['api_server']['password'] = 'WrongPassword' rc = client_get(client, f"{BASE_URI}/version") assert_response(rc, 401) @@ -158,7 +158,7 @@ def test_api_unauthorized(botclient): def test_api_token_login(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client.post(f"{BASE_URI}/token/login", data=None, headers={'Authorization': _basic_auth_str('WRONG_USER', 'WRONG_PASS'), @@ -177,7 +177,7 @@ def test_api_token_login(botclient): def test_api_token_refresh(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_post(client, f"{BASE_URI}/token/login") assert_response(rc) rc = client.post(f"{BASE_URI}/token/refresh", @@ -190,12 +190,12 @@ def test_api_token_refresh(botclient): def test_api_stop_workflow(botclient): - ftbot, client = botclient - assert ftbot.state == State.RUNNING + freqtrade, client = botclient + assert freqtrade.state == State.RUNNING rc = client_post(client, f"{BASE_URI}/stop") assert_response(rc) assert rc.json() == {'status': 'stopping trader ...'} - assert ftbot.state == State.STOPPED + assert freqtrade.state == State.STOPPED # Stop bot again rc = client_post(client, f"{BASE_URI}/stop") @@ -206,7 +206,7 @@ def test_api_stop_workflow(botclient): rc = client_post(client, f"{BASE_URI}/start") assert_response(rc) assert rc.json() == {'status': 'starting trader ...'} - assert ftbot.state == State.RUNNING + assert freqtrade.state == State.RUNNING # Call start again rc = client_post(client, f"{BASE_URI}/start") @@ -358,32 +358,32 @@ def test_api_cleanup(default_conf, mocker, caplog): def test_api_reloadconf(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_post(client, f"{BASE_URI}/reload_config") assert_response(rc) assert rc.json() == {'status': 'Reloading config ...'} - assert ftbot.state == State.RELOAD_CONFIG + assert freqtrade.state == State.RELOAD_CONFIG def test_api_stopbuy(botclient): - ftbot, client = botclient - assert ftbot.config['max_open_trades'] != 0 + freqtrade, client = botclient + assert freqtrade.config['max_open_trades'] != 0 rc = client_post(client, f"{BASE_URI}/stopbuy") assert_response(rc) assert rc.json() == {'status': 'No more buy will occur from now. Run /reload_config to reset.'} - assert ftbot.config['max_open_trades'] == 0 + assert freqtrade.config['max_open_trades'] == 0 def test_api_balance(botclient, mocker, rpc_balance): - ftbot, client = botclient + freqtrade, client = botclient - ftbot.config['dry_run'] = False + freqtrade.config['dry_run'] = False mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance) mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination', side_effect=lambda a, b: f"{a}/{b}") - ftbot.wallets.update() + freqtrade.wallets.update() rc = client_get(client, f"{BASE_URI}/balance") assert_response(rc) @@ -400,8 +400,8 @@ def test_api_balance(botclient, mocker, rpc_balance): def test_api_count(botclient, mocker, ticker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -422,13 +422,13 @@ def test_api_count(botclient, mocker, ticker, fee, markets): assert rc.json()["current"] == 4 assert rc.json()["max"] == 1 - ftbot.config['max_open_trades'] = float('inf') + freqtrade.config['max_open_trades'] = float('inf') rc = client_get(client, f"{BASE_URI}/count") assert rc.json()["max"] == -1 def test_api_locks(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/locks") assert_response(rc) @@ -462,8 +462,8 @@ def test_api_locks(botclient): def test_api_show_config(botclient, mocker): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) rc = client_get(client, f"{BASE_URI}/show_config") assert_response(rc) @@ -480,8 +480,8 @@ def test_api_show_config(botclient, mocker): def test_api_daily(botclient, mocker, ticker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -498,8 +498,8 @@ def test_api_daily(botclient, mocker, ticker, fee, markets): def test_api_trades(botclient, mocker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', markets=PropertyMock(return_value=markets) @@ -526,8 +526,8 @@ def test_api_trades(botclient, mocker, fee, markets): def test_api_trade_single(botclient, mocker, fee, ticker, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', markets=PropertyMock(return_value=markets), @@ -546,8 +546,8 @@ def test_api_trade_single(botclient, mocker, fee, ticker, markets): def test_api_delete_trade(botclient, mocker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) stoploss_mock = MagicMock() cancel_mock = MagicMock() mocker.patch.multiple( @@ -562,7 +562,7 @@ def test_api_delete_trade(botclient, mocker, fee, markets): create_mock_trades(fee) Trade.query.session.flush() - ftbot.strategy.order_types['stoploss_on_exchange'] = True + freqtrade.strategy.order_types['stoploss_on_exchange'] = True trades = Trade.query.all() trades[1].stoploss_order_id = '1234' assert len(trades) > 2 @@ -588,7 +588,7 @@ def test_api_delete_trade(botclient, mocker, fee, markets): def test_api_logs(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/logs") assert_response(rc) assert len(rc.json()) == 2 @@ -620,8 +620,8 @@ def test_api_logs(botclient): def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -636,8 +636,8 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): @pytest.mark.usefixtures("init_persistence") def test_api_profit(botclient, mocker, ticker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -683,8 +683,8 @@ def test_api_profit(botclient, mocker, ticker, fee, markets): @pytest.mark.usefixtures("init_persistence") def test_api_stats(botclient, mocker, ticker, fee, markets,): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -711,8 +711,8 @@ def test_api_stats(botclient, mocker, ticker, fee, markets,): def test_api_performance(botclient, fee): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) trade = Trade( pair='LTC/ETH', @@ -757,8 +757,8 @@ def test_api_performance(botclient, fee): def test_api_status(botclient, mocker, ticker, fee, markets): - ftbot, client = botclient - patch_get_signal(ftbot, (True, False)) + freqtrade, client = botclient + patch_get_signal(freqtrade, (True, False, '')) mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -845,7 +845,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets): def test_api_version(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/version") assert_response(rc) @@ -853,7 +853,7 @@ def test_api_version(botclient): def test_api_blacklist(botclient, mocker): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/blacklist") assert_response(rc) @@ -888,7 +888,7 @@ def test_api_blacklist(botclient, mocker): def test_api_whitelist(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/whitelist") assert_response(rc) @@ -900,7 +900,7 @@ def test_api_whitelist(botclient): def test_api_forcebuy(botclient, mocker, fee): - ftbot, client = botclient + freqtrade, client = botclient rc = client_post(client, f"{BASE_URI}/forcebuy", data='{"pair": "ETH/BTC"}') @@ -908,7 +908,7 @@ def test_api_forcebuy(botclient, mocker, fee): assert rc.json() == {"error": "Error querying /api/v1/forcebuy: Forcebuy not enabled."} # enable forcebuy - ftbot.config['forcebuy_enable'] = True + freqtrade.config['forcebuy_enable'] = True fbuy_mock = MagicMock(return_value=None) mocker.patch("freqtrade.rpc.RPC._rpc_forcebuy", fbuy_mock) @@ -990,7 +990,7 @@ def test_api_forcebuy(botclient, mocker, fee): def test_api_forcesell(botclient, mocker, ticker, fee, markets): - ftbot, client = botclient + freqtrade, client = botclient mocker.patch.multiple( 'freqtrade.exchange.Exchange', get_balances=MagicMock(return_value=ticker), @@ -999,14 +999,14 @@ def test_api_forcesell(botclient, mocker, ticker, fee, markets): markets=PropertyMock(return_value=markets), _is_dry_limit_order_filled=MagicMock(return_value=False), ) - patch_get_signal(ftbot, (True, False)) + patch_get_signal(freqtrade, (True, False, '')) rc = client_post(client, f"{BASE_URI}/forcesell", data='{"tradeid": "1"}') assert_response(rc, 502) assert rc.json() == {"error": "Error querying /api/v1/forcesell: invalid argument"} - ftbot.enter_positions() + freqtrade.enter_positions() rc = client_post(client, f"{BASE_URI}/forcesell", data='{"tradeid": "1"}') @@ -1015,7 +1015,7 @@ def test_api_forcesell(botclient, mocker, ticker, fee, markets): def test_api_pair_candles(botclient, ohlcv_history): - ftbot, client = botclient + freqtrade, client = botclient timeframe = '5m' amount = 3 @@ -1043,7 +1043,7 @@ def test_api_pair_candles(botclient, ohlcv_history): ohlcv_history.loc[1, 'buy'] = 1 ohlcv_history['sell'] = 0 - ftbot.dataprovider._set_cached_df("XRP/BTC", timeframe, ohlcv_history) + freqtrade.dataprovider._set_cached_df("XRP/BTC", timeframe, ohlcv_history) rc = client_get(client, f"{BASE_URI}/pair_candles?limit={amount}&pair=XRP%2FBTC&timeframe={timeframe}") @@ -1081,7 +1081,7 @@ def test_api_pair_candles(botclient, ohlcv_history): def test_api_pair_history(botclient, ohlcv_history): - ftbot, client = botclient + freqtrade, client = botclient timeframe = '5m' # No pair @@ -1134,21 +1134,21 @@ def test_api_pair_history(botclient, ohlcv_history): def test_api_plot_config(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/plot_config") assert_response(rc) assert rc.json() == {} - ftbot.strategy.plot_config = {'main_plot': {'sma': {}}, + freqtrade.strategy.plot_config = {'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}} rc = client_get(client, f"{BASE_URI}/plot_config") assert_response(rc) - assert rc.json() == ftbot.strategy.plot_config + assert rc.json() == freqtrade.strategy.plot_config assert isinstance(rc.json()['main_plot'], dict) assert isinstance(rc.json()['subplots'], dict) - ftbot.strategy.plot_config = {'main_plot': {'sma': {}}} + freqtrade.strategy.plot_config = {'main_plot': {'sma': {}}} rc = client_get(client, f"{BASE_URI}/plot_config") assert_response(rc) @@ -1157,7 +1157,7 @@ def test_api_plot_config(botclient): def test_api_strategies(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/strategies") @@ -1170,7 +1170,7 @@ def test_api_strategies(botclient): def test_api_strategy(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/strategy/DefaultStrategy") @@ -1185,7 +1185,7 @@ def test_api_strategy(botclient): def test_list_available_pairs(botclient): - ftbot, client = botclient + freqtrade, client = botclient rc = client_get(client, f"{BASE_URI}/available_pairs") diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 782ae69c6..642b55975 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -55,7 +55,7 @@ class DummyCls(Telegram): raise Exception('test') -def get_telegram_testobject(mocker, default_conf, mock=True, ftbot=None): +def get_telegram_testobject(mocker, default_conf, mock=True, freqtrade=None): msg_mock = MagicMock() if mock: mocker.patch.multiple( @@ -63,12 +63,12 @@ def get_telegram_testobject(mocker, default_conf, mock=True, ftbot=None): _init=MagicMock(), _send_msg=msg_mock ) - if not ftbot: - ftbot = get_patched_freqtradebot(mocker, default_conf) - rpc = RPC(ftbot) + if not freqtrade: + freqtrade = get_patched_freqtradebot(mocker, default_conf) + rpc = RPC(freqtrade) telegram = Telegram(rpc, default_conf) - return telegram, ftbot, msg_mock + return telegram, freqtrade, msg_mock def test_telegram__init__(default_conf, mocker) -> None: @@ -115,11 +115,11 @@ def test_authorized_only(default_conf, mocker, caplog, update) -> None: patch_exchange(mocker) caplog.set_level(logging.DEBUG) default_conf['telegram']['enabled'] = False - bot = FreqtradeBot(default_conf) - rpc = RPC(bot) + freqtrade = FreqtradeBot(default_conf) + rpc = RPC(freqtrade) dummy = DummyCls(rpc, default_conf) - patch_get_signal(bot, (True, False)) + patch_get_signal(freqtrade, (True, False, '')) dummy.dummy_handler(update=update, context=MagicMock()) assert dummy.state['called'] is True assert log_has('Executing handler: dummy_handler for chat_id: 0', caplog) @@ -135,11 +135,11 @@ def test_authorized_only_unauthorized(default_conf, mocker, caplog) -> None: update.message = Message(randint(1, 100), datetime.utcnow(), chat) default_conf['telegram']['enabled'] = False - bot = FreqtradeBot(default_conf) - rpc = RPC(bot) + freqtrade = FreqtradeBot(default_conf) + rpc = RPC(freqtrade) dummy = DummyCls(rpc, default_conf) - patch_get_signal(bot, (True, False)) + patch_get_signal(freqtrade, (True, False, '')) dummy.dummy_handler(update=update, context=MagicMock()) assert dummy.state['called'] is False assert not log_has('Executing handler: dummy_handler for chat_id: 3735928559', caplog) @@ -152,10 +152,10 @@ def test_authorized_only_exception(default_conf, mocker, caplog, update) -> None default_conf['telegram']['enabled'] = False - bot = FreqtradeBot(default_conf) - rpc = RPC(bot) + freqtrade = FreqtradeBot(default_conf) + rpc = RPC(freqtrade) dummy = DummyCls(rpc, default_conf) - patch_get_signal(bot, (True, False)) + patch_get_signal(freqtrade, (True, False, '')) dummy.dummy_exception(update=update, context=MagicMock()) assert dummy.state['called'] is False @@ -228,7 +228,7 @@ def test_status_handle(default_conf, update, ticker, fee, mocker) -> None: telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) freqtradebot.state = State.STOPPED # Status is also enabled when stopped @@ -285,7 +285,7 @@ def test_status_table_handle(default_conf, update, ticker, fee, mocker) -> None: telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) freqtradebot.state = State.STOPPED # Status table is also enabled when stopped @@ -329,7 +329,7 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, fee, telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Create some test data freqtradebot.enter_positions() @@ -400,7 +400,7 @@ def test_daily_wrong_input(default_conf, update, ticker, mocker) -> None: ) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Try invalid data msg_mock.reset_mock() @@ -432,7 +432,7 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee, ) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) telegram._profit(update=update, context=MagicMock()) assert msg_mock.call_count == 1 @@ -486,7 +486,7 @@ def test_telegram_stats(default_conf, update, ticker, ticker_sell_up, fee, get_fee=fee, ) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) telegram._stats(update=update, context=MagicMock()) assert msg_mock.call_count == 1 @@ -512,7 +512,7 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick side_effect=lambda a, b: f"{a}/{b}") telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) telegram._balance(update=update, context=MagicMock()) result = msg_mock.call_args_list[0][0][0] @@ -532,7 +532,7 @@ def test_balance_handle_empty_response(default_conf, update, mocker) -> None: mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={}) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) freqtradebot.config['dry_run'] = False telegram._balance(update=update, context=MagicMock()) @@ -545,7 +545,7 @@ def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={}) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) telegram._balance(update=update, context=MagicMock()) result = msg_mock.call_args_list[0][0][0] @@ -574,7 +574,7 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None }) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) telegram._balance(update=update, context=MagicMock()) assert msg_mock.call_count > 1 @@ -673,7 +673,7 @@ def test_telegram_forcesell_handle(default_conf, update, ticker, fee, freqtradebot = FreqtradeBot(default_conf) rpc = RPC(freqtradebot) telegram = Telegram(rpc, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Create some test data freqtradebot.enter_positions() @@ -732,7 +732,7 @@ def test_telegram_forcesell_down_handle(default_conf, update, ticker, fee, freqtradebot = FreqtradeBot(default_conf) rpc = RPC(freqtradebot) telegram = Telegram(rpc, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Create some test data freqtradebot.enter_positions() @@ -793,7 +793,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None freqtradebot = FreqtradeBot(default_conf) rpc = RPC(freqtradebot) telegram = Telegram(rpc, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Create some test data freqtradebot.enter_positions() @@ -834,7 +834,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None: return_value=15000.0) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Trader is not running freqtradebot.state = State.STOPPED @@ -872,7 +872,7 @@ def test_forcebuy_handle(default_conf, update, mocker) -> None: mocker.patch('freqtrade.rpc.RPC._rpc_forcebuy', fbuy_mock) telegram, freqtradebot, _ = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # /forcebuy ETH/BTC context = MagicMock() @@ -901,7 +901,7 @@ def test_forcebuy_handle_exception(default_conf, update, mocker) -> None: mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) update.message.text = '/forcebuy ETH/Nonepair' telegram._forcebuy(update=update, context=MagicMock()) @@ -918,7 +918,7 @@ def test_forcebuy_no_pair(default_conf, update, mocker) -> None: telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) context = MagicMock() context.args = [] @@ -946,7 +946,7 @@ def test_performance_handle(default_conf, update, ticker, fee, get_fee=fee, ) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) # Create some test data freqtradebot.enter_positions() @@ -974,7 +974,7 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None: get_fee=fee, ) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) freqtradebot.state = State.STOPPED telegram._count(update=update, context=MagicMock()) @@ -1003,7 +1003,7 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None get_fee=fee, ) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) - patch_get_signal(freqtradebot, (True, False)) + patch_get_signal(freqtradebot, (True, False, '')) telegram._locks(update=update, context=MagicMock()) assert msg_mock.call_count == 1 assert 'No active locks.' in msg_mock.call_args_list[0][0][0] diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index cc89ce00c..583ec7ddd 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -1972,16 +1972,16 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_buy_order_open def test_bot_loop_start_called_once(mocker, default_conf, caplog): - ftbot = get_patched_freqtradebot(mocker, default_conf) + freqtrade = get_patched_freqtradebot(mocker, default_conf) mocker.patch('freqtrade.freqtradebot.FreqtradeBot.create_trade') - patch_get_signal(ftbot) - ftbot.strategy.bot_loop_start = MagicMock(side_effect=ValueError) - ftbot.strategy.analyze = MagicMock() + patch_get_signal(freqtrade) + freqtrade.strategy.bot_loop_start = MagicMock(side_effect=ValueError) + freqtrade.strategy.analyze = MagicMock() - ftbot.process() + freqtrade.process() assert log_has_re(r'Strategy caused the following exception.*', caplog) - assert ftbot.strategy.bot_loop_start.call_count == 1 - assert ftbot.strategy.analyze.call_count == 1 + assert freqtrade.strategy.bot_loop_start.call_count == 1 + assert freqtrade.strategy.analyze.call_count == 1 def test_check_handle_timedout_buy_usercustom(default_conf, ticker, limit_buy_order_old, open_trade, @@ -4044,14 +4044,14 @@ def test_startup_trade_reinit(default_conf, edge_conf, mocker): reinit_mock = MagicMock() mocker.patch('freqtrade.persistence.Trade.stoploss_reinitialization', reinit_mock) - ftbot = get_patched_freqtradebot(mocker, default_conf) - ftbot.startup() + freqtrade = get_patched_freqtradebot(mocker, default_conf) + freqtrade.startup() assert reinit_mock.call_count == 1 reinit_mock.reset_mock() - ftbot = get_patched_freqtradebot(mocker, edge_conf) - ftbot.startup() + freqtrade = get_patched_freqtradebot(mocker, edge_conf) + freqtrade.startup() assert reinit_mock.call_count == 0 @@ -4070,17 +4070,17 @@ def test_sync_wallet_dry_run(mocker, default_conf, ticker, fee, limit_buy_order_ get_fee=fee, ) - bot = get_patched_freqtradebot(mocker, default_conf) - patch_get_signal(bot) - assert bot.wallets.get_free('BTC') == 0.002 + freqtrade = get_patched_freqtradebot(mocker, default_conf) + patch_get_signal(freqtrade) + assert freqtrade.wallets.get_free('BTC') == 0.002 - n = bot.enter_positions() + n = freqtrade.enter_positions() assert n == 2 trades = Trade.query.all() assert len(trades) == 2 - bot.config['max_open_trades'] = 3 - n = bot.enter_positions() + freqtrade.config['max_open_trades'] = 3 + n = freqtrade.enter_positions() assert n == 0 assert log_has_re(r"Unable to create trade for XRP/BTC: " r"Available balance \(0.0 BTC\) is lower than stake amount \(0.001 BTC\)",