|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import re
|
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
from unittest.mock import ANY, MagicMock
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from requests.exceptions import ConnectionError
|
|
|
|
|
@ -52,70 +52,89 @@ def test_FtRestClient_call_invalid(caplog):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"method,args",
|
|
|
|
|
"method,args,kwargs",
|
|
|
|
|
[
|
|
|
|
|
("start", []),
|
|
|
|
|
("stop", []),
|
|
|
|
|
("stopbuy", []),
|
|
|
|
|
("reload_config", []),
|
|
|
|
|
("balance", []),
|
|
|
|
|
("count", []),
|
|
|
|
|
("entries", []),
|
|
|
|
|
("exits", []),
|
|
|
|
|
("mix_tags", []),
|
|
|
|
|
("locks", []),
|
|
|
|
|
("lock_add", ["XRP/USDT", "2024-01-01 20:00:00Z", "*", "rand"]),
|
|
|
|
|
("delete_lock", [2]),
|
|
|
|
|
("daily", []),
|
|
|
|
|
("daily", [15]),
|
|
|
|
|
("weekly", []),
|
|
|
|
|
("weekly", [15]),
|
|
|
|
|
("monthly", []),
|
|
|
|
|
("monthly", [12]),
|
|
|
|
|
("edge", []),
|
|
|
|
|
("profit", []),
|
|
|
|
|
("stats", []),
|
|
|
|
|
("performance", []),
|
|
|
|
|
("status", []),
|
|
|
|
|
("version", []),
|
|
|
|
|
("show_config", []),
|
|
|
|
|
("ping", []),
|
|
|
|
|
("logs", []),
|
|
|
|
|
("logs", [55]),
|
|
|
|
|
("trades", []),
|
|
|
|
|
("trades", [5]),
|
|
|
|
|
("trades", [5, 5]), # With offset
|
|
|
|
|
("trade", [1]),
|
|
|
|
|
("delete_trade", [1]),
|
|
|
|
|
("cancel_open_order", [1]),
|
|
|
|
|
("whitelist", []),
|
|
|
|
|
("blacklist", []),
|
|
|
|
|
("blacklist", ["XRP/USDT"]),
|
|
|
|
|
("blacklist", ["XRP/USDT", "BTC/USDT"]),
|
|
|
|
|
("forcebuy", ["XRP/USDT"]),
|
|
|
|
|
("forcebuy", ["XRP/USDT", 1.5]),
|
|
|
|
|
("forceenter", ["XRP/USDT", "short"]),
|
|
|
|
|
("forceenter", ["XRP/USDT", "short", 1.5]),
|
|
|
|
|
("forceexit", [1]),
|
|
|
|
|
("forceexit", [1, "limit"]),
|
|
|
|
|
("forceexit", [1, "limit", 100]),
|
|
|
|
|
("strategies", []),
|
|
|
|
|
("strategy", ["sampleStrategy"]),
|
|
|
|
|
("pairlists_available", []),
|
|
|
|
|
("plot_config", []),
|
|
|
|
|
("available_pairs", []),
|
|
|
|
|
("available_pairs", ["5m"]),
|
|
|
|
|
("pair_candles", ["XRP/USDT", "5m"]),
|
|
|
|
|
("pair_candles", ["XRP/USDT", "5m", 500]),
|
|
|
|
|
("pair_history", ["XRP/USDT", "5m", "SampleStrategy"]),
|
|
|
|
|
("sysinfo", []),
|
|
|
|
|
("health", []),
|
|
|
|
|
("start", [], {}),
|
|
|
|
|
("stop", [], {}),
|
|
|
|
|
("stopbuy", [], {}),
|
|
|
|
|
("reload_config", [], {}),
|
|
|
|
|
("balance", [], {}),
|
|
|
|
|
("count", [], {}),
|
|
|
|
|
("entries", [], {}),
|
|
|
|
|
("exits", [], {}),
|
|
|
|
|
("mix_tags", [], {}),
|
|
|
|
|
("locks", [], {}),
|
|
|
|
|
("lock_add", ["XRP/USDT", "2024-01-01 20:00:00Z", "*", "rand"], {}),
|
|
|
|
|
("delete_lock", [2], {}),
|
|
|
|
|
("daily", [], {}),
|
|
|
|
|
("daily", [15], {}),
|
|
|
|
|
("weekly", [], {}),
|
|
|
|
|
("weekly", [15], {}),
|
|
|
|
|
("monthly", [], {}),
|
|
|
|
|
("monthly", [12], {}),
|
|
|
|
|
("edge", [], {}),
|
|
|
|
|
("profit", [], {}),
|
|
|
|
|
("stats", [], {}),
|
|
|
|
|
("performance", [], {}),
|
|
|
|
|
("status", [], {}),
|
|
|
|
|
("version", [], {}),
|
|
|
|
|
("show_config", [], {}),
|
|
|
|
|
("ping", [], {}),
|
|
|
|
|
("logs", [], {}),
|
|
|
|
|
("logs", [55], {}),
|
|
|
|
|
("trades", [], {}),
|
|
|
|
|
("trades", [5], {}),
|
|
|
|
|
("trades", [5, 5], {}), # With offset
|
|
|
|
|
("trade", [1], {}),
|
|
|
|
|
("delete_trade", [1], {}),
|
|
|
|
|
("cancel_open_order", [1], {}),
|
|
|
|
|
("whitelist", [], {}),
|
|
|
|
|
("blacklist", [], {}),
|
|
|
|
|
("blacklist", ["XRP/USDT"], {}),
|
|
|
|
|
("blacklist", ["XRP/USDT", "BTC/USDT"], {}),
|
|
|
|
|
("forcebuy", ["XRP/USDT"], {}),
|
|
|
|
|
("forcebuy", ["XRP/USDT", 1.5], {}),
|
|
|
|
|
("forceenter", ["XRP/USDT", "short"], {}),
|
|
|
|
|
("forceenter", ["XRP/USDT", "short", 1.5], {}),
|
|
|
|
|
("forceenter", ["XRP/USDT", "short", 1.5], {"order_type": "market"}),
|
|
|
|
|
("forceenter", ["XRP/USDT", "short", 1.5], {"order_type": "market", "stake_amount": 100}),
|
|
|
|
|
(
|
|
|
|
|
"forceenter",
|
|
|
|
|
["XRP/USDT", "short", 1.5],
|
|
|
|
|
{"order_type": "market", "stake_amount": 100, "leverage": 10.0},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
"forceenter",
|
|
|
|
|
["XRP/USDT", "short", 1.5],
|
|
|
|
|
{
|
|
|
|
|
"order_type": "market",
|
|
|
|
|
"stake_amount": 100,
|
|
|
|
|
"leverage": 10.0,
|
|
|
|
|
"enter_tag": "test_force_enter",
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
("forceexit", [1], {}),
|
|
|
|
|
("forceexit", [1, "limit"], {}),
|
|
|
|
|
("forceexit", [1, "limit", 100], {}),
|
|
|
|
|
("strategies", [], {}),
|
|
|
|
|
("strategy", ["sampleStrategy"], {}),
|
|
|
|
|
("pairlists_available", [], {}),
|
|
|
|
|
("plot_config", [], {}),
|
|
|
|
|
("available_pairs", [], {}),
|
|
|
|
|
("available_pairs", ["5m"], {}),
|
|
|
|
|
("pair_candles", ["XRP/USDT", "5m"], {}),
|
|
|
|
|
("pair_candles", ["XRP/USDT", "5m", 500], {}),
|
|
|
|
|
("pair_candles", ["XRP/USDT", "5m", 500], {"columns": ["close_time,close"]}),
|
|
|
|
|
("pair_history", ["XRP/USDT", "5m", "SampleStrategy"], {}),
|
|
|
|
|
("pair_history", ["XRP/USDT", "5m"], {"strategy": "SampleStrategy"}),
|
|
|
|
|
("sysinfo", [], {}),
|
|
|
|
|
("health", [], {}),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_FtRestClient_call_explicit_methods(method, args):
|
|
|
|
|
def test_FtRestClient_call_explicit_methods(method, args, kwargs):
|
|
|
|
|
client, mock = get_rest_client()
|
|
|
|
|
exec = getattr(client, method)
|
|
|
|
|
exec(*args)
|
|
|
|
|
exec(*args, **kwargs)
|
|
|
|
|
assert mock.call_count == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -148,3 +167,40 @@ def test_ft_client(mocker, capsys, caplog):
|
|
|
|
|
)
|
|
|
|
|
main_exec(args)
|
|
|
|
|
assert log_has_re("Command whatever not defined", caplog)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"params, expected_args, expected_kwargs",
|
|
|
|
|
[
|
|
|
|
|
("forceenter BTC/USDT long", ["BTC/USDT", "long"], {}),
|
|
|
|
|
("forceenter BTC/USDT long limit", ["BTC/USDT", "long", "limit"], {}),
|
|
|
|
|
(
|
|
|
|
|
# Skip most parameters, only providing enter_tag
|
|
|
|
|
"forceenter BTC/USDT long enter_tag=deadBeef",
|
|
|
|
|
["BTC/USDT", "long"],
|
|
|
|
|
{"enter_tag": "deadBeef"},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
"forceenter BTC/USDT long invalid_key=123",
|
|
|
|
|
[],
|
|
|
|
|
SystemExit,
|
|
|
|
|
# {"invalid_key": "deadBeef"},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_ft_client_argparsing(mocker, params, expected_args, expected_kwargs, caplog):
|
|
|
|
|
mocked_method = params.split(" ")[0]
|
|
|
|
|
mocker.patch("freqtrade_client.ft_client.load_config", return_value={}, autospec=True)
|
|
|
|
|
mm = mocker.patch(
|
|
|
|
|
f"freqtrade_client.ft_client.FtRestClient.{mocked_method}", return_value={}, autospec=True
|
|
|
|
|
)
|
|
|
|
|
args = add_arguments(params.split(" "))
|
|
|
|
|
if isinstance(expected_kwargs, dict):
|
|
|
|
|
main_exec(args)
|
|
|
|
|
mm.assert_called_once_with(ANY, *expected_args, **expected_kwargs)
|
|
|
|
|
else:
|
|
|
|
|
with pytest.raises(expected_kwargs):
|
|
|
|
|
main_exec(args)
|
|
|
|
|
|
|
|
|
|
assert log_has_re(f"Error executing command {mocked_method}: got an unexpected .*", caplog)
|
|
|
|
|
mm.assert_not_called()
|
|
|
|
|
|