Improve tests by also having a "Mixed" case
This commit is contained in:
parent
a08572e907
commit
9102590365
@ -248,33 +248,35 @@ def patch_get_signal(
|
|||||||
freqtrade.exchange.refresh_latest_ohlcv = lambda p: None
|
freqtrade.exchange.refresh_latest_ohlcv = lambda p: None
|
||||||
|
|
||||||
|
|
||||||
def create_mock_trades(fee, is_short: bool = False, use_db: bool = True):
|
def create_mock_trades(fee, is_short: Optional[bool] = False, use_db: bool = True):
|
||||||
"""
|
"""
|
||||||
Create some fake trades ...
|
Create some fake trades ...
|
||||||
|
:param is_short: Optional bool, None creates a mix of long and short trades.
|
||||||
"""
|
"""
|
||||||
def add_trade(trade):
|
def add_trade(trade):
|
||||||
if use_db:
|
if use_db:
|
||||||
Trade.query.session.add(trade)
|
Trade.query.session.add(trade)
|
||||||
else:
|
else:
|
||||||
LocalTrade.add_bt_trade(trade)
|
LocalTrade.add_bt_trade(trade)
|
||||||
|
is_short1 = is_short if is_short is not None else True
|
||||||
|
is_short2 = is_short if is_short is not None else False
|
||||||
# Simulate dry_run entries
|
# Simulate dry_run entries
|
||||||
trade = mock_trade_1(fee, is_short)
|
trade = mock_trade_1(fee, is_short1)
|
||||||
add_trade(trade)
|
add_trade(trade)
|
||||||
|
|
||||||
trade = mock_trade_2(fee, is_short)
|
trade = mock_trade_2(fee, is_short1)
|
||||||
add_trade(trade)
|
add_trade(trade)
|
||||||
|
|
||||||
trade = mock_trade_3(fee, is_short)
|
trade = mock_trade_3(fee, is_short2)
|
||||||
add_trade(trade)
|
add_trade(trade)
|
||||||
|
|
||||||
trade = mock_trade_4(fee, is_short)
|
trade = mock_trade_4(fee, is_short2)
|
||||||
add_trade(trade)
|
add_trade(trade)
|
||||||
|
|
||||||
trade = mock_trade_5(fee, is_short)
|
trade = mock_trade_5(fee, is_short2)
|
||||||
add_trade(trade)
|
add_trade(trade)
|
||||||
|
|
||||||
trade = mock_trade_6(fee, is_short)
|
trade = mock_trade_6(fee, is_short1)
|
||||||
add_trade(trade)
|
add_trade(trade)
|
||||||
|
|
||||||
if use_db:
|
if use_db:
|
||||||
|
@ -699,7 +699,7 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets):
|
|||||||
assert rc.json() == {"error": "Error querying /api/v1/edge: Edge is not enabled."}
|
assert rc.json() == {"error": "Error querying /api/v1/edge: Edge is not enabled."}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('is_short', [True, False])
|
@pytest.mark.parametrize('is_short', [True, False, None])
|
||||||
def test_api_profit(botclient, mocker, ticker, fee, markets, is_short):
|
def test_api_profit(botclient, mocker, ticker, fee, markets, is_short):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
patch_get_signal(ftbot)
|
patch_get_signal(ftbot)
|
||||||
@ -721,36 +721,43 @@ def test_api_profit(botclient, mocker, ticker, fee, markets, is_short):
|
|||||||
rc = client_get(client, f"{BASE_URI}/profit")
|
rc = client_get(client, f"{BASE_URI}/profit")
|
||||||
assert_response(rc)
|
assert_response(rc)
|
||||||
# raise ValueError(rc.json())
|
# raise ValueError(rc.json())
|
||||||
assert rc.json() == {'avg_duration': ANY,
|
assert rc.json() == {
|
||||||
|
'avg_duration': ANY,
|
||||||
'best_pair': 'ETC/BTC' if is_short else 'XRP/BTC',
|
'best_pair': 'ETC/BTC' if is_short else 'XRP/BTC',
|
||||||
'best_rate': -0.5 if is_short else 1.0,
|
'best_rate': -0.5 if is_short else 1.0,
|
||||||
'first_trade_date': ANY,
|
'first_trade_date': ANY,
|
||||||
'first_trade_timestamp': ANY,
|
'first_trade_timestamp': ANY,
|
||||||
'latest_trade_date': '5 minutes ago',
|
'latest_trade_date': '5 minutes ago',
|
||||||
'latest_trade_timestamp': ANY,
|
'latest_trade_timestamp': ANY,
|
||||||
'profit_all_coin': 43.61269123 if is_short else -44.0631579,
|
'profit_all_coin': 43.61269123 if is_short else -14.43790415
|
||||||
'profit_all_fiat': 538398.67323435 if is_short else -543959.6842755,
|
if is_short is None else -44.0631579,
|
||||||
'profit_all_percent_mean': 66.41 if is_short else -66.41,
|
'profit_all_fiat': 538398.67323435 if is_short else -178235.92673175
|
||||||
'profit_all_ratio_mean': 0.664109545 if is_short else -0.6641100666666667,
|
if is_short is None else -543959.6842755,
|
||||||
'profit_all_percent_sum': 398.47 if is_short else -398.47,
|
'profit_all_percent_mean': 66.41 if is_short else 0.08 if is_short is None else -66.41,
|
||||||
'profit_all_ratio_sum': 3.98465727 if is_short else -3.9846604,
|
'profit_all_ratio_mean': 0.664109545 if is_short else 0.000835751666666662
|
||||||
'profit_all_percent': 4.36 if is_short else -4.41,
|
if is_short is None else -0.6641100666666667,
|
||||||
'profit_all_ratio': 0.043612222872799825 if is_short
|
'profit_all_percent_sum': 398.47 if is_short else 0.5 if is_short is None else -398.47,
|
||||||
else -0.044063014216106644,
|
'profit_all_ratio_sum': 3.98465727 if is_short else 0.005014509999999972
|
||||||
'profit_closed_coin': -0.00673913 if is_short else 0.00073913,
|
if is_short is None else -3.9846604,
|
||||||
'profit_closed_fiat': -83.19455985 if is_short else 9.124559849999999,
|
'profit_all_percent': 4.36 if is_short else -1.44 if is_short is None else -4.41,
|
||||||
'profit_closed_ratio_mean': -0.0075 if is_short else 0.0075,
|
'profit_all_ratio': 0.043612222872799825 if is_short else -0.014437768014451796
|
||||||
'profit_closed_percent_mean': -0.75 if is_short else 0.75,
|
if is_short is None else -0.044063014216106644,
|
||||||
'profit_closed_ratio_sum': -0.015 if is_short else 0.015,
|
'profit_closed_coin': -0.00673913 if is_short else -0.00542913
|
||||||
'profit_closed_percent_sum': -1.5 if is_short else 1.5,
|
if is_short is None else 0.00073913,
|
||||||
|
'profit_closed_fiat': -83.19455985 if is_short else -67.02260985
|
||||||
|
if is_short is None else 9.124559849999999,
|
||||||
|
'profit_closed_ratio_mean': -0.0075 if is_short else 0.0025 if is_short is None else 0.0075,
|
||||||
|
'profit_closed_percent_mean': -0.75 if is_short else 0.25 if is_short is None else 0.75,
|
||||||
|
'profit_closed_ratio_sum': -0.015 if is_short else 0.005 if is_short is None else 0.015,
|
||||||
|
'profit_closed_percent_sum': -1.5 if is_short else 0.5 if is_short is None else 1.5,
|
||||||
'profit_closed_ratio': -6.739057628404269e-06 if is_short
|
'profit_closed_ratio': -6.739057628404269e-06 if is_short
|
||||||
else 7.391275897987988e-07,
|
else -5.429078808526421e-06 if is_short is None else 7.391275897987988e-07,
|
||||||
'profit_closed_percent': -0.0 if is_short else 0.0,
|
'profit_closed_percent': -0.0 if is_short else -0.0 if is_short is None else 0.0,
|
||||||
'trade_count': 6,
|
'trade_count': 6,
|
||||||
'closed_trade_count': 2,
|
'closed_trade_count': 2,
|
||||||
'short_trades': 6 if is_short else 0,
|
'short_trades': 6 if is_short else 3 if is_short is None else 0,
|
||||||
'winning_trades': 0 if is_short else 2,
|
'winning_trades': 0 if is_short else 1 if is_short is None else 2,
|
||||||
'losing_trades': 2 if is_short else 0,
|
'losing_trades': 2 if is_short else 1 if is_short is None else 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -976,6 +983,7 @@ def test_api_whitelist(botclient):
|
|||||||
"method": ["StaticPairList"]
|
"method": ["StaticPairList"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('is_short', [True, False])
|
@pytest.mark.parametrize('is_short', [True, False])
|
||||||
def test_api_forcebuy(botclient, mocker, fee, is_short):
|
def test_api_forcebuy(botclient, mocker, fee, is_short):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
|
@ -4317,7 +4317,7 @@ def test_sync_wallet_dry_run(mocker, default_conf_usdt, ticker_usdt, fee, limit_
|
|||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
@pytest.mark.parametrize("is_short,buy_calls,sell_calls", [
|
@pytest.mark.parametrize("is_short,buy_calls,sell_calls", [
|
||||||
(False, 1, 2),
|
(False, 1, 2),
|
||||||
(True, 2, 1),
|
(True, 1, 2),
|
||||||
])
|
])
|
||||||
def test_cancel_all_open_orders(mocker, default_conf_usdt, fee, limit_order, limit_order_open,
|
def test_cancel_all_open_orders(mocker, default_conf_usdt, fee, limit_order, limit_order_open,
|
||||||
is_short, buy_calls, sell_calls):
|
is_short, buy_calls, sell_calls):
|
||||||
|
Loading…
Reference in New Issue
Block a user