removed short_trades, updated schema, tests

This commit is contained in:
aezo.teo 2021-11-16 14:03:33 +08:00
parent 9c34208b15
commit c17c1611bd
4 changed files with 82 additions and 60 deletions

View File

@ -95,7 +95,6 @@ class Profit(BaseModel):
avg_duration: str avg_duration: str
best_pair: str best_pair: str
best_rate: float best_rate: float
short_trades: int
winning_trades: int winning_trades: int
losing_trades: int losing_trades: int

View File

@ -358,7 +358,6 @@ class RPC:
durations = [] durations = []
winning_trades = 0 winning_trades = 0
losing_trades = 0 losing_trades = 0
short_trades = 0
for trade in trades: for trade in trades:
current_rate: float = 0.0 current_rate: float = 0.0
@ -391,9 +390,6 @@ class RPC:
) )
profit_all_ratio.append(profit_ratio) profit_all_ratio.append(profit_ratio)
if trade.is_short:
short_trades += 1
best_pair = Trade.get_best_pair(start_date) best_pair = Trade.get_best_pair(start_date)
# Prepare data to display # Prepare data to display
@ -453,7 +449,6 @@ class RPC:
'avg_duration': str(timedelta(seconds=sum(durations) / num)).split('.')[0], 'avg_duration': str(timedelta(seconds=sum(durations) / num)).split('.')[0],
'best_pair': best_pair[0] if best_pair else '', 'best_pair': best_pair[0] if best_pair else '',
'best_rate': round(best_pair[1] * 100, 2) if best_pair else 0, 'best_rate': round(best_pair[1] * 100, 2) if best_pair else 0,
'short_trades': short_trades,
'winning_trades': winning_trades, 'winning_trades': winning_trades,
'losing_trades': losing_trades, 'losing_trades': losing_trades,
} }

View File

