Merge branch 'feat/short' into pr/samgermain/5567

This commit is contained in:
Matthias
2021-10-17 10:41:03 +02:00
17 changed files with 94 additions and 28 deletions

View File

@@ -285,6 +285,7 @@ def create_mock_trades(fee, is_short: bool, use_db: bool = True):
add_trade(trade)
if use_db:
Trade.commit()
Trade.query.session.flush()
@@ -357,6 +358,7 @@ def create_mock_trades_usdt(fee, use_db: bool = True):
add_trade(trade)
if use_db:
Trade.commit()
Trade.query.session.flush()

View File

@@ -705,7 +705,7 @@ def test_simplified_interface_roi_stoploss(mocker, hyperopt_conf, capsys) -> Non
assert hasattr(hyperopt, "position_stacking")
def test_simplified_interface_all_failed(mocker, hyperopt_conf) -> None:
def test_simplified_interface_all_failed(mocker, hyperopt_conf, caplog) -> None:
mocker.patch('freqtrade.optimize.hyperopt.dump', MagicMock())
mocker.patch('freqtrade.optimize.hyperopt.file_dump_json')
mocker.patch('freqtrade.optimize.backtesting.Backtesting.load_bt_data',
@@ -727,7 +727,13 @@ def test_simplified_interface_all_failed(mocker, hyperopt_conf) -> None:
hyperopt.custom_hyperopt.generate_roi_table = MagicMock(return_value={})
with pytest.raises(OperationalException, match=r"The 'protection' space is included into *"):
hyperopt.start()
hyperopt.init_spaces()
hyperopt.config['hyperopt_ignore_missing_space'] = True
caplog.clear()
hyperopt.init_spaces()
assert log_has_re(r"The 'protection' space is included into *", caplog)
assert hyperopt.protection_space == []
def test_simplified_interface_buy(mocker, hyperopt_conf, capsys) -> None:

View File

@@ -666,11 +666,11 @@ def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
@pytest.mark.usefixtures("init_persistence")
# TODO-lev: @pytest.mark.parametrize('is_short', [True, False])
def test_PerformanceFilter_lookback(mocker, whitelist_conf, fee) -> None:
def test_PerformanceFilter_lookback(mocker, whitelist_conf, fee, caplog) -> None:
whitelist_conf['exchange']['pair_whitelist'].append('XRP/BTC')
whitelist_conf['pairlists'] = [
{"method": "StaticPairList"},
{"method": "PerformanceFilter", "minutes": 60}
{"method": "PerformanceFilter", "minutes": 60, "min_profit": 0.01}
]
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
exchange = get_patched_exchange(mocker, whitelist_conf)
@@ -682,7 +682,8 @@ def test_PerformanceFilter_lookback(mocker, whitelist_conf, fee) -> None:
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
create_mock_trades(fee, False)
pm.refresh_pairlist()
assert pm.whitelist == ['XRP/BTC', 'ETH/BTC', 'TKN/BTC']
assert pm.whitelist == ['XRP/BTC']
assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
# Move to "outside" of lookback window, so original sorting is restored.
t.move_to("2021-09-01 07:00:00 +00:00")

View File

@@ -95,7 +95,7 @@ def test_api_not_found(botclient):
assert rc.json() == {"detail": "Not Found"}
def test_api_ui_fallback(botclient):
def test_api_ui_fallback(botclient, mocker):
ftbot, client = botclient
rc = client_get(client, "/favicon.ico")
@@ -109,9 +109,16 @@ def test_api_ui_fallback(botclient):
rc = client_get(client, "/something")
assert rc.status_code == 200
# Test directory traversal
# Test directory traversal without mock
rc = client_get(client, '%2F%2F%2Fetc/passwd')
assert rc.status_code == 200
# Allow both fallback or real UI
assert '`freqtrade install-ui`' in rc.text or '<!DOCTYPE html>' in rc.text
mocker.patch.object(Path, 'is_file', MagicMock(side_effect=[True, False]))
rc = client_get(client, '%2F%2F%2Fetc/passwd')
assert rc.status_code == 200
assert '`freqtrade install-ui`' in rc.text
@@ -617,10 +624,11 @@ def test_api_delete_trade(botclient, mocker, fee, markets):
assert_response(rc, 502)
create_mock_trades(fee, False)
Trade.query.session.flush()
ftbot.strategy.order_types['stoploss_on_exchange'] = True
trades = Trade.query.all()
trades[1].stoploss_order_id = '1234'
Trade.commit()
assert len(trades) > 2
rc = client_delete(client, f"{BASE_URI}/trades/1")

View File

@@ -3738,9 +3738,9 @@ def test_disable_ignore_roi_if_buy_signal(default_conf_usdt, limit_order, limit_
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
fetch_ticker=MagicMock(return_value={
'bid': 0.00000172,
'ask': 0.00000173,
'last': 0.00000172
'bid': 2.0,
'ask': 2.0,
'last': 2.0
}),
create_order=MagicMock(side_effect=[
limit_order_open[enter_side(is_short)],
@@ -3770,7 +3770,7 @@ def test_disable_ignore_roi_if_buy_signal(default_conf_usdt, limit_order, limit_
# Test if buy-signal is absent
patch_get_signal(freqtrade, enter_long=False, exit_long=not is_short, exit_short=is_short)
assert freqtrade.handle_trade(trade) is True
assert trade.sell_reason == SellType.SELL_SIGNAL.value
assert trade.sell_reason == SellType.ROI.value
def test_get_real_amount_quote(default_conf_usdt, trades_for_order, buy_order_fee, fee, caplog,