Merge pull request #6790 from eSeR1805/profit_reporting
Report profit only on filled entries.
This commit is contained in:
commit
ab91758c7e
@ -177,6 +177,7 @@ class RPC:
|
|||||||
current_rate = NAN
|
current_rate = NAN
|
||||||
else:
|
else:
|
||||||
current_rate = trade.close_rate
|
current_rate = trade.close_rate
|
||||||
|
if len(trade.select_filled_orders(trade.entry_side)) > 0:
|
||||||
current_profit = trade.calc_profit_ratio(current_rate)
|
current_profit = trade.calc_profit_ratio(current_rate)
|
||||||
current_profit_abs = trade.calc_profit(current_rate)
|
current_profit_abs = trade.calc_profit(current_rate)
|
||||||
current_profit_fiat: Optional[float] = None
|
current_profit_fiat: Optional[float] = None
|
||||||
@ -187,6 +188,8 @@ class RPC:
|
|||||||
self._freqtrade.config['stake_currency'],
|
self._freqtrade.config['stake_currency'],
|
||||||
self._freqtrade.config['fiat_display_currency']
|
self._freqtrade.config['fiat_display_currency']
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
current_profit = current_profit_abs = current_profit_fiat = 0.0
|
||||||
|
|
||||||
# Calculate guaranteed profit (in case of trailing stop)
|
# Calculate guaranteed profit (in case of trailing stop)
|
||||||
stoploss_entry_dist = trade.calc_profit(trade.stop_loss)
|
stoploss_entry_dist = trade.calc_profit(trade.stop_loss)
|
||||||
@ -235,8 +238,12 @@ class RPC:
|
|||||||
trade.pair, side='exit', is_short=trade.is_short, refresh=False)
|
trade.pair, side='exit', is_short=trade.is_short, refresh=False)
|
||||||
except (PricingError, ExchangeError):
|
except (PricingError, ExchangeError):
|
||||||
current_rate = NAN
|
current_rate = NAN
|
||||||
|
if len(trade.select_filled_orders(trade.entry_side)) > 0:
|
||||||
trade_profit = trade.calc_profit(current_rate)
|
trade_profit = trade.calc_profit(current_rate)
|
||||||
profit_str = f'{trade.calc_profit_ratio(current_rate):.2%}'
|
profit_str = f'{trade.calc_profit_ratio(current_rate):.2%}'
|
||||||
|
else:
|
||||||
|
trade_profit = 0.0
|
||||||
|
profit_str = f'{0.0:.2f}'
|
||||||
direction_str = ('S' if trade.is_short else 'L') if nonspot else ''
|
direction_str = ('S' if trade.is_short else 'L') if nonspot else ''
|
||||||
if self._fiat_converter:
|
if self._fiat_converter:
|
||||||
fiat_profit = self._fiat_converter.convert_amount(
|
fiat_profit = self._fiat_converter.convert_amount(
|
||||||
@ -244,7 +251,7 @@ class RPC:
|
|||||||
stake_currency,
|
stake_currency,
|
||||||
fiat_display_currency
|
fiat_display_currency
|
||||||
)
|
)
|
||||||
if fiat_profit and not isnan(fiat_profit):
|
if not isnan(fiat_profit):
|
||||||
profit_str += f" ({fiat_profit:.2f})"
|
profit_str += f" ({fiat_profit:.2f})"
|
||||||
fiat_profit_sum = fiat_profit if isnan(fiat_profit_sum) \
|
fiat_profit_sum = fiat_profit if isnan(fiat_profit_sum) \
|
||||||
else fiat_profit_sum + fiat_profit
|
else fiat_profit_sum + fiat_profit
|
||||||
|
@ -233,9 +233,20 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||||||
freqtradebot.state = State.RUNNING
|
freqtradebot.state = State.RUNNING
|
||||||
with pytest.raises(RPCException, match=r'.*no active trade*'):
|
with pytest.raises(RPCException, match=r'.*no active trade*'):
|
||||||
rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=False)
|
||||||
freqtradebot.enter_positions()
|
freqtradebot.enter_positions()
|
||||||
|
|
||||||
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
|
assert "Since" in headers
|
||||||
|
assert "Pair" in headers
|
||||||
|
assert 'instantly' == result[0][2]
|
||||||
|
assert 'ETH/BTC' in result[0][1]
|
||||||
|
assert '0.00' == result[0][3]
|
||||||
|
assert isnan(fiat_profit_sum)
|
||||||
|
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange._is_dry_limit_order_filled', return_value=True)
|
||||||
|
freqtradebot.process()
|
||||||
|
|
||||||
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
assert "Since" in headers
|
assert "Since" in headers
|
||||||
assert "Pair" in headers
|
assert "Pair" in headers
|
||||||
@ -243,8 +254,8 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||||||
assert 'ETH/BTC' in result[0][1]
|
assert 'ETH/BTC' in result[0][1]
|
||||||
assert '-0.41%' == result[0][3]
|
assert '-0.41%' == result[0][3]
|
||||||
assert isnan(fiat_profit_sum)
|
assert isnan(fiat_profit_sum)
|
||||||
# Test with fiatconvert
|
|
||||||
|
|
||||||
|
# Test with fiatconvert
|
||||||
rpc._fiat_converter = CryptoToFiatConverter()
|
rpc._fiat_converter = CryptoToFiatConverter()
|
||||||
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
assert "Since" in headers
|
assert "Since" in headers
|
||||||
|
Loading…
Reference in New Issue
Block a user