2019-06-16 08:13:24 +00:00
|
|
|
import re
|
2019-09-21 10:53:15 +00:00
|
|
|
from pathlib import Path
|
2019-08-16 13:28:11 +00:00
|
|
|
from unittest.mock import MagicMock, PropertyMock
|
2019-07-21 12:32:00 +00:00
|
|
|
|
2020-09-19 07:10:34 +00:00
|
|
|
import arrow
|
2019-07-21 12:32:00 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-09-28 17:43:15 +00:00
|
|
|
from freqtrade.commands import (start_convert_data, start_create_userdir, start_download_data,
|
|
|
|
start_hyperopt_list, start_hyperopt_show, start_list_data,
|
|
|
|
start_list_exchanges, start_list_hyperopts, start_list_markets,
|
|
|
|
start_list_strategies, start_list_timeframes, start_new_hyperopt,
|
|
|
|
start_new_strategy, start_show_trades, start_test_pairlist,
|
|
|
|
start_trading)
|
2020-01-26 12:55:48 +00:00
|
|
|
from freqtrade.configuration import setup_utils_configuration
|
2019-12-30 14:02:17 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2019-07-21 12:32:00 +00:00
|
|
|
from freqtrade.state import RunMode
|
2020-09-28 17:43:15 +00:00
|
|
|
from tests.conftest import (create_mock_trades, get_args, log_has, log_has_re, patch_exchange,
|
2019-12-03 14:10:27 +00:00
|
|
|
patched_configuration_load_config_file)
|
2020-09-10 05:40:19 +00:00
|
|
|
from tests.conftest_trades import MOCK_TRADE_COUNT
|
2019-06-16 08:13:24 +00:00
|
|
|
|
|
|
|
|
2019-06-16 18:37:59 +00:00
|
|
|
def test_setup_utils_configuration():
|
2019-06-16 08:13:24 +00:00
|
|
|
args = [
|
2021-01-22 18:18:21 +00:00
|
|
|
'list-exchanges', '--config', 'config_bittrex.json.example',
|
2019-06-16 08:13:24 +00:00
|
|
|
]
|
|
|
|
|
2019-06-16 18:37:59 +00:00
|
|
|
config = setup_utils_configuration(get_args(args), RunMode.OTHER)
|
2019-06-16 08:13:24 +00:00
|
|
|
assert "exchange" in config
|
2019-11-05 11:39:19 +00:00
|
|
|
assert config['dry_run'] is True
|
2019-06-16 08:13:24 +00:00
|
|
|
assert config['exchange']['key'] == ''
|
|
|
|
assert config['exchange']['secret'] == ''
|
|
|
|
|
|
|
|
|
2020-05-08 09:44:24 +00:00
|
|
|
def test_start_trading_fail(mocker, caplog):
|
2019-11-16 08:56:16 +00:00
|
|
|
|
|
|
|
mocker.patch("freqtrade.worker.Worker.run", MagicMock(side_effect=OperationalException))
|
|
|
|
|
|
|
|
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(return_value=None))
|
|
|
|
|
|
|
|
exitmock = mocker.patch("freqtrade.worker.Worker.exit", MagicMock())
|
|
|
|
args = [
|
|
|
|
'trade',
|
2021-01-22 18:18:21 +00:00
|
|
|
'-c', 'config_bittrex.json.example'
|
2019-11-16 08:56:16 +00:00
|
|
|
]
|
2020-05-08 09:44:24 +00:00
|
|
|
start_trading(get_args(args))
|
2019-11-16 08:56:16 +00:00
|
|
|
assert exitmock.call_count == 1
|
|
|
|
|
|
|
|
exitmock.reset_mock()
|
2020-05-08 09:44:24 +00:00
|
|
|
caplog.clear()
|
2019-11-16 08:56:16 +00:00
|
|
|
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(side_effect=OperationalException))
|
2020-05-08 09:44:24 +00:00
|
|
|
start_trading(get_args(args))
|
2019-11-16 08:56:16 +00:00
|
|
|
assert exitmock.call_count == 0
|
2020-05-08 09:44:24 +00:00
|
|
|
assert log_has('Fatal exception!', caplog)
|
2019-11-16 08:56:16 +00:00
|
|
|
|
|
|
|
|
2019-06-16 08:13:24 +00:00
|
|
|
def test_list_exchanges(capsys):
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"list-exchanges",
|
|
|
|
]
|
|
|
|
|
|
|
|
start_list_exchanges(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
2019-09-30 21:33:54 +00:00
|
|
|
assert re.match(r"Exchanges available for Freqtrade.*", captured.out)
|
2019-06-16 08:13:24 +00:00
|
|
|
assert re.match(r".*binance,.*", captured.out)
|
|
|
|
assert re.match(r".*bittrex,.*", captured.out)
|
|
|
|
|
|
|
|
# Test with --one-column
|
|
|
|
args = [
|
|
|
|
"list-exchanges",
|
|
|
|
"--one-column",
|
|
|
|
]
|
|
|
|
|
|
|
|
start_list_exchanges(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.search(r"^binance$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^bittrex$", captured.out, re.MULTILINE)
|
2019-07-21 12:32:00 +00:00
|
|
|
|
2019-09-30 21:33:54 +00:00
|
|
|
# Test with --all
|
|
|
|
args = [
|
|
|
|
"list-exchanges",
|
|
|
|
"--all",
|
|
|
|
]
|
|
|
|
|
|
|
|
start_list_exchanges(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.match(r"All exchanges supported by the ccxt library.*", captured.out)
|
|
|
|
assert re.match(r".*binance,.*", captured.out)
|
|
|
|
assert re.match(r".*bittrex,.*", captured.out)
|
|
|
|
assert re.match(r".*bitmex,.*", captured.out)
|
|
|
|
|
|
|
|
# Test with --one-column --all
|
|
|
|
args = [
|
|
|
|
"list-exchanges",
|
|
|
|
"--one-column",
|
|
|
|
"--all",
|
|
|
|
]
|
|
|
|
|
|
|
|
start_list_exchanges(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.search(r"^binance$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^bittrex$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^bitmex$", captured.out, re.MULTILINE)
|
|
|
|
|
2019-07-21 12:32:00 +00:00
|
|
|
|
2019-10-06 08:32:19 +00:00
|
|
|
def test_list_timeframes(mocker, capsys):
|
|
|
|
|
|
|
|
api_mock = MagicMock()
|
2019-10-06 12:33:23 +00:00
|
|
|
api_mock.timeframes = {'1m': 'oneMin',
|
|
|
|
'5m': 'fiveMin',
|
|
|
|
'30m': 'thirtyMin',
|
|
|
|
'1h': 'hour',
|
|
|
|
'1d': 'day',
|
2019-10-06 08:32:19 +00:00
|
|
|
}
|
|
|
|
patch_exchange(mocker, api_mock=api_mock)
|
2019-10-03 23:01:44 +00:00
|
|
|
args = [
|
|
|
|
"list-timeframes",
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"This command requires a configured exchange.*"):
|
|
|
|
start_list_timeframes(pargs)
|
|
|
|
|
2021-01-22 18:18:21 +00:00
|
|
|
# Test with --config config_bittrex.json.example
|
2019-10-03 23:01:44 +00:00
|
|
|
args = [
|
|
|
|
"list-timeframes",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-03 23:01:44 +00:00
|
|
|
]
|
|
|
|
start_list_timeframes(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
2019-10-23 05:06:02 +00:00
|
|
|
assert re.match("Timeframes available for the exchange `Bittrex`: "
|
2019-10-03 23:01:44 +00:00
|
|
|
"1m, 5m, 30m, 1h, 1d",
|
|
|
|
captured.out)
|
|
|
|
|
|
|
|
# Test with --exchange bittrex
|
|
|
|
args = [
|
|
|
|
"list-timeframes",
|
|
|
|
"--exchange", "bittrex",
|
|
|
|
]
|
|
|
|
start_list_timeframes(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
2019-10-23 05:06:02 +00:00
|
|
|
assert re.match("Timeframes available for the exchange `Bittrex`: "
|
2019-10-03 23:01:44 +00:00
|
|
|
"1m, 5m, 30m, 1h, 1d",
|
|
|
|
captured.out)
|
|
|
|
|
2019-10-06 08:32:19 +00:00
|
|
|
api_mock.timeframes = {'1m': '1m',
|
|
|
|
'5m': '5m',
|
|
|
|
'15m': '15m',
|
|
|
|
'30m': '30m',
|
|
|
|
'1h': '1h',
|
|
|
|
'6h': '6h',
|
|
|
|
'12h': '12h',
|
|
|
|
'1d': '1d',
|
|
|
|
'3d': '3d',
|
|
|
|
}
|
2019-10-23 05:06:02 +00:00
|
|
|
patch_exchange(mocker, api_mock=api_mock, id='binance')
|
2019-10-03 23:01:44 +00:00
|
|
|
# Test with --exchange binance
|
|
|
|
args = [
|
|
|
|
"list-timeframes",
|
|
|
|
"--exchange", "binance",
|
|
|
|
]
|
|
|
|
start_list_timeframes(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
2019-10-23 05:06:02 +00:00
|
|
|
assert re.match("Timeframes available for the exchange `Binance`: "
|
2019-10-06 08:32:19 +00:00
|
|
|
"1m, 5m, 15m, 30m, 1h, 6h, 12h, 1d, 3d",
|
2019-10-03 23:01:44 +00:00
|
|
|
captured.out)
|
|
|
|
|
|
|
|
# Test with --one-column
|
|
|
|
args = [
|
|
|
|
"list-timeframes",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-03 23:01:44 +00:00
|
|
|
"--one-column",
|
|
|
|
]
|
|
|
|
start_list_timeframes(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.search(r"^1m$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^5m$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^1h$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^1d$", captured.out, re.MULTILINE)
|
|
|
|
|
|
|
|
# Test with --exchange binance --one-column
|
|
|
|
args = [
|
|
|
|
"list-timeframes",
|
|
|
|
"--exchange", "binance",
|
|
|
|
"--one-column",
|
|
|
|
]
|
|
|
|
start_list_timeframes(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.search(r"^1m$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^5m$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^1h$", captured.out, re.MULTILINE)
|
|
|
|
assert re.search(r"^1d$", captured.out, re.MULTILINE)
|
|
|
|
|
|
|
|
|
2019-10-17 21:48:40 +00:00
|
|
|
def test_list_markets(mocker, markets, capsys):
|
|
|
|
|
|
|
|
api_mock = MagicMock()
|
|
|
|
api_mock.markets = markets
|
|
|
|
patch_exchange(mocker, api_mock=api_mock)
|
|
|
|
|
|
|
|
# Test with no --config
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
|
|
|
]
|
2019-10-20 19:43:00 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
2019-10-17 21:48:40 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"This command requires a configured exchange.*"):
|
2019-10-20 19:43:00 +00:00
|
|
|
start_list_markets(pargs, False)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
2021-01-22 18:18:21 +00:00
|
|
|
# Test with --config config_bittrex.json.example
|
2019-10-17 21:48:40 +00:00
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 10 active markets: "
|
|
|
|
"BLK/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, NEO/BTC, "
|
|
|
|
"TKN/BTC, XLTCUSDT, XRP/BTC.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
2019-10-21 05:07:25 +00:00
|
|
|
patch_exchange(mocker, api_mock=api_mock, id="binance")
|
2019-10-20 23:15:37 +00:00
|
|
|
# Test with --exchange
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
|
|
|
"--exchange", "binance"
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_list_markets(pargs, False)
|
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert re.match("\nExchange Binance has 10 active markets:\n",
|
2019-10-20 23:15:37 +00:00
|
|
|
captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
2019-10-21 05:07:25 +00:00
|
|
|
patch_exchange(mocker, api_mock=api_mock, id="bittrex")
|
2019-10-17 21:48:40 +00:00
|
|
|
# Test with --all: all markets
|
|
|
|
args = [
|
2019-10-18 11:25:43 +00:00
|
|
|
"list-markets", "--all",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 12 markets: "
|
|
|
|
"BLK/BTC, BTT/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, LTC/USDT, NEO/BTC, "
|
2019-10-18 11:25:43 +00:00
|
|
|
"TKN/BTC, XLTCUSDT, XRP/BTC.\n"
|
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# Test list-pairs subcommand: active pairs
|
|
|
|
args = [
|
|
|
|
"list-pairs",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), True)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 9 active pairs: "
|
|
|
|
"BLK/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XRP/BTC.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# Test list-pairs subcommand with --all: all pairs
|
|
|
|
args = [
|
2019-10-18 11:25:43 +00:00
|
|
|
"list-pairs", "--all",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), True)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 11 pairs: "
|
|
|
|
"BLK/BTC, BTT/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, LTC/USDT, NEO/BTC, "
|
2019-10-18 11:25:43 +00:00
|
|
|
"TKN/BTC, XRP/BTC.\n"
|
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, base=ETH, LTC
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--base", "ETH", "LTC",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 6 active markets with ETH, LTC as base currencies: "
|
|
|
|
"ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, XLTCUSDT.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, base=LTC
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--base", "LTC",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 4 active markets with LTC as base currency: "
|
|
|
|
"LTC/BTC, LTC/ETH, LTC/USD, XLTCUSDT.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, quote=USDT, USD
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--quote", "USDT", "USD",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2019-10-26 11:24:26 +00:00
|
|
|
assert ("Exchange Bittrex has 3 active markets with USDT, USD as quote currencies: "
|
|
|
|
"ETH/USDT, LTC/USD, XLTCUSDT.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, quote=USDT
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--quote", "USDT",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2019-10-26 11:24:26 +00:00
|
|
|
assert ("Exchange Bittrex has 2 active markets with USDT as quote currency: "
|
|
|
|
"ETH/USDT, XLTCUSDT.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, base=LTC, quote=USDT
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--base", "LTC", "--quote", "USDT",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2019-10-26 11:24:26 +00:00
|
|
|
assert ("Exchange Bittrex has 1 active market with LTC as base currency and "
|
|
|
|
"with USDT as quote currency: XLTCUSDT.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active pairs, base=LTC, quote=USDT
|
|
|
|
args = [
|
|
|
|
"list-pairs",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-26 11:24:26 +00:00
|
|
|
"--base", "LTC", "--quote", "USD",
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), True)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2019-10-18 11:25:43 +00:00
|
|
|
assert ("Exchange Bittrex has 1 active pair with LTC as base currency and "
|
2019-10-26 11:24:26 +00:00
|
|
|
"with USD as quote currency: LTC/USD.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, base=LTC, quote=USDT, NONEXISTENT
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--base", "LTC", "--quote", "USDT", "NONEXISTENT",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2019-10-26 11:24:26 +00:00
|
|
|
assert ("Exchange Bittrex has 1 active market with LTC as base currency and "
|
|
|
|
"with USDT, NONEXISTENT as quote currencies: XLTCUSDT.\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
|
|
|
# active markets, base=LTC, quote=NONEXISTENT
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--base", "LTC", "--quote", "NONEXISTENT",
|
|
|
|
"--print-list",
|
2019-10-17 21:48:40 +00:00
|
|
|
]
|
2019-10-17 22:26:05 +00:00
|
|
|
start_list_markets(get_args(args), False)
|
2019-10-17 21:48:40 +00:00
|
|
|
captured = capsys.readouterr()
|
2019-10-18 11:25:43 +00:00
|
|
|
assert ("Exchange Bittrex has 0 active markets with LTC as base currency and "
|
|
|
|
"with NONEXISTENT as quote currency.\n"
|
|
|
|
in captured.out)
|
|
|
|
|
|
|
|
# Test tabular output
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
]
|
|
|
|
start_list_markets(get_args(args), False)
|
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ("Exchange Bittrex has 10 active markets:\n"
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
|
|
|
|
|
|
|
# Test tabular output, no markets found
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--base", "LTC", "--quote", "NONEXISTENT",
|
|
|
|
]
|
|
|
|
start_list_markets(get_args(args), False)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert ("Exchange Bittrex has 0 active markets with LTC as base currency and "
|
|
|
|
"with NONEXISTENT as quote currency.\n"
|
|
|
|
in captured.out)
|
|
|
|
|
|
|
|
# Test --print-json
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-json"
|
|
|
|
]
|
|
|
|
start_list_markets(get_args(args), False)
|
|
|
|
captured = capsys.readouterr()
|
2020-02-24 20:50:27 +00:00
|
|
|
assert ('["BLK/BTC","ETH/BTC","ETH/USDT","LTC/BTC","LTC/ETH","LTC/USD","NEO/BTC",'
|
2019-10-26 11:28:04 +00:00
|
|
|
'"TKN/BTC","XLTCUSDT","XRP/BTC"]'
|
2019-10-18 11:25:43 +00:00
|
|
|
in captured.out)
|
|
|
|
|
|
|
|
# Test --print-csv
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--print-csv"
|
|
|
|
]
|
|
|
|
start_list_markets(get_args(args), False)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert ("Id,Symbol,Base,Quote,Active,Is pair" in captured.out)
|
|
|
|
assert ("blkbtc,BLK/BTC,BLK,BTC,True,True" in captured.out)
|
2019-10-26 11:24:26 +00:00
|
|
|
assert ("USD-LTC,LTC/USD,LTC,USD,True,True" in captured.out)
|
2019-10-18 11:25:43 +00:00
|
|
|
|
|
|
|
# Test --one-column
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2019-10-18 11:25:43 +00:00
|
|
|
"--one-column"
|
|
|
|
]
|
|
|
|
start_list_markets(get_args(args), False)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.search(r"^BLK/BTC$", captured.out, re.MULTILINE)
|
2019-10-26 11:24:26 +00:00
|
|
|
assert re.search(r"^LTC/USD$", captured.out, re.MULTILINE)
|
2019-10-17 21:48:40 +00:00
|
|
|
|
2020-10-29 06:54:42 +00:00
|
|
|
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(side_effect=ValueError))
|
|
|
|
# Test --one-column
|
|
|
|
args = [
|
|
|
|
"list-markets",
|
2021-01-22 18:18:21 +00:00
|
|
|
'--config', 'config_bittrex.json.example',
|
2020-10-29 06:54:42 +00:00
|
|
|
"--one-column"
|
|
|
|
]
|
|
|
|
with pytest.raises(OperationalException, match=r"Cannot get markets.*"):
|
|
|
|
start_list_markets(get_args(args), False)
|
|
|
|
|
2019-10-17 21:48:40 +00:00
|
|
|
|
2019-07-21 12:32:00 +00:00
|
|
|
def test_create_datadir_failed(caplog):
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"create-userdir",
|
|
|
|
]
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
start_create_userdir(get_args(args))
|
2019-08-18 13:09:44 +00:00
|
|
|
assert log_has("`create-userdir` requires --userdir to be set.", caplog)
|
2019-07-21 12:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_datadir(caplog, mocker):
|
2020-02-29 14:44:45 +00:00
|
|
|
|
2020-01-26 12:09:13 +00:00
|
|
|
cud = mocker.patch("freqtrade.commands.deploy_commands.create_userdata_dir", MagicMock())
|
|
|
|
csf = mocker.patch("freqtrade.commands.deploy_commands.copy_sample_files", MagicMock())
|
2019-07-21 12:32:00 +00:00
|
|
|
args = [
|
|
|
|
"create-userdir",
|
|
|
|
"--userdir",
|
|
|
|
"/temp/freqtrade/test"
|
|
|
|
]
|
|
|
|
start_create_userdir(get_args(args))
|
|
|
|
|
|
|
|
assert cud.call_count == 1
|
2019-11-01 12:41:25 +00:00
|
|
|
assert csf.call_count == 1
|
2019-08-21 17:35:27 +00:00
|
|
|
|
|
|
|
|
2019-11-12 12:31:07 +00:00
|
|
|
def test_start_new_strategy(mocker, caplog):
|
|
|
|
wt_mock = mocker.patch.object(Path, "write_text", MagicMock())
|
2019-11-16 13:47:44 +00:00
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
|
|
|
|
2019-11-12 12:31:07 +00:00
|
|
|
args = [
|
|
|
|
"new-strategy",
|
|
|
|
"--strategy",
|
|
|
|
"CoolNewStrategy"
|
|
|
|
]
|
|
|
|
start_new_strategy(get_args(args))
|
|
|
|
|
|
|
|
assert wt_mock.call_count == 1
|
|
|
|
assert "CoolNewStrategy" in wt_mock.call_args_list[0][0][0]
|
|
|
|
assert log_has_re("Writing strategy to .*", caplog)
|
|
|
|
|
2020-10-29 06:44:03 +00:00
|
|
|
mocker.patch('freqtrade.commands.deploy_commands.setup_utils_configuration')
|
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r".* already exists. Please choose another Strategy Name\."):
|
|
|
|
start_new_strategy(get_args(args))
|
|
|
|
|
2019-11-12 12:31:07 +00:00
|
|
|
|
|
|
|
def test_start_new_strategy_DefaultStrat(mocker, caplog):
|
|
|
|
args = [
|
|
|
|
"new-strategy",
|
|
|
|
"--strategy",
|
|
|
|
"DefaultStrategy"
|
|
|
|
]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"DefaultStrategy is not allowed as name\."):
|
|
|
|
start_new_strategy(get_args(args))
|
|
|
|
|
|
|
|
|
2019-11-12 12:33:37 +00:00
|
|
|
def test_start_new_strategy_no_arg(mocker, caplog):
|
|
|
|
args = [
|
|
|
|
"new-strategy",
|
|
|
|
]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match="`new-strategy` requires --strategy to be set."):
|
|
|
|
start_new_strategy(get_args(args))
|
|
|
|
|
|
|
|
|
2019-11-16 14:52:32 +00:00
|
|
|
def test_start_new_hyperopt(mocker, caplog):
|
|
|
|
wt_mock = mocker.patch.object(Path, "write_text", MagicMock())
|
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"new-hyperopt",
|
|
|
|
"--hyperopt",
|
|
|
|
"CoolNewhyperopt"
|
|
|
|
]
|
|
|
|
start_new_hyperopt(get_args(args))
|
|
|
|
|
|
|
|
assert wt_mock.call_count == 1
|
|
|
|
assert "CoolNewhyperopt" in wt_mock.call_args_list[0][0][0]
|
|
|
|
assert log_has_re("Writing hyperopt to .*", caplog)
|
|
|
|
|
2020-10-29 06:44:03 +00:00
|
|
|
mocker.patch('freqtrade.commands.deploy_commands.setup_utils_configuration')
|
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r".* already exists. Please choose another Hyperopt Name\."):
|
|
|
|
start_new_hyperopt(get_args(args))
|
|
|
|
|
2019-11-16 14:52:32 +00:00
|
|
|
|
|
|
|
def test_start_new_hyperopt_DefaultHyperopt(mocker, caplog):
|
|
|
|
args = [
|
|
|
|
"new-hyperopt",
|
|
|
|
"--hyperopt",
|
|
|
|
"DefaultHyperopt"
|
|
|
|
]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"DefaultHyperopt is not allowed as name\."):
|
|
|
|
start_new_hyperopt(get_args(args))
|
|
|
|
|
|
|
|
|
|
|
|
def test_start_new_hyperopt_no_arg(mocker, caplog):
|
|
|
|
args = [
|
|
|
|
"new-hyperopt",
|
|
|
|
]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match="`new-hyperopt` requires --hyperopt to be set."):
|
|
|
|
start_new_hyperopt(get_args(args))
|
|
|
|
|
|
|
|
|
2019-08-25 13:02:40 +00:00
|
|
|
def test_download_data_keyboardInterrupt(mocker, caplog, markets):
|
2020-01-26 12:17:26 +00:00
|
|
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
2019-08-25 13:02:40 +00:00
|
|
|
MagicMock(side_effect=KeyboardInterrupt))
|
2019-08-17 04:58:38 +00:00
|
|
|
patch_exchange(mocker)
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
|
|
)
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange", "binance",
|
|
|
|
"--pairs", "ETH/BTC", "XRP/BTC",
|
|
|
|
]
|
2019-08-25 13:02:40 +00:00
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
start_download_data(get_args(args))
|
2019-08-17 04:58:38 +00:00
|
|
|
|
2019-08-25 13:02:40 +00:00
|
|
|
assert dl_mock.call_count == 1
|
2019-08-17 04:58:38 +00:00
|
|
|
|
|
|
|
|
2020-09-19 07:10:34 +00:00
|
|
|
def test_download_data_timerange(mocker, caplog, markets):
|
|
|
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
|
|
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
|
|
|
patch_exchange(mocker)
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
|
|
)
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange", "binance",
|
|
|
|
"--pairs", "ETH/BTC", "XRP/BTC",
|
|
|
|
"--days", "20",
|
|
|
|
"--timerange", "20200101-"
|
|
|
|
]
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"--days and --timerange are mutually.*"):
|
|
|
|
start_download_data(get_args(args))
|
|
|
|
assert dl_mock.call_count == 0
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange", "binance",
|
|
|
|
"--pairs", "ETH/BTC", "XRP/BTC",
|
|
|
|
"--days", "20",
|
|
|
|
]
|
|
|
|
start_download_data(get_args(args))
|
|
|
|
assert dl_mock.call_count == 1
|
|
|
|
# 20days ago
|
2020-10-12 17:58:04 +00:00
|
|
|
days_ago = arrow.get(arrow.utcnow().shift(days=-20).date()).int_timestamp
|
2020-09-19 07:10:34 +00:00
|
|
|
assert dl_mock.call_args_list[0][1]['timerange'].startts == days_ago
|
|
|
|
|
|
|
|
dl_mock.reset_mock()
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange", "binance",
|
|
|
|
"--pairs", "ETH/BTC", "XRP/BTC",
|
|
|
|
"--timerange", "20200101-"
|
|
|
|
]
|
|
|
|
start_download_data(get_args(args))
|
|
|
|
assert dl_mock.call_count == 1
|
|
|
|
|
2020-10-12 17:58:04 +00:00
|
|
|
assert dl_mock.call_args_list[0][1]['timerange'].startts == arrow.Arrow(
|
|
|
|
2020, 1, 1).int_timestamp
|
2020-09-19 07:10:34 +00:00
|
|
|
|
|
|
|
|
2019-08-16 13:28:11 +00:00
|
|
|
def test_download_data_no_markets(mocker, caplog):
|
2020-01-26 12:17:26 +00:00
|
|
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
2019-08-25 13:02:40 +00:00
|
|
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
2019-10-23 05:06:02 +00:00
|
|
|
patch_exchange(mocker, id='binance')
|
2019-08-16 13:28:11 +00:00
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
|
|
)
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange", "binance",
|
2019-08-17 04:58:38 +00:00
|
|
|
"--pairs", "ETH/BTC", "XRP/BTC",
|
2019-08-25 13:02:40 +00:00
|
|
|
"--days", "20"
|
2019-08-16 13:28:11 +00:00
|
|
|
]
|
|
|
|
start_download_data(get_args(args))
|
2019-08-25 13:02:40 +00:00
|
|
|
assert dl_mock.call_args[1]['timerange'].starttype == "date"
|
2019-10-23 05:06:02 +00:00
|
|
|
assert log_has("Pairs [ETH/BTC,XRP/BTC] not available on exchange Binance.", caplog)
|
2019-09-21 09:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_download_data_no_exchange(mocker, caplog):
|
2020-01-26 12:17:26 +00:00
|
|
|
mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
2019-09-21 09:24:51 +00:00
|
|
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
|
|
|
patch_exchange(mocker)
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
|
|
)
|
|
|
|
args = [
|
2019-09-21 10:53:15 +00:00
|
|
|
"download-data",
|
2019-12-03 14:10:27 +00:00
|
|
|
]
|
2019-09-24 09:07:12 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
2019-09-21 09:24:51 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"This command requires a configured exchange.*"):
|
2019-09-24 09:07:12 +00:00
|
|
|
start_download_data(pargs)
|
2019-09-21 10:53:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_download_data_no_pairs(mocker, caplog):
|
2019-09-24 09:07:12 +00:00
|
|
|
|
2019-09-21 10:53:15 +00:00
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
|
|
|
|
2020-01-26 12:17:26 +00:00
|
|
|
mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
2019-09-21 10:53:15 +00:00
|
|
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
|
|
|
patch_exchange(mocker)
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
|
|
)
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange",
|
|
|
|
"binance",
|
|
|
|
]
|
2019-09-24 09:07:12 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
2019-09-21 10:53:15 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"Downloading data requires a list of pairs\..*"):
|
2019-09-24 09:07:12 +00:00
|
|
|
start_download_data(pargs)
|
2019-10-08 18:31:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_download_data_trades(mocker, caplog):
|
2020-01-26 12:17:26 +00:00
|
|
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_trades_data',
|
2019-10-08 18:31:14 +00:00
|
|
|
MagicMock(return_value=[]))
|
2020-01-26 12:17:26 +00:00
|
|
|
convert_mock = mocker.patch('freqtrade.commands.data_commands.convert_trades_to_ohlcv',
|
2019-10-08 18:31:14 +00:00
|
|
|
MagicMock(return_value=[]))
|
|
|
|
patch_exchange(mocker)
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
|
|
)
|
|
|
|
args = [
|
|
|
|
"download-data",
|
|
|
|
"--exchange", "kraken",
|
|
|
|
"--pairs", "ETH/BTC", "XRP/BTC",
|
|
|
|
"--days", "20",
|
|
|
|
"--dl-trades"
|
|
|
|
]
|
|
|
|
start_download_data(get_args(args))
|
|
|
|
assert dl_mock.call_args[1]['timerange'].starttype == "date"
|
|
|
|
assert dl_mock.call_count == 1
|
|
|
|
assert convert_mock.call_count == 1
|
2019-12-03 14:10:27 +00:00
|
|
|
|
|
|
|
|
2019-12-24 14:35:38 +00:00
|
|
|
def test_start_list_strategies(mocker, caplog, capsys):
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"list-strategies",
|
|
|
|
"--strategy-path",
|
2020-02-18 19:12:10 +00:00
|
|
|
str(Path(__file__).parent.parent / "strategy" / "strats"),
|
2019-12-24 14:35:38 +00:00
|
|
|
"-1"
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
# pargs['config'] = None
|
|
|
|
start_list_strategies(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "TestStrategyLegacy" in captured.out
|
2019-12-28 05:39:25 +00:00
|
|
|
assert "legacy_strategy.py" not in captured.out
|
2019-12-24 14:35:38 +00:00
|
|
|
assert "DefaultStrategy" in captured.out
|
|
|
|
|
|
|
|
# Test regular output
|
|
|
|
args = [
|
|
|
|
"list-strategies",
|
|
|
|
"--strategy-path",
|
2020-02-18 19:12:10 +00:00
|
|
|
str(Path(__file__).parent.parent / "strategy" / "strats"),
|
2020-10-29 06:54:42 +00:00
|
|
|
'--no-color',
|
2019-12-24 14:35:38 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
# pargs['config'] = None
|
|
|
|
start_list_strategies(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "TestStrategyLegacy" in captured.out
|
2019-12-28 05:39:25 +00:00
|
|
|
assert "legacy_strategy.py" in captured.out
|
2019-12-24 14:35:38 +00:00
|
|
|
assert "DefaultStrategy" in captured.out
|
|
|
|
|
|
|
|
|
2020-02-02 16:13:17 +00:00
|
|
|
def test_start_list_hyperopts(mocker, caplog, capsys):
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"list-hyperopts",
|
|
|
|
"--hyperopt-path",
|
2020-08-06 07:00:28 +00:00
|
|
|
str(Path(__file__).parent.parent / "optimize" / "hyperopts"),
|
2020-02-02 16:13:17 +00:00
|
|
|
"-1"
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
# pargs['config'] = None
|
|
|
|
start_list_hyperopts(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "TestHyperoptLegacy" not in captured.out
|
|
|
|
assert "legacy_hyperopt.py" not in captured.out
|
|
|
|
assert "DefaultHyperOpt" in captured.out
|
|
|
|
assert "test_hyperopt.py" not in captured.out
|
|
|
|
|
|
|
|
# Test regular output
|
|
|
|
args = [
|
|
|
|
"list-hyperopts",
|
|
|
|
"--hyperopt-path",
|
2020-08-06 07:00:28 +00:00
|
|
|
str(Path(__file__).parent.parent / "optimize" / "hyperopts"),
|
2020-02-02 16:13:17 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
# pargs['config'] = None
|
|
|
|
start_list_hyperopts(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "TestHyperoptLegacy" not in captured.out
|
|
|
|
assert "legacy_hyperopt.py" not in captured.out
|
|
|
|
assert "DefaultHyperOpt" in captured.out
|
|
|
|
|
|
|
|
|
2020-01-25 12:38:13 +00:00
|
|
|
def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys):
|
|
|
|
patch_exchange(mocker, mock_markets=True)
|
2019-12-03 14:10:27 +00:00
|
|
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
|
|
|
exchange_has=MagicMock(return_value=True),
|
2020-01-25 12:38:13 +00:00
|
|
|
get_tickers=tickers,
|
2019-12-03 14:10:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
default_conf['pairlists'] = [
|
|
|
|
{
|
|
|
|
"method": "VolumePairList",
|
|
|
|
"number_assets": 5,
|
|
|
|
"sort_key": "quoteVolume",
|
|
|
|
},
|
|
|
|
{"method": "PrecisionFilter"},
|
|
|
|
{"method": "PriceFilter", "low_price_ratio": 0.02},
|
|
|
|
]
|
|
|
|
|
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
|
|
|
args = [
|
|
|
|
'test-pairlist',
|
2021-01-22 18:18:21 +00:00
|
|
|
'-c', 'config_bittrex.json.example'
|
2019-12-03 14:10:27 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
start_test_pairlist(get_args(args))
|
|
|
|
|
|
|
|
assert log_has_re(r"^Using resolved pairlist VolumePairList.*", caplog)
|
|
|
|
assert log_has_re(r"^Using resolved pairlist PrecisionFilter.*", caplog)
|
|
|
|
assert log_has_re(r"^Using resolved pairlist PriceFilter.*", caplog)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.match(r"Pairs for .*", captured.out)
|
|
|
|
assert re.match("['ETH/BTC', 'TKN/BTC', 'BLK/BTC', 'LTC/BTC', 'XRP/BTC']", captured.out)
|
2019-12-09 01:37:58 +00:00
|
|
|
|
2020-10-29 07:09:50 +00:00
|
|
|
args = [
|
|
|
|
'test-pairlist',
|
2021-01-22 18:18:21 +00:00
|
|
|
'-c', 'config_bittrex.json.example',
|
2020-10-29 07:09:50 +00:00
|
|
|
'--one-column',
|
|
|
|
]
|
|
|
|
start_test_pairlist(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.match(r"ETH/BTC\nTKN/BTC\nBLK/BTC\nLTC/BTC\nXRP/BTC\n", captured.out)
|
|
|
|
|
|
|
|
args = [
|
|
|
|
'test-pairlist',
|
2021-01-22 18:18:21 +00:00
|
|
|
'-c', 'config_bittrex.json.example',
|
2020-10-29 07:09:50 +00:00
|
|
|
'--print-json',
|
|
|
|
]
|
|
|
|
start_test_pairlist(get_args(args))
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert re.match(r'Pairs for BTC: \n\["ETH/BTC","TKN/BTC","BLK/BTC","LTC/BTC","XRP/BTC"\]\n',
|
|
|
|
captured.out)
|
|
|
|
|
2019-12-09 01:37:58 +00:00
|
|
|
|
2020-04-28 14:33:07 +00:00
|
|
|
def test_hyperopt_list(mocker, capsys, caplog, hyperopt_results):
|
2019-12-09 01:37:58 +00:00
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.optimize.hyperopt.Hyperopt.load_previous_results',
|
|
|
|
MagicMock(return_value=hyperopt_results)
|
|
|
|
)
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2019-12-09 01:37:58 +00:00
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 3/12", " 4/12", " 5/12",
|
|
|
|
" 6/12", " 7/12", " 8/12", " 9/12", " 10/12",
|
|
|
|
" 11/12", " 12/12"])
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--best",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2019-12-09 01:37:58 +00:00
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 1/12", " 5/12", " 10/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 2/12", " 3/12", " 4/12", " 6/12", " 7/12", " 8/12", " 9/12",
|
|
|
|
" 11/12", " 12/12"])
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--profitable",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2019-12-09 01:37:58 +00:00
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 2/12", " 10/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12",
|
|
|
|
" 11/12", " 12/12"])
|
2020-02-20 18:12:55 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--profitable",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-02-20 18:12:55 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
2020-02-20 18:18:42 +00:00
|
|
|
for x in [" 2/12", " 10/12", "Best result:", "Buy hyperspace params",
|
|
|
|
"Sell hyperspace params", "ROI table", "Stoploss"])
|
2020-02-20 18:12:55 +00:00
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12",
|
|
|
|
" 11/12", " 12/12"])
|
2020-02-11 15:02:08 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--min-trades", "20",
|
2020-02-11 15:02:08 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 3/12", " 6/12", " 7/12", " 9/12", " 11/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 4/12", " 5/12", " 8/12", " 10/12", " 12/12"])
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--profitable",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--max-trades", "20",
|
2020-02-11 15:02:08 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 2/12", " 10/12"])
|
2019-12-09 01:37:58 +00:00
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12",
|
|
|
|
" 11/12", " 12/12"])
|
2020-02-09 13:18:56 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--profitable",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--min-avg-profit", "0.11",
|
2020-02-09 13:18:56 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 2/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12",
|
|
|
|
" 10/12", " 11/12", " 12/12"])
|
2020-02-11 20:29:55 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--max-avg-profit", "0.10",
|
2020-02-11 20:29:55 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 1/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12",
|
|
|
|
" 11/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 2/12", " 4/12", " 10/12", " 12/12"])
|
2020-02-09 13:18:56 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--min-total-profit", "0.4",
|
2020-02-09 13:18:56 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 10/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12",
|
|
|
|
" 9/12", " 11/12", " 12/12"])
|
2020-02-11 20:29:55 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--max-total-profit", "0.4",
|
2020-02-11 20:29:55 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
2020-03-22 01:22:06 +00:00
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12",
|
|
|
|
" 9/12", " 11/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 4/12", " 10/12", " 12/12"])
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--min-objective", "0.1",
|
2020-03-22 01:22:06 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 10/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12", " 8/12",
|
|
|
|
" 9/12", " 11/12", " 12/12"])
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--max-objective", "0.1",
|
2020-03-22 01:22:06 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
2020-02-11 20:29:55 +00:00
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12",
|
|
|
|
" 9/12", " 11/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 4/12", " 10/12", " 12/12"])
|
2020-02-09 13:18:56 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--profitable",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--min-avg-time", "2000",
|
2020-02-09 13:18:56 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 10/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 2/12", " 3/12", " 4/12", " 5/12", " 6/12", " 7/12",
|
|
|
|
" 8/12", " 9/12", " 11/12", " 12/12"])
|
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--max-avg-time", "1500",
|
2020-02-09 13:18:56 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert all(x in captured.out
|
|
|
|
for x in [" 2/12", " 6/12"])
|
|
|
|
assert all(x not in captured.out
|
|
|
|
for x in [" 1/12", " 3/12", " 4/12", " 5/12", " 7/12", " 8/12"
|
|
|
|
" 9/12", " 10/12", " 11/12", " 12/12"])
|
2020-03-05 18:43:43 +00:00
|
|
|
args = [
|
|
|
|
"hyperopt-list",
|
|
|
|
"--no-details",
|
2021-01-31 13:50:39 +00:00
|
|
|
"--no-color",
|
2020-08-11 18:10:43 +00:00
|
|
|
"--export-csv", "test_file.csv",
|
2020-03-05 18:43:43 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_list(pargs)
|
|
|
|
captured = capsys.readouterr()
|
2020-04-28 14:33:07 +00:00
|
|
|
log_has("CSV file created: test_file.csv", caplog)
|
2020-03-05 18:43:43 +00:00
|
|
|
f = Path("test_file.csv")
|
|
|
|
assert 'Best,1,2,-1.25%,-0.00125625,,-2.51,"3,930.0 m",0.43662' in f.read_text()
|
|
|
|
assert f.is_file()
|
|
|
|
f.unlink()
|
2019-12-09 01:37:58 +00:00
|
|
|
|
2020-03-05 18:58:01 +00:00
|
|
|
|
2019-12-09 01:37:58 +00:00
|
|
|
def test_hyperopt_show(mocker, capsys, hyperopt_results):
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.optimize.hyperopt.Hyperopt.load_previous_results',
|
|
|
|
MagicMock(return_value=hyperopt_results)
|
|
|
|
)
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_show(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert " 12/12" in captured.out
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
"--best"
|
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_show(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert " 10/12" in captured.out
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
"-n", "1"
|
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_show(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert " 1/12" in captured.out
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
"--best",
|
|
|
|
"-n", "2"
|
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_show(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert " 5/12" in captured.out
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
"--best",
|
|
|
|
"-n", "-1"
|
|
|
|
]
|
2019-12-09 09:49:04 +00:00
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_hyperopt_show(pargs)
|
2019-12-09 01:37:58 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert " 10/12" in captured.out
|
2019-12-09 21:22:11 +00:00
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
"--best",
|
|
|
|
"-n", "-4"
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match="The index of the epoch to show should be greater than -4."):
|
|
|
|
start_hyperopt_show(pargs)
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"hyperopt-show",
|
|
|
|
"--best",
|
|
|
|
"-n", "4"
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match="The index of the epoch to show should be less than 4."):
|
|
|
|
start_hyperopt_show(pargs)
|
2019-12-28 09:37:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_convert_data(mocker, testdatadir):
|
2020-01-26 19:31:13 +00:00
|
|
|
ohlcv_mock = mocker.patch("freqtrade.commands.data_commands.convert_ohlcv_format")
|
|
|
|
trades_mock = mocker.patch("freqtrade.commands.data_commands.convert_trades_format")
|
2019-12-28 09:37:34 +00:00
|
|
|
args = [
|
|
|
|
"convert-data",
|
|
|
|
"--format-from",
|
|
|
|
"json",
|
|
|
|
"--format-to",
|
|
|
|
"jsongz",
|
|
|
|
"--datadir",
|
|
|
|
str(testdatadir),
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_convert_data(pargs, True)
|
|
|
|
assert trades_mock.call_count == 0
|
|
|
|
assert ohlcv_mock.call_count == 1
|
|
|
|
assert ohlcv_mock.call_args[1]['convert_from'] == 'json'
|
|
|
|
assert ohlcv_mock.call_args[1]['convert_to'] == 'jsongz'
|
|
|
|
assert ohlcv_mock.call_args[1]['erase'] is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_convert_data_trades(mocker, testdatadir):
|
2020-01-26 19:31:13 +00:00
|
|
|
ohlcv_mock = mocker.patch("freqtrade.commands.data_commands.convert_ohlcv_format")
|
|
|
|
trades_mock = mocker.patch("freqtrade.commands.data_commands.convert_trades_format")
|
2019-12-28 09:37:34 +00:00
|
|
|
args = [
|
|
|
|
"convert-trade-data",
|
|
|
|
"--format-from",
|
|
|
|
"jsongz",
|
|
|
|
"--format-to",
|
|
|
|
"json",
|
|
|
|
"--datadir",
|
|
|
|
str(testdatadir),
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_convert_data(pargs, False)
|
|
|
|
assert ohlcv_mock.call_count == 0
|
|
|
|
assert trades_mock.call_count == 1
|
|
|
|
assert trades_mock.call_args[1]['convert_from'] == 'jsongz'
|
|
|
|
assert trades_mock.call_args[1]['convert_to'] == 'json'
|
|
|
|
assert trades_mock.call_args[1]['erase'] is False
|
2020-05-02 09:44:18 +00:00
|
|
|
|
|
|
|
|
2020-07-12 08:01:37 +00:00
|
|
|
def test_start_list_data(testdatadir, capsys):
|
|
|
|
args = [
|
|
|
|
"list-data",
|
|
|
|
"--data-format-ohlcv",
|
|
|
|
"json",
|
|
|
|
"--datadir",
|
|
|
|
str(testdatadir),
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_list_data(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "Found 16 pair / timeframe combinations." in captured.out
|
2020-07-14 04:55:34 +00:00
|
|
|
assert "\n| Pair | Timeframe |\n" in captured.out
|
|
|
|
assert "\n| UNITTEST/BTC | 1m, 5m, 8m, 30m |\n" in captured.out
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"list-data",
|
|
|
|
"--data-format-ohlcv",
|
|
|
|
"json",
|
|
|
|
"--pairs", "XRP/ETH",
|
|
|
|
"--datadir",
|
|
|
|
str(testdatadir),
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_list_data(pargs)
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "Found 2 pair / timeframe combinations." in captured.out
|
|
|
|
assert "\n| Pair | Timeframe |\n" in captured.out
|
|
|
|
assert "UNITTEST/BTC" not in captured.out
|
|
|
|
assert "\n| XRP/ETH | 1m, 5m |\n" in captured.out
|
2020-07-12 08:01:37 +00:00
|
|
|
|
|
|
|
|
2020-05-02 09:44:18 +00:00
|
|
|
@pytest.mark.usefixtures("init_persistence")
|
|
|
|
def test_show_trades(mocker, fee, capsys, caplog):
|
2020-10-16 05:39:12 +00:00
|
|
|
mocker.patch("freqtrade.persistence.init_db")
|
2020-05-02 09:44:18 +00:00
|
|
|
create_mock_trades(fee)
|
|
|
|
args = [
|
|
|
|
"show-trades",
|
|
|
|
"--db-url",
|
|
|
|
"sqlite:///"
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_show_trades(pargs)
|
2020-09-10 05:40:19 +00:00
|
|
|
assert log_has(f"Printing {MOCK_TRADE_COUNT} Trades: ", caplog)
|
2020-05-02 09:44:18 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert "Trade(id=1" in captured.out
|
|
|
|
assert "Trade(id=2" in captured.out
|
|
|
|
assert "Trade(id=3" in captured.out
|
|
|
|
args = [
|
|
|
|
"show-trades",
|
|
|
|
"--db-url",
|
|
|
|
"sqlite:///",
|
|
|
|
"--print-json",
|
2020-05-03 13:32:09 +00:00
|
|
|
"--trade-ids", "1", "2"
|
2020-05-02 09:44:18 +00:00
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
start_show_trades(pargs)
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert log_has("Printing 2 Trades: ", caplog)
|
|
|
|
assert '"trade_id": 1' in captured.out
|
|
|
|
assert '"trade_id": 2' in captured.out
|
|
|
|
assert '"trade_id": 3' not in captured.out
|
2020-05-05 17:48:28 +00:00
|
|
|
args = [
|
|
|
|
"show-trades",
|
|
|
|
]
|
|
|
|
pargs = get_args(args)
|
|
|
|
pargs['config'] = None
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException, match=r"--db-url is required for this command."):
|
|
|
|
start_show_trades(pargs)
|