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
|
# Must also run for partial exits
|
||||||
# TODO: Margin will need to use interest_rate as well.
|
# TODO: Margin will need to use interest_rate as well.
|
||||||
# interest_rate = self.exchange.get_interest_rate()
|
# interest_rate = self.exchange.get_interest_rate()
|
||||||
try:
|
update_liquidation_prices(
|
||||||
update_liquidation_prices(
|
trade,
|
||||||
trade,
|
exchange=self.exchange,
|
||||||
exchange=self.exchange,
|
wallets=self.wallets,
|
||||||
wallets=self.wallets,
|
stake_currency=self.config["stake_currency"],
|
||||||
stake_currency=self.config["stake_currency"],
|
dry_run=self.config["dry_run"],
|
||||||
dry_run=self.config["dry_run"],
|
)
|
||||||
)
|
|
||||||
except DependencyException:
|
|
||||||
logger.warning("Unable to calculate liquidation price")
|
|
||||||
if self.strategy.use_custom_stoploss:
|
if self.strategy.use_custom_stoploss:
|
||||||
current_rate = self.exchange.get_rate(
|
current_rate = self.exchange.get_rate(
|
||||||
trade.pair, side="exit", is_short=trade.is_short, refresh=True
|
trade.pair, side="exit", is_short=trade.is_short, refresh=True
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from freqtrade.enums import MarginMode
|
from freqtrade.enums import MarginMode
|
||||||
|
from freqtrade.exceptions import DependencyException
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.persistence import LocalTrade, Trade
|
from freqtrade.persistence import LocalTrade, Trade
|
||||||
from freqtrade.wallets import Wallets
|
from freqtrade.wallets import Wallets
|
||||||
@@ -21,37 +22,40 @@ def update_liquidation_prices(
|
|||||||
Update trade liquidation price in isolated margin mode.
|
Update trade liquidation price in isolated margin mode.
|
||||||
Updates liquidation price for all trades in cross margin mode.
|
Updates liquidation price for all trades in cross margin mode.
|
||||||
"""
|
"""
|
||||||
if exchange.margin_mode == MarginMode.CROSS:
|
try:
|
||||||
total_wallet_stake = 0.0
|
if exchange.margin_mode == MarginMode.CROSS:
|
||||||
if dry_run:
|
total_wallet_stake = 0.0
|
||||||
# Parameters only needed for cross margin
|
if dry_run:
|
||||||
total_wallet_stake = wallets.get_total(stake_currency)
|
# Parameters only needed for cross margin
|
||||||
|
total_wallet_stake = wallets.get_total(stake_currency)
|
||||||
|
|
||||||
logger.info("Updating liquidation price for all open trades.")
|
logger.info("Updating liquidation price for all open trades.")
|
||||||
for t in Trade.get_open_trades():
|
for t in Trade.get_open_trades():
|
||||||
# TODO: This should be done in a batch update
|
# TODO: This should be done in a batch update
|
||||||
t.set_liquidation_price(
|
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(
|
exchange.get_liquidation_price(
|
||||||
pair=t.pair,
|
pair=trade.pair,
|
||||||
open_rate=t.open_rate,
|
open_rate=trade.open_rate,
|
||||||
is_short=t.is_short,
|
is_short=trade.is_short,
|
||||||
amount=t.amount,
|
amount=trade.amount,
|
||||||
stake_amount=t.stake_amount,
|
stake_amount=trade.stake_amount,
|
||||||
leverage=trade.leverage,
|
leverage=trade.leverage,
|
||||||
wallet_balance=total_wallet_stake,
|
wallet_balance=trade.stake_amount,
|
||||||
other_trades=[], # TODO: Add other trades
|
other_trades=[],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
except DependencyException:
|
||||||
trade.set_liquidation_price(
|
logger.warning("Unable to calculate 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=[],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user