@ -476,7 +476,7 @@ def test_api_count(botclient, mocker, ticker, fee, markets, is_short):
assert rc.json()["max"] == 1 assert rc.json()["max"] == 1
# Create some test data # Create some test data
create_mock_trades(fee, is_short) create_mock_trades(fee, is_short=is_short)
rc = client_get(client, f"{BASE_URI}/count") rc = client_get(client, f"{BASE_URI}/count")
assert_response(rc) assert_response(rc)
assert rc.json()["current"] == 4 assert rc.json()["current"] == 4
@ -700,12 +700,45 @@ 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', [ @pytest.mark.parametrize(
(True), 'is_short, best_pair, best_rate, profit_all_coin, profit_all_fiat,'
(False), 'profit_all_percent_mean, profit_all_ratio_mean, profit_all_percent_sum,'
(None), 'profit_all_ratio_sum, profit_all_percent, profit_all_ratio,'
]) 'profit_closed_coin, profit_closed_fiat, profit_closed_ratio_mean,'
def test_api_profit(botclient, mocker, ticker, fee, markets, is_short): 'profit_closed_percent_mean, profit_closed_ratio_sum,'
'profit_closed_percent_sum, profit_closed_ratio,'
'profit_closed_percent, winning_trades, losing_trades',
[
(True, 'ETC/BTC', -0.5, 43.61269123, 538398.67323435,
66.41, 0.664109545, 398.47,
3.98465727, 4.36, 0.043612222872799825,
-0.00673913, -83.19455985, -0.0075,
-0.75, -0.015,
-1.5, -6.739057628404269e-06,
-0.0, 0, 2),
(False, 'XRP/BTC', 1.0, -44.0631579, -543959.6842755,
-66.41, -0.6641100666666667, -398.47,
-3.9846604, -4.41, -0.044063014216106644,
0.00073913, 9.124559849999999, 0.0075,
0.75, 0.015,
1.5, 7.391275897987988e-07,
0.0, 2, 0),
(None, 'XRP/BTC', 1.0, -14.43790415, -178235.92673175,
0.08, 0.000835751666666662, 0.5,
0.005014509999999972, -1.44, -0.014437768014451796,
-0.00542913, -67.02260985, 0.0025,
0.25, 0.005,
0.5, -5.429078808526421e-06,
-0.0, 1, 1)
])
def test_api_profit(
botclient, mocker, ticker, fee, markets, is_short, best_pair, best_rate, profit_all_coin,
profit_all_fiat, profit_all_percent_mean, profit_all_ratio_mean, profit_all_percent_sum,
profit_all_ratio_sum, profit_all_percent, profit_all_ratio, profit_closed_coin,
profit_closed_fiat, profit_closed_ratio_mean, profit_closed_percent_mean,
profit_closed_ratio_sum, profit_closed_percent_sum, profit_closed_ratio,
profit_closed_percent, winning_trades, losing_trades
):
ftbot, client = botclient ftbot, client = botclient
patch_get_signal(ftbot) patch_get_signal(ftbot)
mocker.patch.multiple( mocker.patch.multiple(
@ -728,41 +761,32 @@ def test_api_profit(botclient, mocker, ticker, fee, markets, is_short):
# raise ValueError(rc.json()) # raise ValueError(rc.json())
assert rc.json() == { assert rc.json() == {
'avg_duration': ANY, 'avg_duration': ANY,
'best_pair': 'ETC/BTC' if is_short else 'XRP/BTC', 'best_pair': best_pair,
'best_rate': -0.5 if is_short else 1.0, 'best_rate': best_rate,
'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 -14.43790415 'profit_all_coin': profit_all_coin,
if is_short is None else -44.0631579, 'profit_all_fiat': profit_all_fiat,
'profit_all_fiat': 538398.67323435 if is_short else -178235.92673175 'profit_all_percent_mean': profit_all_percent_mean,
if is_short is None else -543959.6842755, 'profit_all_ratio_mean': profit_all_ratio_mean,
'profit_all_percent_mean': 66.41 if is_short else 0.08 if is_short is None else -66.41, 'profit_all_percent_sum': profit_all_percent_sum,
'profit_all_ratio_mean': 0.664109545 if is_short else 0.000835751666666662 'profit_all_ratio_sum': profit_all_ratio_sum,
if is_short is None else -0.6641100666666667, 'profit_all_percent': profit_all_percent,
'profit_all_percent_sum': 398.47 if is_short else 0.5 if is_short is None else -398.47, 'profit_all_ratio': profit_all_ratio,
'profit_all_ratio_sum': 3.98465727 if is_short else 0.005014509999999972 'profit_closed_coin': profit_closed_coin,
if is_short is None else -3.9846604, 'profit_closed_fiat': profit_closed_fiat,
'profit_all_percent': 4.36 if is_short else -1.44 if is_short is None else -4.41, 'profit_closed_ratio_mean': profit_closed_ratio_mean,
'profit_all_ratio': 0.043612222872799825 if is_short else -0.014437768014451796 'profit_closed_percent_mean': profit_closed_percent_mean,
if is_short is None else -0.044063014216106644, 'profit_closed_ratio_sum': profit_closed_ratio_sum,
'profit_closed_coin': -0.00673913 if is_short else -0.00542913 'profit_closed_percent_sum': profit_closed_percent_sum,
if is_short is None else 0.00073913, 'profit_closed_ratio': profit_closed_ratio,
'profit_closed_fiat': -83.19455985 if is_short else -67.02260985 'profit_closed_percent': profit_closed_percent,
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
else -5.429078808526421e-06 if is_short is None else 7.391275897987988e-07,
'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 3 if is_short is None else 0, 'winning_trades': winning_trades,
'winning_trades': 0 if is_short else 1 if is_short is None else 2, 'losing_trades': losing_trades,
'losing_trades': 2 if is_short else 1 if is_short is None else 0,
} }
@ -843,8 +867,12 @@ def test_api_performance(botclient, fee):
'profit_ratio': -0.05570419, 'profit_abs': -0.1150375}] 'profit_ratio': -0.05570419, 'profit_abs': -0.1150375}]
@pytest.mark.parametrize('is_short', [True, False]) @pytest.mark.parametrize(
def test_api_status(botclient, mocker, ticker, fee, markets, is_short): 'is_short,current_rate,open_order_id,open_trade_value',
[(True, 1.098e-05, 'dry_run_buy_short_12345', 15.0911775),
(False, 1.099e-05, 'dry_run_buy_long_12345', 15.1668225)])
def test_api_status(botclient, mocker, ticker, fee, markets, is_short,
current_rate, open_order_id, open_trade_value):
ftbot, client = botclient ftbot, client = botclient
patch_get_signal(ftbot) patch_get_signal(ftbot)
mocker.patch.multiple( mocker.patch.multiple(
@ -859,7 +887,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets, is_short):
rc = client_get(client, f"{BASE_URI}/status") rc = client_get(client, f"{BASE_URI}/status")
assert_response(rc, 200) assert_response(rc, 200)
assert rc.json() == [] assert rc.json() == []
create_mock_trades(fee, is_short) create_mock_trades(fee, is_short=is_short)
rc = client_get(client, f"{BASE_URI}/status") rc = client_get(client, f"{BASE_URI}/status")
assert_response(rc) assert_response(rc)
@ -880,7 +908,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets, is_short):
'profit_pct': ANY, 'profit_pct': ANY,
'profit_abs': ANY, 'profit_abs': ANY,
'profit_fiat': ANY, 'profit_fiat': ANY,
'current_rate': 1.098e-05 if is_short else 1.099e-05, 'current_rate': current_rate,
'open_date': ANY, 'open_date': ANY,
'open_timestamp': ANY, 'open_timestamp': ANY,
'open_order': None, 'open_order': None,
@ -913,9 +941,9 @@ def test_api_status(botclient, mocker, ticker, fee, markets, is_short):
"is_short": is_short, "is_short": is_short,
'max_rate': ANY, 'max_rate': ANY,
'min_rate': ANY, 'min_rate': ANY,
'open_order_id': 'dry_run_buy_short_12345' if is_short else 'dry_run_buy_long_12345', 'open_order_id': open_order_id,
'open_rate_requested': ANY, 'open_rate_requested': ANY,
'open_trade_value': 15.0911775 if is_short else 15.1668225, 'open_trade_value': open_trade_value,
'sell_reason': None, 'sell_reason': None,
'sell_order_status': None, 'sell_order_status': None,
'strategy': CURRENT_TEST_STRATEGY, 'strategy': CURRENT_TEST_STRATEGY,
@ -989,8 +1017,8 @@ def test_api_whitelist(botclient):
} }
@pytest.mark.parametrize('is_short', [True, False]) # TODO -lev: add test for forcebuy (short) when feature is supported
def test_api_forcebuy(botclient, mocker, fee, is_short): def test_api_forcebuy(botclient, mocker, fee):
ftbot, client = botclient ftbot, client = botclient
rc = client_post(client, f"{BASE_URI}/forcebuy", rc = client_post(client, f"{BASE_URI}/forcebuy",
@ -1019,7 +1047,7 @@ def test_api_forcebuy(botclient, mocker, fee, is_short):
open_order_id="123456", open_order_id="123456",
open_date=datetime.utcnow(), open_date=datetime.utcnow(),
is_open=False, is_open=False,
is_short=is_short, is_short=False,
fee_close=fee.return_value, fee_close=fee.return_value,
fee_open=fee.return_value, fee_open=fee.return_value,
close_rate=0.265441, close_rate=0.265441,
@ -1068,12 +1096,12 @@ def test_api_forcebuy(botclient, mocker, fee, is_short):
'fee_open_cost': None, 'fee_open_cost': None,
'fee_open_currency': None, 'fee_open_currency': None,
'is_open': False, 'is_open': False,
'is_short': is_short, 'is_short': False,
'max_rate': None, 'max_rate': None,
'min_rate': None, 'min_rate': None,
'open_order_id': '123456', 'open_order_id': '123456',
'open_rate_requested': None, 'open_rate_requested': None,
'open_trade_value': 0.2448274 if is_short else 0.24605460, 'open_trade_value': 0.24605460,
'sell_reason': None, 'sell_reason': None,
'sell_order_status': None, 'sell_order_status': None,
'strategy': CURRENT_TEST_STRATEGY, 'strategy': CURRENT_TEST_STRATEGY,

View File

@ -499,7 +499,7 @@ def test_telegram_stats(default_conf, update, ticker, ticker_sell_up, fee,
msg_mock.reset_mock() msg_mock.reset_mock()
# Create some test data # Create some test data
create_mock_trades(fee, is_short) create_mock_trades(fee, is_short=is_short)
telegram._stats(update=update, context=MagicMock()) telegram._stats(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
@ -1261,8 +1261,10 @@ def test_edge_enabled(edge_conf, update, mocker) -> None:
assert 'Winrate' not in msg_mock.call_args_list[0][0][0] assert 'Winrate' not in msg_mock.call_args_list[0][0][0]
@pytest.mark.parametrize('is_short', [True, False]) @pytest.mark.parametrize('is_short,regex_pattern',
def test_telegram_trades(mocker, update, default_conf, fee, is_short): [(True, r"just now[ ]*XRP\/BTC \(#3\) -1.00% \("),
(False, r"just now[ ]*XRP\/BTC \(#3\) 1.00% \(")])
def test_telegram_trades(mocker, update, default_conf, fee, is_short, regex_pattern):
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
@ -1280,7 +1282,7 @@ def test_telegram_trades(mocker, update, default_conf, fee, is_short):
assert "<pre>" not in msg_mock.call_args_list[0][0][0] assert "<pre>" not in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock() msg_mock.reset_mock()
create_mock_trades(fee, is_short) create_mock_trades(fee, is_short=is_short)
context = MagicMock() context = MagicMock()
context.args = [5] context.args = [5]
@ -1290,8 +1292,6 @@ def test_telegram_trades(mocker, update, default_conf, fee, is_short):
assert "Profit (" in msg_mock.call_args_list[0][0][0] assert "Profit (" in msg_mock.call_args_list[0][0][0]
assert "Close Date" in msg_mock.call_args_list[0][0][0] assert "Close Date" in msg_mock.call_args_list[0][0][0]
assert "<pre>" in msg_mock.call_args_list[0][0][0] assert "<pre>" in msg_mock.call_args_list[0][0][0]
regex_pattern = r"just now[ ]*XRP\/BTC \(#3\) -1.00% \(" if is_short else \
r"just now[ ]*XRP\/BTC \(#3\) 1.00% \("
assert bool(re.search(regex_pattern, msg_mock.call_args_list[0][0][0])) assert bool(re.search(regex_pattern, msg_mock.call_args_list[0][0][0]))
@ -1306,7 +1306,7 @@ def test_telegram_delete_trade(mocker, update, default_conf, fee, is_short):
assert "Trade-id not set." in msg_mock.call_args_list[0][0][0] assert "Trade-id not set." in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock() msg_mock.reset_mock()
create_mock_trades(fee, is_short) create_mock_trades(fee, is_short=is_short)
context = MagicMock() context = MagicMock()
context.args = [1] context.args = [1]