mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-26 06:11:45 +00:00
Merge branch 'freqtrade:develop' into bt-metrics
This commit is contained in:
@@ -30,7 +30,7 @@ def test_validate_is_int():
|
||||
assert not validate_is_int('-ee')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exchange', ['bittrex', 'binance', 'kraken'])
|
||||
@pytest.mark.parametrize('exchange', ['bybit', 'binance', 'kraken'])
|
||||
def test_start_new_config(mocker, caplog, exchange):
|
||||
wt_mock = mocker.patch.object(Path, "write_text", MagicMock())
|
||||
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
||||
|
||||
@@ -32,7 +32,7 @@ from tests.conftest_trades import MOCK_TRADE_COUNT
|
||||
|
||||
def test_setup_utils_configuration():
|
||||
args = [
|
||||
'list-exchanges', '--config', 'config_examples/config_bittrex.example.json',
|
||||
'list-exchanges', '--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
]
|
||||
|
||||
config = setup_utils_configuration(get_args(args), RunMode.OTHER)
|
||||
@@ -49,7 +49,7 @@ def test_start_trading_fail(mocker, caplog):
|
||||
exitmock = mocker.patch("freqtrade.worker.Worker.exit", MagicMock())
|
||||
args = [
|
||||
'trade',
|
||||
'-c', 'config_examples/config_bittrex.example.json'
|
||||
'-c', 'tests/testdata/testconfigs/main_test_config.json'
|
||||
]
|
||||
start_trading(get_args(args))
|
||||
assert exitmock.call_count == 1
|
||||
@@ -68,7 +68,7 @@ def test_start_webserver(mocker, caplog):
|
||||
|
||||
args = [
|
||||
'webserver',
|
||||
'-c', 'config_examples/config_bittrex.example.json'
|
||||
'-c', 'tests/testdata/testconfigs/main_test_config.json'
|
||||
]
|
||||
start_webserver(get_args(args))
|
||||
assert api_server_mock.call_count == 1
|
||||
@@ -84,7 +84,7 @@ def test_list_exchanges(capsys):
|
||||
captured = capsys.readouterr()
|
||||
assert re.match(r"Exchanges available for Freqtrade.*", captured.out)
|
||||
assert re.search(r".*binance.*", captured.out)
|
||||
assert re.search(r".*bittrex.*", captured.out)
|
||||
assert re.search(r".*bybit.*", captured.out)
|
||||
|
||||
# Test with --one-column
|
||||
args = [
|
||||
@@ -95,7 +95,7 @@ def test_list_exchanges(capsys):
|
||||
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"^bybit$", captured.out, re.MULTILINE)
|
||||
|
||||
# Test with --all
|
||||
args = [
|
||||
@@ -107,7 +107,7 @@ def test_list_exchanges(capsys):
|
||||
captured = capsys.readouterr()
|
||||
assert re.match(r"All exchanges supported by the ccxt library.*", captured.out)
|
||||
assert re.search(r".*binance.*", captured.out)
|
||||
assert re.search(r".*bittrex.*", captured.out)
|
||||
assert re.search(r".*bingx.*", captured.out)
|
||||
assert re.search(r".*bitmex.*", captured.out)
|
||||
|
||||
# Test with --one-column --all
|
||||
@@ -120,7 +120,7 @@ def test_list_exchanges(capsys):
|
||||
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"^bingx$", captured.out, re.MULTILINE)
|
||||
assert re.search(r"^bitmex$", captured.out, re.MULTILINE)
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ def test_list_timeframes(mocker, capsys):
|
||||
'1h': 'hour',
|
||||
'1d': 'day',
|
||||
}
|
||||
patch_exchange(mocker, api_mock=api_mock, id='bittrex')
|
||||
patch_exchange(mocker, api_mock=api_mock, id='bybit')
|
||||
args = [
|
||||
"list-timeframes",
|
||||
]
|
||||
@@ -143,25 +143,25 @@ def test_list_timeframes(mocker, capsys):
|
||||
match=r"This command requires a configured exchange.*"):
|
||||
start_list_timeframes(pargs)
|
||||
|
||||
# Test with --config config_examples/config_bittrex.example.json
|
||||
# Test with --config tests/testdata/testconfigs/main_test_config.json
|
||||
args = [
|
||||
"list-timeframes",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
]
|
||||
start_list_timeframes(get_args(args))
|
||||
captured = capsys.readouterr()
|
||||
assert re.match("Timeframes available for the exchange `Bittrex`: "
|
||||
assert re.match("Timeframes available for the exchange `Bybit`: "
|
||||
"1m, 5m, 30m, 1h, 1d",
|
||||
captured.out)
|
||||
|
||||
# Test with --exchange bittrex
|
||||
# Test with --exchange bybit
|
||||
args = [
|
||||
"list-timeframes",
|
||||
"--exchange", "bittrex",
|
||||
"--exchange", "bybit",
|
||||
]
|
||||
start_list_timeframes(get_args(args))
|
||||
captured = capsys.readouterr()
|
||||
assert re.match("Timeframes available for the exchange `Bittrex`: "
|
||||
assert re.match("Timeframes available for the exchange `Bybit`: "
|
||||
"1m, 5m, 30m, 1h, 1d",
|
||||
captured.out)
|
||||
|
||||
@@ -190,7 +190,7 @@ def test_list_timeframes(mocker, capsys):
|
||||
# Test with --one-column
|
||||
args = [
|
||||
"list-timeframes",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--one-column",
|
||||
]
|
||||
start_list_timeframes(get_args(args))
|
||||
@@ -217,7 +217,7 @@ def test_list_timeframes(mocker, capsys):
|
||||
def test_list_markets(mocker, markets_static, capsys):
|
||||
|
||||
api_mock = MagicMock()
|
||||
patch_exchange(mocker, api_mock=api_mock, id='bittrex', mock_markets=markets_static)
|
||||
patch_exchange(mocker, api_mock=api_mock, id='binance', mock_markets=markets_static)
|
||||
|
||||
# Test with no --config
|
||||
args = [
|
||||
@@ -229,15 +229,15 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
match=r"This command requires a configured exchange.*"):
|
||||
start_list_markets(pargs, False)
|
||||
|
||||
# Test with --config config_examples/config_bittrex.example.json
|
||||
# Test with --config tests/testdata/testconfigs/main_test_config.json
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 12 active markets: "
|
||||
assert ("Exchange Binance has 12 active markets: "
|
||||
"ADA/USDT:USDT, BLK/BTC, ETH/BTC, ETH/USDT, ETH/USDT:USDT, LTC/BTC, "
|
||||
"LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n"
|
||||
in captured.out)
|
||||
@@ -255,16 +255,16 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
assert re.match("\nExchange Binance has 12 active markets:\n",
|
||||
captured.out)
|
||||
|
||||
patch_exchange(mocker, api_mock=api_mock, id="bittrex", mock_markets=markets_static)
|
||||
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
|
||||
# Test with --all: all markets
|
||||
args = [
|
||||
"list-markets", "--all",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 14 markets: "
|
||||
assert ("Exchange Binance has 14 markets: "
|
||||
"ADA/USDT:USDT, BLK/BTC, BTT/BTC, ETH/BTC, ETH/USDT, ETH/USDT:USDT, "
|
||||
"LTC/BTC, LTC/ETH, LTC/USD, LTC/USDT, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n"
|
||||
in captured.out)
|
||||
@@ -272,24 +272,24 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
# Test list-pairs subcommand: active pairs
|
||||
args = [
|
||||
"list-pairs",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), True)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 9 active pairs: "
|
||||
assert ("Exchange Binance has 9 active pairs: "
|
||||
"BLK/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XRP/BTC.\n"
|
||||
in captured.out)
|
||||
|
||||
# Test list-pairs subcommand with --all: all pairs
|
||||
args = [
|
||||
"list-pairs", "--all",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), True)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 11 pairs: "
|
||||
assert ("Exchange Binance has 11 pairs: "
|
||||
"BLK/BTC, BTT/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, LTC/USDT, NEO/BTC, "
|
||||
"TKN/BTC, XRP/BTC.\n"
|
||||
in captured.out)
|
||||
@@ -297,133 +297,133 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
# active markets, base=ETH, LTC
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--base", "ETH", "LTC",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 7 active markets with ETH, LTC as base currencies: "
|
||||
assert ("Exchange Binance has 7 active markets with ETH, LTC as base currencies: "
|
||||
"ETH/BTC, ETH/USDT, ETH/USDT:USDT, LTC/BTC, LTC/ETH, LTC/USD, XLTCUSDT.\n"
|
||||
in captured.out)
|
||||
|
||||
# active markets, base=LTC
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--base", "LTC",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 4 active markets with LTC as base currency: "
|
||||
assert ("Exchange Binance has 4 active markets with LTC as base currency: "
|
||||
"LTC/BTC, LTC/ETH, LTC/USD, XLTCUSDT.\n"
|
||||
in captured.out)
|
||||
|
||||
# active markets, quote=USDT, USD
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--quote", "USDT", "USD",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 5 active markets with USDT, USD as quote currencies: "
|
||||
assert ("Exchange Binance has 5 active markets with USDT, USD as quote currencies: "
|
||||
"ADA/USDT:USDT, ETH/USDT, ETH/USDT:USDT, LTC/USD, XLTCUSDT.\n"
|
||||
in captured.out)
|
||||
|
||||
# active markets, quote=USDT
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--quote", "USDT",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 4 active markets with USDT as quote currency: "
|
||||
assert ("Exchange Binance has 4 active markets with USDT as quote currency: "
|
||||
"ADA/USDT:USDT, ETH/USDT, ETH/USDT:USDT, XLTCUSDT.\n"
|
||||
in captured.out)
|
||||
|
||||
# active markets, base=LTC, quote=USDT
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--base", "LTC", "--quote", "USDT",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 1 active market with LTC as base currency and "
|
||||
assert ("Exchange Binance has 1 active market with LTC as base currency and "
|
||||
"with USDT as quote currency: XLTCUSDT.\n"
|
||||
in captured.out)
|
||||
|
||||
# active pairs, base=LTC, quote=USDT
|
||||
args = [
|
||||
"list-pairs",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--base", "LTC", "--quote", "USD",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), True)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 1 active pair with LTC as base currency and "
|
||||
assert ("Exchange Binance has 1 active pair with LTC as base currency and "
|
||||
"with USD as quote currency: LTC/USD.\n"
|
||||
in captured.out)
|
||||
|
||||
# active markets, base=LTC, quote=USDT, NONEXISTENT
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--base", "LTC", "--quote", "USDT", "NONEXISTENT",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 1 active market with LTC as base currency and "
|
||||
assert ("Exchange Binance has 1 active market with LTC as base currency and "
|
||||
"with USDT, NONEXISTENT as quote currencies: XLTCUSDT.\n"
|
||||
in captured.out)
|
||||
|
||||
# active markets, base=LTC, quote=NONEXISTENT
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--base", "LTC", "--quote", "NONEXISTENT",
|
||||
"--print-list",
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 0 active markets with LTC as base currency and "
|
||||
assert ("Exchange Binance 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",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
captured = capsys.readouterr()
|
||||
assert ("Exchange Bittrex has 12 active markets:\n"
|
||||
assert ("Exchange Binance has 12 active markets:\n"
|
||||
in captured.out)
|
||||
|
||||
# Test tabular output, no markets found
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--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 "
|
||||
assert ("Exchange Binance 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",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--print-json"
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
@@ -435,7 +435,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
# Test --print-csv
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--print-csv"
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
@@ -447,7 +447,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
# Test --one-column
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--one-column"
|
||||
]
|
||||
start_list_markets(get_args(args), False)
|
||||
@@ -459,7 +459,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||
# Test --one-column
|
||||
args = [
|
||||
"list-markets",
|
||||
'--config', 'config_examples/config_bittrex.example.json',
|
||||
'--config', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
"--one-column"
|
||||
]
|
||||
with pytest.raises(OperationalException, match=r"Cannot get markets.*"):
|
||||
@@ -971,7 +971,7 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys):
|
||||
patched_configuration_load_config_file(mocker, default_conf)
|
||||
args = [
|
||||
'test-pairlist',
|
||||
'-c', 'config_examples/config_bittrex.example.json'
|
||||
'-c', 'tests/testdata/testconfigs/main_test_config.json'
|
||||
]
|
||||
|
||||
start_test_pairlist(get_args(args))
|
||||
@@ -985,7 +985,7 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys):
|
||||
|
||||
args = [
|
||||
'test-pairlist',
|
||||
'-c', 'config_examples/config_bittrex.example.json',
|
||||
'-c', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
'--one-column',
|
||||
]
|
||||
start_test_pairlist(get_args(args))
|
||||
@@ -994,7 +994,7 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys):
|
||||
|
||||
args = [
|
||||
'test-pairlist',
|
||||
'-c', 'config_examples/config_bittrex.example.json',
|
||||
'-c', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
'--print-json',
|
||||
]
|
||||
start_test_pairlist(get_args(args))
|
||||
|
||||
@@ -91,6 +91,8 @@ def generate_test_data(timeframe: str, size: int, start: str = '2020-07-05'):
|
||||
base = np.random.normal(20, 2, size=size)
|
||||
if timeframe == '1M':
|
||||
date = pd.date_range(start, periods=size, freq='1MS', tz='UTC')
|
||||
elif timeframe == '1w':
|
||||
date = pd.date_range(start, periods=size, freq='1W-MON', tz='UTC')
|
||||
else:
|
||||
tf_mins = timeframe_to_minutes(timeframe)
|
||||
date = pd.date_range(start, periods=size, freq=f'{tf_mins}min', tz='UTC')
|
||||
|
||||
@@ -64,7 +64,7 @@ def test_ohlcv_fill_up_missing_data(testdatadir, caplog):
|
||||
# Column names should not change
|
||||
assert (data.columns == data2.columns).all()
|
||||
|
||||
assert log_has_re(f"Missing data fillup for UNITTEST/BTC: before: "
|
||||
assert log_has_re(f"Missing data fillup for UNITTEST/BTC, 1m: before: "
|
||||
f"{len(data)} - after: {len(data2)}.*", caplog)
|
||||
|
||||
# Test fillup actually fixes invalid backtest data
|
||||
@@ -128,7 +128,7 @@ def test_ohlcv_fill_up_missing_data2(caplog):
|
||||
# Column names should not change
|
||||
assert (data.columns == data2.columns).all()
|
||||
|
||||
assert log_has_re(f"Missing data fillup for UNITTEST/BTC: before: "
|
||||
assert log_has_re(f"Missing data fillup for UNITTEST/BTC, {timeframe}: before: "
|
||||
f"{len(data)} - after: {len(data2)}.*", caplog)
|
||||
|
||||
|
||||
|
||||
@@ -500,3 +500,89 @@ def test_dp__add_external_df(default_conf_usdt):
|
||||
# 36 hours - from 2022-01-03 12:00:00+00:00 to 2022-01-05 00:00:00+00:00
|
||||
assert isinstance(res[1], int)
|
||||
assert res[1] == 0
|
||||
|
||||
|
||||
def test_dp_get_required_startup(default_conf_usdt):
|
||||
timeframe = '1h'
|
||||
default_conf_usdt["timeframe"] = timeframe
|
||||
dp = DataProvider(default_conf_usdt, None)
|
||||
|
||||
# No FreqAI config
|
||||
assert dp.get_required_startup('5m', False) == 0
|
||||
assert dp.get_required_startup('1h', False) == 0
|
||||
assert dp.get_required_startup('1d', False) == 0
|
||||
assert dp.get_required_startup('1d', True) == 0
|
||||
assert dp.get_required_startup('1d') == 0
|
||||
|
||||
dp._config['startup_candle_count'] = 20
|
||||
assert dp.get_required_startup('5m', False) == 20
|
||||
assert dp.get_required_startup('5m', True) == 20
|
||||
assert dp.get_required_startup('1h', False) == 20
|
||||
assert dp.get_required_startup('1h') == 20
|
||||
|
||||
# With freqAI config
|
||||
|
||||
dp._config['freqai'] = {
|
||||
'enabled': True,
|
||||
'train_period_days': 20,
|
||||
'feature_parameters': {
|
||||
'indicator_periods_candles': [
|
||||
5,
|
||||
20,
|
||||
]
|
||||
}
|
||||
}
|
||||
assert dp.get_required_startup('5m', False) == 20
|
||||
assert dp.get_required_startup('5m', True) == 5780
|
||||
|
||||
assert dp.get_required_startup('1h', False) == 20
|
||||
assert dp.get_required_startup('1h', True) == 500
|
||||
|
||||
assert dp.get_required_startup('1d', False) == 20
|
||||
assert dp.get_required_startup('1d', True) == 40
|
||||
assert dp.get_required_startup('1d') == 40
|
||||
|
||||
# FreqAI kindof ignores startup_candle_count if it's below indicator_periods_candles
|
||||
dp._config['startup_candle_count'] = 0
|
||||
assert dp.get_required_startup('5m', False) == 20
|
||||
assert dp.get_required_startup('5m', True) == 5780
|
||||
|
||||
assert dp.get_required_startup('1h', False) == 20
|
||||
assert dp.get_required_startup('1h', True) == 500
|
||||
|
||||
assert dp.get_required_startup('1d', False) == 20
|
||||
assert dp.get_required_startup('1d', True) == 40
|
||||
assert dp.get_required_startup('1d') == 40
|
||||
|
||||
dp._config['freqai']['feature_parameters']['indicator_periods_candles'][1] = 50
|
||||
assert dp.get_required_startup('5m', False) == 50
|
||||
assert dp.get_required_startup('5m', True) == 5810
|
||||
|
||||
assert dp.get_required_startup('1h', False) == 50
|
||||
assert dp.get_required_startup('1h', True) == 530
|
||||
|
||||
assert dp.get_required_startup('1d', False) == 50
|
||||
assert dp.get_required_startup('1d', True) == 70
|
||||
assert dp.get_required_startup('1d') == 70
|
||||
|
||||
# scenario from issue https://github.com/freqtrade/freqtrade/issues/9432
|
||||
dp._config['freqai'] = {
|
||||
'enabled': True,
|
||||
'train_period_days': 180,
|
||||
'feature_parameters': {
|
||||
'indicator_periods_candles': [
|
||||
10,
|
||||
20,
|
||||
]
|
||||
}
|
||||
}
|
||||
dp._config['startup_candle_count'] = 40
|
||||
assert dp.get_required_startup('5m', False) == 40
|
||||
assert dp.get_required_startup('5m', True) == 51880
|
||||
|
||||
assert dp.get_required_startup('1h', False) == 40
|
||||
assert dp.get_required_startup('1h', True) == 4360
|
||||
|
||||
assert dp.get_required_startup('1d', False) == 40
|
||||
assert dp.get_required_startup('1d', True) == 220
|
||||
assert dp.get_required_startup('1d') == 220
|
||||
|
||||
@@ -13,7 +13,7 @@ from freqtrade.enums import CandleType, MarginMode, TradingMode
|
||||
from freqtrade.exceptions import (DDosProtection, DependencyException, ExchangeError,
|
||||
InsufficientFundsError, InvalidOrderException,
|
||||
OperationalException, PricingError, TemporaryError)
|
||||
from freqtrade.exchange import (Binance, Bittrex, Exchange, Kraken, market_is_active,
|
||||
from freqtrade.exchange import (Binance, Bybit, Exchange, Kraken, market_is_active,
|
||||
timeframe_to_prev_date)
|
||||
from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, API_RETRY_COUNT,
|
||||
calculate_backoff, remove_exchange_credentials)
|
||||
@@ -228,10 +228,10 @@ def test_exchange_resolver(default_conf, mocker, caplog):
|
||||
assert log_has_re(r"No .* specific subclass found. Using the generic class instead.", caplog)
|
||||
caplog.clear()
|
||||
|
||||
default_conf['exchange']['name'] = 'Bittrex'
|
||||
default_conf['exchange']['name'] = 'Bybit'
|
||||
exchange = ExchangeResolver.load_exchange(default_conf)
|
||||
assert isinstance(exchange, Exchange)
|
||||
assert isinstance(exchange, Bittrex)
|
||||
assert isinstance(exchange, Bybit)
|
||||
assert not log_has_re(r"No .* specific subclass found. Using the generic class instead.",
|
||||
caplog)
|
||||
caplog.clear()
|
||||
@@ -263,8 +263,8 @@ def test_exchange_resolver(default_conf, mocker, caplog):
|
||||
|
||||
def test_validate_order_time_in_force(default_conf, mocker, caplog):
|
||||
caplog.set_level(logging.INFO)
|
||||
# explicitly test bittrex, exchanges implementing other policies need separate tests
|
||||
ex = get_patched_exchange(mocker, default_conf, id="bittrex")
|
||||
# explicitly test bybit, exchanges implementing other policies need separate tests
|
||||
ex = get_patched_exchange(mocker, default_conf, id="bybit")
|
||||
tif = {
|
||||
"buy": "gtc",
|
||||
"sell": "gtc",
|
||||
@@ -273,11 +273,14 @@ def test_validate_order_time_in_force(default_conf, mocker, caplog):
|
||||
ex.validate_order_time_in_force(tif)
|
||||
tif2 = {
|
||||
"buy": "fok",
|
||||
"sell": "ioc",
|
||||
"sell": "ioc22",
|
||||
}
|
||||
with pytest.raises(OperationalException, match=r"Time in force.*not supported for .*"):
|
||||
ex.validate_order_time_in_force(tif2)
|
||||
|
||||
tif2 = {
|
||||
"buy": "fok",
|
||||
"sell": "ioc",
|
||||
}
|
||||
# Patch to see if this will pass if the values are in the ft dict
|
||||
ex._ft_has.update({"order_time_in_force": ["GTC", "FOK", "IOC"]})
|
||||
ex.validate_order_time_in_force(tif2)
|
||||
@@ -915,7 +918,6 @@ def test_validate_ordertypes(default_conf, mocker):
|
||||
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||
mocker.patch(f'{EXMS}.validate_pricing')
|
||||
mocker.patch(f'{EXMS}.name', 'Bittrex')
|
||||
|
||||
default_conf['order_types'] = {
|
||||
'entry': 'limit',
|
||||
@@ -2766,7 +2768,6 @@ async def test___async_get_candle_history_sort(default_conf, mocker, exchange_na
|
||||
assert res_ohlcv[9][4] == 0.07668
|
||||
assert res_ohlcv[9][5] == 16.65244264
|
||||
|
||||
# Bittrex use-case (real data from Bittrex)
|
||||
# This OHLCV data is ordered ASC (oldest first, newest last)
|
||||
ohlcv = [
|
||||
[1527827700000, 0.07659999, 0.0766, 0.07627, 0.07657998, 1.85216924],
|
||||
@@ -3410,7 +3411,7 @@ def test_get_fee(default_conf, mocker, exchange_name):
|
||||
|
||||
|
||||
def test_stoploss_order_unsupported_exchange(default_conf, mocker):
|
||||
exchange = get_patched_exchange(mocker, default_conf, id='bittrex')
|
||||
exchange = get_patched_exchange(mocker, default_conf, id='bitpanda')
|
||||
with pytest.raises(OperationalException, match=r"stoploss is not implemented .*"):
|
||||
exchange.create_stoploss(
|
||||
pair='ETH/BTC',
|
||||
@@ -3606,10 +3607,10 @@ def test_ohlcv_candle_limit(default_conf, mocker, exchange_name):
|
||||
timeframes = ('1m', '5m', '1h')
|
||||
expected = exchange._ft_has['ohlcv_candle_limit']
|
||||
for timeframe in timeframes:
|
||||
if 'ohlcv_candle_limit_per_timeframe' in exchange._ft_has:
|
||||
expected = exchange._ft_has['ohlcv_candle_limit_per_timeframe'][timeframe]
|
||||
# This should only run for bittrex
|
||||
assert exchange_name == 'bittrex'
|
||||
# if 'ohlcv_candle_limit_per_timeframe' in exchange._ft_has:
|
||||
# expected = exchange._ft_has['ohlcv_candle_limit_per_timeframe'][timeframe]
|
||||
# This should only run for bittrex
|
||||
# assert exchange_name == 'bittrex'
|
||||
assert exchange.ohlcv_candle_limit(timeframe, CandleType.SPOT) == expected
|
||||
|
||||
|
||||
@@ -4522,10 +4523,10 @@ def test_amount_to_contract_precision(
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exchange_name,open_rate,is_short,trading_mode,margin_mode', [
|
||||
# Bittrex
|
||||
('bittrex', 2.0, False, 'spot', None),
|
||||
('bittrex', 2.0, False, 'spot', 'cross'),
|
||||
('bittrex', 2.0, True, 'spot', 'isolated'),
|
||||
# Bybit
|
||||
('bybit', 2.0, False, 'spot', None),
|
||||
('bybit', 2.0, False, 'spot', 'cross'),
|
||||
('bybit', 2.0, True, 'spot', 'isolated'),
|
||||
# Binance
|
||||
('binance', 2.0, False, 'spot', None),
|
||||
('binance', 2.0, False, 'spot', 'cross'),
|
||||
@@ -4947,7 +4948,7 @@ def test_get_max_leverage_futures(default_conf, mocker, leverage_tiers):
|
||||
exchange.get_max_leverage("BTC/USDT:USDT", 1000000000.01)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exchange_name", ['bittrex', 'binance', 'kraken', 'gate', 'okx', 'bybit'])
|
||||
@pytest.mark.parametrize("exchange_name", ['binance', 'kraken', 'gate', 'okx', 'bybit'])
|
||||
def test__get_params(mocker, default_conf, exchange_name):
|
||||
api_mock = MagicMock()
|
||||
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||
|
||||
@@ -218,9 +218,6 @@ class TestCCXTExchange:
|
||||
|
||||
def test_ccxt__async_get_candle_history(self, exchange: EXCHANGE_FIXTURE_TYPE):
|
||||
exc, exchangename = exchange
|
||||
if exchangename in ('bittrex'):
|
||||
# For some weired reason, this test returns random lengths for bittrex.
|
||||
pytest.skip("Exchange doesn't provide stable ohlcv history")
|
||||
|
||||
if not exc._ft_has['ohlcv_has_history']:
|
||||
pytest.skip("Exchange does not support candle history")
|
||||
|
||||
@@ -20,6 +20,21 @@ def is_mac() -> bool:
|
||||
return "Darwin" in machine
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_torch_initlogs(mocker) -> None:
|
||||
|
||||
if is_mac():
|
||||
# Mock torch import completely
|
||||
import sys
|
||||
import types
|
||||
|
||||
module_name = 'torch'
|
||||
mocked_module = types.ModuleType(module_name)
|
||||
sys.modules[module_name] = mocked_module
|
||||
else:
|
||||
mocker.patch("torch._logging._init_logs")
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def freqai_conf(default_conf, tmp_path):
|
||||
freqaiconf = deepcopy(default_conf)
|
||||
|
||||
@@ -176,6 +176,7 @@ def test_extract_data_and_train_model_MultiTargets(mocker, freqai_conf, model, s
|
||||
'CatboostClassifier',
|
||||
'XGBoostClassifier',
|
||||
'XGBoostRFClassifier',
|
||||
'SKLearnRandomForestClassifier',
|
||||
'PyTorchMLPClassifier',
|
||||
])
|
||||
def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model):
|
||||
|
||||
@@ -549,6 +549,7 @@ def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
||||
default_conf_usdt['exchange']['pair_whitelist'] = ['.*']
|
||||
backtesting = Backtesting(default_conf_usdt)
|
||||
backtesting._set_strategy(backtesting.strategylist[0])
|
||||
mocker.patch('freqtrade.optimize.backtesting.Backtesting._run_funding_fees')
|
||||
pair = 'ETH/USDT:USDT'
|
||||
row = [
|
||||
pd.Timestamp(year=2020, month=1, day=1, hour=5, minute=0),
|
||||
@@ -851,9 +852,13 @@ def test_backtest_one_detail(default_conf_usdt, fee, mocker, testdatadir, use_de
|
||||
assert late_entry > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('use_detail', [True, False])
|
||||
@pytest.mark.parametrize('use_detail,exp_funding_fee, exp_ff_updates', [
|
||||
(True, -0.018054162, 11),
|
||||
(False, -0.01780296, 5),
|
||||
])
|
||||
def test_backtest_one_detail_futures(
|
||||
default_conf_usdt, fee, mocker, testdatadir, use_detail) -> None:
|
||||
default_conf_usdt, fee, mocker, testdatadir, use_detail, exp_funding_fee,
|
||||
exp_ff_updates) -> None:
|
||||
default_conf_usdt['use_exit_signal'] = False
|
||||
default_conf_usdt['trading_mode'] = 'futures'
|
||||
default_conf_usdt['margin_mode'] = 'isolated'
|
||||
@@ -882,6 +887,8 @@ def test_backtest_one_detail_futures(
|
||||
default_conf_usdt['max_open_trades'] = 10
|
||||
|
||||
backtesting = Backtesting(default_conf_usdt)
|
||||
ff_spy = mocker.spy(backtesting.exchange, 'calculate_funding_fees')
|
||||
|
||||
backtesting._set_strategy(backtesting.strategylist[0])
|
||||
backtesting.strategy.populate_entry_trend = advise_entry
|
||||
backtesting.strategy.custom_entry_price = custom_entry_price
|
||||
@@ -936,13 +943,22 @@ def test_backtest_one_detail_futures(
|
||||
|
||||
assert (round(ln2.iloc[0]["low"], 6) <= round(
|
||||
t["close_rate"], 6) <= round(ln2.iloc[0]["high"], 6))
|
||||
assert -0.0181 < Trade.trades[1].funding_fees < -0.01
|
||||
assert pytest.approx(Trade.trades[1].funding_fees) == exp_funding_fee
|
||||
assert ff_spy.call_count == exp_ff_updates
|
||||
# assert late_entry > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('use_detail', [True, False])
|
||||
@pytest.mark.parametrize('use_detail,entries,max_stake,ff_updates,expected_ff', [
|
||||
(True, 50, 3000, 54, -1.18038144),
|
||||
(False, 6, 360, 10, -0.14679994),
|
||||
])
|
||||
def test_backtest_one_detail_futures_funding_fees(
|
||||
default_conf_usdt, fee, mocker, testdatadir, use_detail) -> None:
|
||||
default_conf_usdt, fee, mocker, testdatadir, use_detail, entries, max_stake,
|
||||
ff_updates, expected_ff,
|
||||
) -> None:
|
||||
"""
|
||||
Funding fees are expected to differ, as the maximum position size differs.
|
||||
"""
|
||||
default_conf_usdt['use_exit_signal'] = False
|
||||
default_conf_usdt['trading_mode'] = 'futures'
|
||||
default_conf_usdt['margin_mode'] = 'isolated'
|
||||
@@ -975,6 +991,7 @@ def test_backtest_one_detail_futures_funding_fees(
|
||||
default_conf_usdt['max_open_trades'] = 1
|
||||
|
||||
backtesting = Backtesting(default_conf_usdt)
|
||||
ff_spy = mocker.spy(backtesting.exchange, 'calculate_funding_fees')
|
||||
backtesting._set_strategy(backtesting.strategylist[0])
|
||||
backtesting.strategy.populate_entry_trend = advise_entry
|
||||
backtesting.strategy.adjust_trade_position = adjust_trade_position
|
||||
@@ -1000,13 +1017,18 @@ def test_backtest_one_detail_futures_funding_fees(
|
||||
assert len(results) == 1
|
||||
|
||||
assert 'orders' in results.columns
|
||||
# funding_fees have been calculated for each funding-fee candle
|
||||
# the trade is open for 26 hours - hence we expect the 8h fee to apply 4 times.
|
||||
# Additional counts will happen due each successful entry, which needs to call this, too.
|
||||
assert ff_spy.call_count == ff_updates
|
||||
|
||||
for t in Trade.trades:
|
||||
# At least 4 adjustment orders
|
||||
assert t.nr_of_successful_entries >= 6
|
||||
# At least 6 adjustment orders
|
||||
assert t.nr_of_successful_entries == entries
|
||||
# Funding fees will vary depending on the number of adjustment orders
|
||||
# That number is a lot higher with detail data.
|
||||
assert -1.81 < t.funding_fees < -0.1
|
||||
assert t.max_stake_amount == max_stake
|
||||
assert pytest.approx(t.funding_fees) == expected_ff
|
||||
|
||||
|
||||
def test_backtest_timedout_entry_orders(default_conf, fee, mocker, testdatadir) -> None:
|
||||
|
||||
@@ -104,6 +104,7 @@ def test_backtest_position_adjustment_detailed(default_conf, fee, mocker, levera
|
||||
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||
mocker.patch(f"{EXMS}.get_max_leverage", return_value=10)
|
||||
mocker.patch(f"{EXMS}.get_maintenance_ratio_and_amt", return_value=(0.1, 0.1))
|
||||
mocker.patch('freqtrade.optimize.backtesting.Backtesting._run_funding_fees')
|
||||
|
||||
patch_exchange(mocker)
|
||||
default_conf.update({
|
||||
|
||||
@@ -1770,6 +1770,7 @@ def test_api_freqaimodels(botclient, tmp_path, mocker):
|
||||
{'name': 'LightGBMRegressorMultiTarget'},
|
||||
{'name': 'ReinforcementLearner'},
|
||||
{'name': 'ReinforcementLearner_multiproc'},
|
||||
{'name': 'SKlearnRandomForestClassifier'},
|
||||
{'name': 'XGBoostClassifier'},
|
||||
{'name': 'XGBoostRFClassifier'},
|
||||
{'name': 'XGBoostRFRegressor'},
|
||||
@@ -1788,6 +1789,7 @@ def test_api_freqaimodels(botclient, tmp_path, mocker):
|
||||
'LightGBMRegressorMultiTarget',
|
||||
'ReinforcementLearner',
|
||||
'ReinforcementLearner_multiproc',
|
||||
'SKlearnRandomForestClassifier',
|
||||
'XGBoostClassifier',
|
||||
'XGBoostRFClassifier',
|
||||
'XGBoostRFRegressor',
|
||||
|
||||
@@ -63,7 +63,35 @@ def test_merge_informative_pair():
|
||||
assert result.iloc[8]['date_1h'] is pd.NaT
|
||||
|
||||
|
||||
def test_merge_informative_pair_high_tf():
|
||||
def test_merge_informative_pair_weekly():
|
||||
# Covers roughly 2 months - until 2023-01-10
|
||||
data = generate_test_data('1h', 1040, '2022-11-28')
|
||||
informative = generate_test_data('1w', 40, '2022-11-01')
|
||||
informative['day'] = informative['date'].dt.day_name()
|
||||
|
||||
result = merge_informative_pair(data, informative, '1h', '1w', ffill=True)
|
||||
assert isinstance(result, pd.DataFrame)
|
||||
# 2022-12-24 is a Saturday
|
||||
candle1 = result.loc[(result['date'] == '2022-12-24T22:00:00.000Z')]
|
||||
assert candle1.iloc[0]['date'] == pd.Timestamp('2022-12-24T22:00:00.000Z')
|
||||
assert candle1.iloc[0]['date_1w'] == pd.Timestamp('2022-12-12T00:00:00.000Z')
|
||||
|
||||
candle2 = result.loc[(result['date'] == '2022-12-24T23:00:00.000Z')]
|
||||
assert candle2.iloc[0]['date'] == pd.Timestamp('2022-12-24T23:00:00.000Z')
|
||||
assert candle2.iloc[0]['date_1w'] == pd.Timestamp('2022-12-12T00:00:00.000Z')
|
||||
|
||||
# 2022-12-25 is a Sunday
|
||||
candle3 = result.loc[(result['date'] == '2022-12-25T22:00:00.000Z')]
|
||||
assert candle3.iloc[0]['date'] == pd.Timestamp('2022-12-25T22:00:00.000Z')
|
||||
# Still old candle
|
||||
assert candle3.iloc[0]['date_1w'] == pd.Timestamp('2022-12-12T00:00:00.000Z')
|
||||
|
||||
candle4 = result.loc[(result['date'] == '2022-12-25T23:00:00.000Z')]
|
||||
assert candle4.iloc[0]['date'] == pd.Timestamp('2022-12-25T23:00:00.000Z')
|
||||
assert candle4.iloc[0]['date_1w'] == pd.Timestamp('2022-12-19T00:00:00.000Z')
|
||||
|
||||
|
||||
def test_merge_informative_pair_monthly():
|
||||
# Covers roughly 2 months - until 2023-01-10
|
||||
data = generate_test_data('1h', 1040, '2022-11-28')
|
||||
informative = generate_test_data('1M', 40, '2022-01-01')
|
||||
|
||||
@@ -173,7 +173,7 @@ def test_download_data_options() -> None:
|
||||
def test_plot_dataframe_options() -> None:
|
||||
args = [
|
||||
'plot-dataframe',
|
||||
'-c', 'config_examples/config_bittrex.example.json',
|
||||
'-c', 'tests/testdata/testconfigs/main_test_config.json',
|
||||
'--indicators1', 'sma10', 'sma100',
|
||||
'--indicators2', 'macd', 'fastd', 'fastk',
|
||||
'--plot-limit', '30',
|
||||
|
||||
@@ -146,7 +146,7 @@ def test_get_trade_stake_amount(default_conf_usdt, mocker) -> None:
|
||||
|
||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||
|
||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/USDT', 1)
|
||||
assert result == default_conf_usdt['stake_amount']
|
||||
|
||||
|
||||
@@ -211,12 +211,12 @@ def test_check_available_stake_amount(
|
||||
|
||||
if expected[i] is not None:
|
||||
limit_buy_order_usdt_open['id'] = str(i)
|
||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/USDT', 1)
|
||||
assert pytest.approx(result) == expected[i]
|
||||
freqtrade.execute_entry('ETH/USDT', result)
|
||||
else:
|
||||
with pytest.raises(DependencyException):
|
||||
freqtrade.wallets.get_trade_stake_amount('ETH/USDT')
|
||||
freqtrade.wallets.get_trade_stake_amount('ETH/USDT', 1)
|
||||
|
||||
|
||||
def test_edge_called_in_process(mocker, edge_conf) -> None:
|
||||
@@ -238,9 +238,9 @@ def test_edge_overrides_stake_amount(mocker, edge_conf) -> None:
|
||||
freqtrade = FreqtradeBot(edge_conf)
|
||||
|
||||
assert freqtrade.wallets.get_trade_stake_amount(
|
||||
'NEO/BTC', freqtrade.edge) == (999.9 * 0.5 * 0.01) / 0.20
|
||||
'NEO/BTC', 1, freqtrade.edge) == (999.9 * 0.5 * 0.01) / 0.20
|
||||
assert freqtrade.wallets.get_trade_stake_amount(
|
||||
'LTC/BTC', freqtrade.edge) == (999.9 * 0.5 * 0.01) / 0.21
|
||||
'LTC/BTC', 1, freqtrade.edge) == (999.9 * 0.5 * 0.01) / 0.21
|
||||
|
||||
|
||||
@pytest.mark.parametrize('buy_price_mult,ignore_strat_sl', [
|
||||
@@ -420,7 +420,8 @@ def test_create_trade_minimal_amount(
|
||||
else:
|
||||
assert not freqtrade.create_trade('ETH/USDT')
|
||||
if not max_open_trades:
|
||||
assert freqtrade.wallets.get_trade_stake_amount('ETH/USDT', freqtrade.edge) == 0
|
||||
assert freqtrade.wallets.get_trade_stake_amount(
|
||||
'ETH/USDT', default_conf_usdt['max_open_trades'], freqtrade.edge) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('whitelist,positions', [
|
||||
@@ -3485,7 +3486,7 @@ def test_handle_cancel_enter(mocker, caplog, default_conf_usdt, limit_order, is_
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_short", [False, True])
|
||||
@pytest.mark.parametrize("limit_buy_order_canceled_empty", ['binance', 'kraken', 'bittrex'],
|
||||
@pytest.mark.parametrize("limit_buy_order_canceled_empty", ['binance', 'kraken', 'bybit'],
|
||||
indirect=['limit_buy_order_canceled_empty'])
|
||||
def test_handle_cancel_enter_exchanges(mocker, caplog, default_conf_usdt, is_short, fee,
|
||||
limit_buy_order_canceled_empty) -> None:
|
||||
|
||||
@@ -185,7 +185,7 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, mocker, balance_rati
|
||||
|
||||
trades = Trade.session.scalars(select(Trade)).all()
|
||||
assert len(trades) == 4
|
||||
assert freqtrade.wallets.get_trade_stake_amount('XRP/BTC') == result1
|
||||
assert freqtrade.wallets.get_trade_stake_amount('XRP/BTC', 5) == result1
|
||||
|
||||
rpc._rpc_force_entry('TKN/BTC', None)
|
||||
|
||||
@@ -205,7 +205,7 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, mocker, balance_rati
|
||||
# One trade sold
|
||||
assert len(trades) == 4
|
||||
# stake-amount should now be reduced, since one trade was sold at a loss.
|
||||
assert freqtrade.wallets.get_trade_stake_amount('XRP/BTC') < result1
|
||||
assert freqtrade.wallets.get_trade_stake_amount('XRP/BTC', 5) < result1
|
||||
# Validate that balance of sold trade is not in dry-run balances anymore.
|
||||
bals2 = freqtrade.wallets.get_all_balances()
|
||||
assert bals != bals2
|
||||
|
||||
@@ -67,12 +67,12 @@ def test_main_fatal_exception(mocker, default_conf, caplog) -> None:
|
||||
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
||||
mocker.patch('freqtrade.freqtradebot.init_db', MagicMock())
|
||||
|
||||
args = ['trade', '-c', 'config_examples/config_bittrex.example.json']
|
||||
args = ['trade', '-c', 'tests/testdata/testconfigs/main_test_config.json']
|
||||
|
||||
# Test Main + the KeyboardInterrupt exception
|
||||
with pytest.raises(SystemExit):
|
||||
main(args)
|
||||
assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog)
|
||||
assert log_has('Using config: tests/testdata/testconfigs/main_test_config.json ...', caplog)
|
||||
assert log_has('Fatal exception!', caplog)
|
||||
|
||||
|
||||
@@ -85,12 +85,12 @@ def test_main_keyboard_interrupt(mocker, default_conf, caplog) -> None:
|
||||
mocker.patch('freqtrade.wallets.Wallets.update', MagicMock())
|
||||
mocker.patch('freqtrade.freqtradebot.init_db', MagicMock())
|
||||
|
||||
args = ['trade', '-c', 'config_examples/config_bittrex.example.json']
|
||||
args = ['trade', '-c', 'tests/testdata/testconfigs/main_test_config.json']
|
||||
|
||||
# Test Main + the KeyboardInterrupt exception
|
||||
with pytest.raises(SystemExit):
|
||||
main(args)
|
||||
assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog)
|
||||
assert log_has('Using config: tests/testdata/testconfigs/main_test_config.json ...', caplog)
|
||||
assert log_has('SIGINT received, aborting ...', caplog)
|
||||
|
||||
|
||||
@@ -106,12 +106,12 @@ def test_main_operational_exception(mocker, default_conf, caplog) -> None:
|
||||
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
||||
mocker.patch('freqtrade.freqtradebot.init_db', MagicMock())
|
||||
|
||||
args = ['trade', '-c', 'config_examples/config_bittrex.example.json']
|
||||
args = ['trade', '-c', 'tests/testdata/testconfigs/main_test_config.json']
|
||||
|
||||
# Test Main + the KeyboardInterrupt exception
|
||||
with pytest.raises(SystemExit):
|
||||
main(args)
|
||||
assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog)
|
||||
assert log_has('Using config: tests/testdata/testconfigs/main_test_config.json ...', caplog)
|
||||
assert log_has('Oh snap!', caplog)
|
||||
|
||||
|
||||
@@ -160,13 +160,13 @@ def test_main_reload_config(mocker, default_conf, caplog) -> None:
|
||||
args = Arguments([
|
||||
'trade',
|
||||
'-c',
|
||||
'config_examples/config_bittrex.example.json'
|
||||
'tests/testdata/testconfigs/main_test_config.json'
|
||||
]).get_parsed_arg()
|
||||
worker = Worker(args=args, config=default_conf)
|
||||
with pytest.raises(SystemExit):
|
||||
main(['trade', '-c', 'config_examples/config_bittrex.example.json'])
|
||||
main(['trade', '-c', 'tests/testdata/testconfigs/main_test_config.json'])
|
||||
|
||||
assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog)
|
||||
assert log_has('Using config: tests/testdata/testconfigs/main_test_config.json ...', caplog)
|
||||
assert worker_mock.call_count == 4
|
||||
assert reconfigure_mock.call_count == 1
|
||||
assert isinstance(worker.freqtrade, FreqtradeBot)
|
||||
@@ -187,7 +187,7 @@ def test_reconfigure(mocker, default_conf) -> None:
|
||||
args = Arguments([
|
||||
'trade',
|
||||
'-c',
|
||||
'config_examples/config_bittrex.example.json'
|
||||
'tests/testdata/testconfigs/main_test_config.json'
|
||||
]).get_parsed_arg()
|
||||
worker = Worker(args=args, config=default_conf)
|
||||
freqtrade = worker.freqtrade
|
||||
|
||||
@@ -377,7 +377,7 @@ def test_start_plot_dataframe(mocker):
|
||||
aup = mocker.patch("freqtrade.plot.plotting.load_and_plot_trades", MagicMock())
|
||||
args = [
|
||||
"plot-dataframe",
|
||||
"--config", "config_examples/config_bittrex.example.json",
|
||||
"--config", "tests/testdata/testconfigs/main_test_config.json",
|
||||
"--pairs", "ETH/BTC"
|
||||
]
|
||||
start_plot_dataframe(get_args(args))
|
||||
@@ -420,7 +420,7 @@ def test_start_plot_profit(mocker):
|
||||
aup = mocker.patch("freqtrade.plot.plotting.plot_profit", MagicMock())
|
||||
args = [
|
||||
"plot-profit",
|
||||
"--config", "config_examples/config_bittrex.example.json",
|
||||
"--config", "tests/testdata/testconfigs/main_test_config.json",
|
||||
"--pairs", "ETH/BTC"
|
||||
]
|
||||
start_plot_profit(get_args(args))
|
||||
|
||||
@@ -121,7 +121,7 @@ def test_get_trade_stake_amount_no_stake_amount(default_conf, mocker) -> None:
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||
|
||||
with pytest.raises(DependencyException, match=r'.*stake amount.*'):
|
||||
freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
||||
freqtrade.wallets.get_trade_stake_amount('ETH/BTC', 1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("balance_ratio,capital,result1,result2", [
|
||||
@@ -148,7 +148,6 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r
|
||||
conf = deepcopy(default_conf)
|
||||
conf['stake_amount'] = UNLIMITED_STAKE_AMOUNT
|
||||
conf['dry_run_wallet'] = 100
|
||||
conf['max_open_trades'] = 2
|
||||
conf['tradable_balance_ratio'] = balance_ratio
|
||||
if capital is not None:
|
||||
conf['available_capital'] = capital
|
||||
@@ -156,30 +155,28 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r
|
||||
freqtrade = get_patched_freqtradebot(mocker, conf)
|
||||
|
||||
# no open trades, order amount should be 'balance / max_open_trades'
|
||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/USDT', 2)
|
||||
assert result == result1
|
||||
|
||||
# create one trade, order amount should be 'balance / (max_open_trades - num_open_trades)'
|
||||
freqtrade.execute_entry('ETH/USDT', result)
|
||||
|
||||
result = freqtrade.wallets.get_trade_stake_amount('LTC/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('LTC/USDT', 2)
|
||||
assert result == result1
|
||||
|
||||
# create 2 trades, order amount should be None
|
||||
freqtrade.execute_entry('LTC/BTC', result)
|
||||
|
||||
result = freqtrade.wallets.get_trade_stake_amount('XRP/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('XRP/USDT', 2)
|
||||
assert result == 0
|
||||
|
||||
freqtrade.config['max_open_trades'] = 3
|
||||
freqtrade.config['dry_run_wallet'] = 200
|
||||
freqtrade.wallets.start_cap = 200
|
||||
result = freqtrade.wallets.get_trade_stake_amount('XRP/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('XRP/USDT', 3)
|
||||
assert round(result, 4) == round(result2, 4)
|
||||
|
||||
# set max_open_trades = None, so do not trade
|
||||
freqtrade.config['max_open_trades'] = 0
|
||||
result = freqtrade.wallets.get_trade_stake_amount('NEO/USDT')
|
||||
result = freqtrade.wallets.get_trade_stake_amount('NEO/USDT', 0)
|
||||
assert result == 0
|
||||
|
||||
|
||||
|
||||
77
tests/testdata/testconfigs/main_test_config.json
vendored
Normal file
77
tests/testdata/testconfigs/main_test_config.json
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"max_open_trades": 3,
|
||||
"stake_currency": "BTC",
|
||||
"stake_amount": 0.05,
|
||||
"tradable_balance_ratio": 0.99,
|
||||
"fiat_display_currency": "USD",
|
||||
"timeframe": "5m",
|
||||
"dry_run": true,
|
||||
"cancel_open_orders_on_exit": false,
|
||||
"unfilledtimeout": {
|
||||
"entry": 10,
|
||||
"exit": 10,
|
||||
"exit_timeout_count": 0,
|
||||
"unit": "minutes"
|
||||
},
|
||||
"entry_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"price_last_balance": 0.0,
|
||||
"check_depth_of_market": {
|
||||
"enabled": false,
|
||||
"bids_to_ask_delta": 1
|
||||
}
|
||||
},
|
||||
"exit_pricing":{
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1
|
||||
},
|
||||
"exchange": {
|
||||
"name": "binance",
|
||||
"key": "your_exchange_key",
|
||||
"secret": "your_exchange_secret",
|
||||
"ccxt_config": {},
|
||||
"ccxt_async_config": {},
|
||||
"pair_whitelist": [
|
||||
"ETH/BTC",
|
||||
"LTC/BTC",
|
||||
"ETC/BTC",
|
||||
"RVN/BTC",
|
||||
"CRO/BTC",
|
||||
"XLM/BTC",
|
||||
"XRP/BTC",
|
||||
"TRX/BTC",
|
||||
"ADA/BTC",
|
||||
"DOT/BTC"
|
||||
],
|
||||
"pair_blacklist": [
|
||||
"DOGE/BTC"
|
||||
]
|
||||
},
|
||||
"pairlists": [
|
||||
{"method": "StaticPairList"}
|
||||
],
|
||||
"telegram": {
|
||||
"enabled": false,
|
||||
"token": "your_telegram_token",
|
||||
"chat_id": "your_telegram_chat_id"
|
||||
},
|
||||
"api_server": {
|
||||
"enabled": false,
|
||||
"listen_ip_address": "127.0.0.1",
|
||||
"listen_port": 8080,
|
||||
"verbosity": "error",
|
||||
"jwt_secret_key": "somethingrandom",
|
||||
"CORS_origins": [],
|
||||
"username": "freqtrader",
|
||||
"password": "SuperSecurePassword"
|
||||
},
|
||||
"bot_name": "freqtrade",
|
||||
"initial_state": "running",
|
||||
"force_entry_enable": false,
|
||||
"internals": {
|
||||
"process_throttle_secs": 5
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user