refactor: move exception handler into helper function

This commit is contained in:
Matthias
2024-08-30 07:07:22 +02:00
parent 0c0bb29f83
commit c316d27444
2 changed files with 40 additions and 39 deletions
-3
View File
@@ -2233,7 +2233,6 @@ class FreqtradeBot(LoggingMixin):
# Must also run for partial exits
# TODO: Margin will need to use interest_rate as well.
# interest_rate = self.exchange.get_interest_rate()
try:
update_liquidation_prices(
trade,
exchange=self.exchange,
@@ -2241,8 +2240,6 @@ class FreqtradeBot(LoggingMixin):
stake_currency=self.config["stake_currency"],
dry_run=self.config["dry_run"],
)
except DependencyException:
logger.warning("Unable to calculate liquidation price")
if self.strategy.use_custom_stoploss:
current_rate = self.exchange.get_rate(
trade.pair, side="exit", is_short=trade.is_short, refresh=True
+4
View File
@@ -1,6 +1,7 @@
import logging
from freqtrade.enums import MarginMode
from freqtrade.exceptions import DependencyException
from freqtrade.exchange import Exchange
from freqtrade.persistence import LocalTrade, Trade
from freqtrade.wallets import Wallets
@@ -21,6 +22,7 @@ def update_liquidation_prices(
Update trade liquidation price in isolated margin mode.
Updates liquidation price for all trades in cross margin mode.
"""
try:
if exchange.margin_mode == MarginMode.CROSS:
total_wallet_stake = 0.0
if dry_run:
@@ -55,3 +57,5 @@ def update_liquidation_prices(
other_trades=[],
)
)
except DependencyException:
logger.warning("Unable to calculate liquidation price")