mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
Simplify profit calculation (removes unnecessary fallback)
This commit is contained in:
@@ -924,15 +924,14 @@ class LocalTrade:
|
||||
|
||||
short_close_zero = (self.is_short and close_trade_value == 0.0)
|
||||
long_close_zero = (not self.is_short and open_trade_value == 0.0)
|
||||
leverage = self.leverage or 1.0
|
||||
|
||||
if (short_close_zero or long_close_zero):
|
||||
return 0.0
|
||||
else:
|
||||
if self.is_short:
|
||||
profit_ratio = (1 - (close_trade_value / open_trade_value)) * leverage
|
||||
profit_ratio = (1 - (close_trade_value / open_trade_value)) * self.leverage
|
||||
else:
|
||||
profit_ratio = ((close_trade_value / open_trade_value) - 1) * leverage
|
||||
profit_ratio = ((close_trade_value / open_trade_value) - 1) * self.leverage
|
||||
|
||||
return float(f"{profit_ratio:.8f}")
|
||||
|
||||
|
||||
@@ -986,7 +986,7 @@ def test_api_performance(botclient, fee):
|
||||
fee_close=fee.return_value,
|
||||
fee_open=fee.return_value,
|
||||
close_rate=0.265441,
|
||||
|
||||
leverage=1.0,
|
||||
)
|
||||
trade.close_profit = trade.calc_profit_ratio(trade.close_rate)
|
||||
trade.close_profit_abs = trade.calc_profit(trade.close_rate)
|
||||
@@ -1002,7 +1002,8 @@ def test_api_performance(botclient, fee):
|
||||
is_open=False,
|
||||
fee_close=fee.return_value,
|
||||
fee_open=fee.return_value,
|
||||
close_rate=0.391
|
||||
close_rate=0.391,
|
||||
leverage=1.0,
|
||||
)
|
||||
trade.close_profit = trade.calc_profit_ratio(trade.close_rate)
|
||||
trade.close_profit_abs = trade.calc_profit(trade.close_rate)
|
||||
|
||||
@@ -503,6 +503,7 @@ def test_custom_exit(default_conf, fee, caplog) -> None:
|
||||
fee_close=fee.return_value,
|
||||
exchange='binance',
|
||||
open_rate=1,
|
||||
leverage=1.0,
|
||||
)
|
||||
|
||||
now = dt_now()
|
||||
@@ -552,6 +553,7 @@ def test_should_sell(default_conf, fee) -> None:
|
||||
fee_close=fee.return_value,
|
||||
exchange='binance',
|
||||
open_rate=1,
|
||||
leverage=1.0,
|
||||
)
|
||||
now = dt_now()
|
||||
res = strategy.should_exit(trade, 1, now,
|
||||
|
||||
@@ -3458,6 +3458,7 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None:
|
||||
close_date=dt_now(),
|
||||
exit_reason="sell_reason_whatever",
|
||||
stake_amount=0.245441 * 2,
|
||||
leverage=1,
|
||||
)
|
||||
trade.orders = [
|
||||
Order(
|
||||
|
||||
Reference in New Issue
Block a user