adding sides for rate and 1 more test case

This commit is contained in:
aezo.teo 2021-11-14 17:37:31 +08:00
parent 8df334515f
commit 92997c85f9
2 changed files with 13 additions and 12 deletions

View File

@ -156,8 +156,9 @@ class RPC:
# calculate profit and send message to user
if trade.is_open:
try:
closing_side = "buy" if trade.is_short else "sell"
current_rate = self._freqtrade.exchange.get_rate(
trade.pair, refresh=False, side="sell")
trade.pair, refresh=False, side=closing_side)
except (ExchangeError, PricingError):
current_rate = NAN
else:
@ -216,8 +217,9 @@ class RPC:
for trade in trades:
# calculate profit and send message to user
try:
closing_side = "buy" if trade.is_short else "sell"
current_rate = self._freqtrade.exchange.get_rate(
trade.pair, refresh=False, side="sell")
trade.pair, refresh=False, side=closing_side)
except (PricingError, ExchangeError):
current_rate = NAN
trade_percent = (100 * trade.calc_profit_ratio(current_rate))
@ -578,8 +580,9 @@ class RPC:
if not fully_canceled:
# Get current rate and execute sell
closing_side = "buy" if trade.is_short else "sell"
current_rate = self._freqtrade.exchange.get_rate(
trade.pair, refresh=False, side="sell")
trade.pair, refresh=False, side=closing_side)
sell_reason = SellCheckTuple(sell_type=SellType.FORCE_SELL)
self._freqtrade.execute_trade_exit(trade, current_rate, sell_reason)
# ---- EOF def _exec_forcesell ----

View File

@ -829,11 +829,8 @@ def test_api_performance(botclient, fee):
'profit_ratio': -0.05570419, 'profit_abs': -0.1150375}]
# TODO-lev: @pytest.mark.parametrize('is_short,side', [
# (True, "short"),
# (False, "long")
# ])
def test_api_status(botclient, mocker, ticker, fee, markets):
@pytest.mark.parametrize('is_short', [True, False])
def test_api_status(botclient, mocker, ticker, fee, markets, is_short):
ftbot, client = botclient
patch_get_signal(ftbot)
mocker.patch.multiple(
@ -848,7 +845,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
rc = client_get(client, f"{BASE_URI}/status")
assert_response(rc, 200)
assert rc.json() == []
create_mock_trades(fee, False)
create_mock_trades(fee, is_short)
rc = client_get(client, f"{BASE_URI}/status")
assert_response(rc)
@ -869,7 +866,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'profit_pct': ANY,
'profit_abs': ANY,
'profit_fiat': ANY,
'current_rate': 1.099e-05,
'current_rate': 1.098e-05 if is_short else 1.099e-05,
'open_date': ANY,
'open_timestamp': ANY,
'open_order': None,
@ -899,11 +896,12 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'fee_open_cost': None,
'fee_open_currency': None,
'is_open': True,
"is_short": is_short,
'max_rate': ANY,
'min_rate': ANY,
'open_order_id': 'dry_run_buy_long_12345',
'open_order_id': 'dry_run_buy_short_12345' if is_short else 'dry_run_buy_long_12345',
'open_rate_requested': ANY,
'open_trade_value': 15.1668225,
'open_trade_value': 15.0911775 if is_short else 15.1668225,
'sell_reason': None,
'sell_order_status': None,
'strategy': CURRENT_TEST_STRATEGY,