more calc_profit_combined usage

This commit is contained in:
Matthias
2023-08-29 21:29:36 +02:00
parent 459b9d80d4
commit 399f144c27
2 changed files with 17 additions and 13 deletions

View File

@@ -174,6 +174,8 @@ class RPC:
order: Optional[Order] = None order: Optional[Order] = None
current_profit_fiat: Optional[float] = None current_profit_fiat: Optional[float] = None
total_profit_fiat: Optional[float] = None total_profit_fiat: Optional[float] = None
total_profit_abs = 0.0
total_profit_ratio: Optional[float] = None
if trade.open_order_id: if trade.open_order_id:
order = trade.select_order_by_order_id(trade.open_order_id) order = trade.select_order_by_order_id(trade.open_order_id)
# calculate profit and send message to user # calculate profit and send message to user
@@ -184,23 +186,22 @@ class RPC:
except (ExchangeError, PricingError): except (ExchangeError, PricingError):
current_rate = NAN current_rate = NAN
if len(trade.select_filled_orders(trade.entry_side)) > 0: if len(trade.select_filled_orders(trade.entry_side)) > 0:
current_profit = trade.calc_profit_ratio(
current_rate) if not isnan(current_rate) else NAN current_profit = current_profit_abs = current_profit_fiat = NAN
current_profit_abs = trade.calc_profit( if not isnan(current_rate):
current_rate) if not isnan(current_rate) else NAN prof = trade.calc_profit_combined(current_rate)
current_profit = prof.profit_ratio
current_profit_abs = prof.profit_abs
total_profit_abs = prof.total_profit
total_profit_ratio = prof.total_profit_ratio
else: else:
current_profit = current_profit_abs = current_profit_fiat = 0.0 current_profit = current_profit_abs = current_profit_fiat = 0.0
else: else:
# Closed trade ... # Closed trade ...
current_rate = trade.close_rate current_rate = trade.close_rate
current_profit = trade.close_profit or 0.0 current_profit = trade.close_profit or 0.0
current_profit_abs = trade.close_profit_abs or 0.0 current_profit_abs = trade.close_profit_abs or 0.0
total_profit_abs = trade.realized_profit + current_profit_abs
total_profit_ratio: Optional[float] = None
if trade.max_stake_amount:
total_profit_ratio = (
(total_profit_abs / trade.max_stake_amount) * trade.leverage
)
# Calculate fiat profit # Calculate fiat profit
if not isnan(current_profit_abs) and self._fiat_converter: if not isnan(current_profit_abs) and self._fiat_converter:
@@ -216,8 +217,11 @@ class RPC:
) )
# 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) stop_entry = trade.calc_profit_combined(trade.stop_loss)
stoploss_entry_dist_ratio = trade.calc_profit_ratio(trade.stop_loss)
stoploss_entry_dist = stop_entry.profit_abs
stoploss_entry_dist_ratio = stop_entry.profit_ratio
# calculate distance to stoploss # calculate distance to stoploss
stoploss_current_dist = trade.stop_loss - current_rate stoploss_current_dist = trade.stop_loss - current_rate
stoploss_current_dist_ratio = stoploss_current_dist / current_rate stoploss_current_dist_ratio = stoploss_current_dist / current_rate

View File

@@ -164,7 +164,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
response = deepcopy(gen_response) response = deepcopy(gen_response)
response.update({ response.update({
'max_stake_amount': 0.001, 'max_stake_amount': 0.001,
'total_profit_ratio': pytest.approx(-0.00409), 'total_profit_ratio': pytest.approx(-0.00409153),
}) })
assert results[0] == response assert results[0] == response