refactor: move exception handler into helper function
This commit is contained in:
@@ -2233,16 +2233,13 @@ 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,
|
||||
wallets=self.wallets,
|
||||
stake_currency=self.config["stake_currency"],
|
||||
dry_run=self.config["dry_run"],
|
||||
)
|
||||
except DependencyException:
|
||||
logger.warning("Unable to calculate liquidation price")
|
||||
update_liquidation_prices(
|
||||
trade,
|
||||
exchange=self.exchange,
|
||||
wallets=self.wallets,
|
||||
stake_currency=self.config["stake_currency"],
|
||||
dry_run=self.config["dry_run"],
|
||||
)
|
||||
if self.strategy.use_custom_stoploss:
|
||||
current_rate = self.exchange.get_rate(
|
||||
trade.pair, side="exit", is_short=trade.is_short, refresh=True
|
||||
|
||||
@@ -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,37 +22,40 @@ def update_liquidation_prices(
|
||||
Update trade liquidation price in isolated margin mode.
|
||||
Updates liquidation price for all trades in cross margin mode.
|
||||
"""
|
||||
if exchange.margin_mode == MarginMode.CROSS:
|
||||
total_wallet_stake = 0.0
|
||||
if dry_run:
|
||||
# Parameters only needed for cross margin
|
||||
total_wallet_stake = wallets.get_total(stake_currency)
|
||||
try:
|
||||
if exchange.margin_mode == MarginMode.CROSS:
|
||||
total_wallet_stake = 0.0
|
||||
if dry_run:
|
||||
# Parameters only needed for cross margin
|
||||
total_wallet_stake = wallets.get_total(stake_currency)
|
||||
|
||||
logger.info("Updating liquidation price for all open trades.")
|
||||
for t in Trade.get_open_trades():
|
||||
# TODO: This should be done in a batch update
|
||||
t.set_liquidation_price(
|
||||
logger.info("Updating liquidation price for all open trades.")
|
||||
for t in Trade.get_open_trades():
|
||||
# TODO: This should be done in a batch update
|
||||
t.set_liquidation_price(
|
||||
exchange.get_liquidation_price(
|
||||
pair=t.pair,
|
||||
open_rate=t.open_rate,
|
||||
is_short=t.is_short,
|
||||
amount=t.amount,
|
||||
stake_amount=t.stake_amount,
|
||||
leverage=trade.leverage,
|
||||
wallet_balance=total_wallet_stake,
|
||||
other_trades=[], # TODO: Add other trades
|
||||
)
|
||||
)
|
||||
else:
|
||||
trade.set_liquidation_price(
|
||||
exchange.get_liquidation_price(
|
||||
pair=t.pair,
|
||||
open_rate=t.open_rate,
|
||||
is_short=t.is_short,
|
||||
amount=t.amount,
|
||||
stake_amount=t.stake_amount,
|
||||
pair=trade.pair,
|
||||
open_rate=trade.open_rate,
|
||||
is_short=trade.is_short,
|
||||
amount=trade.amount,
|
||||
stake_amount=trade.stake_amount,
|
||||
leverage=trade.leverage,
|
||||
wallet_balance=total_wallet_stake,
|
||||
other_trades=[], # TODO: Add other trades
|
||||
wallet_balance=trade.stake_amount,
|
||||
other_trades=[],
|
||||
)
|
||||
)
|
||||
else:
|
||||
trade.set_liquidation_price(
|
||||
exchange.get_liquidation_price(
|
||||
pair=trade.pair,
|
||||
open_rate=trade.open_rate,
|
||||
is_short=trade.is_short,
|
||||
amount=trade.amount,
|
||||
stake_amount=trade.stake_amount,
|
||||
leverage=trade.leverage,
|
||||
wallet_balance=trade.stake_amount,
|
||||
other_trades=[],
|
||||
)
|
||||
)
|
||||
except DependencyException:
|
||||
logger.warning("Unable to calculate liquidation price")
|
||||
|
||||
Reference in New Issue
Block a user