diff --git a/freqtrade/enums/maintenancemarginformula.py b/freqtrade/enums/maintenancemarginformula.py deleted file mode 100644 index 60e9d6bd5..000000000 --- a/freqtrade/enums/maintenancemarginformula.py +++ /dev/null @@ -1,26 +0,0 @@ -from enum import Enum -from freqtrade.exceptions import OperationalException - - -class MaintenanceMarginFormula(Enum): - """Equations to calculate maintenance margin""" - - BINANCE = "BINANCE" - FTX = "FTX" - KRAKEN = "KRAKEN" - - # TODO: Add arguments - def __call__(self): - if self.name == "BINANCE": - raise OperationalException("Cross margin not available on this exchange with freqtrade") - # TODO: return This formula - # https://www.binance.com/en/support/faq/f6b010588e55413aa58b7d63ee0125ed - elif self.name == "FTX": - # TODO: Implement - raise OperationalException("Cross margin not available on this exchange with freqtrade") - elif self.name == "KRAKEN": - # TODO: Implement - raise OperationalException("Cross margin not available on this exchange with freqtrade") - # https://support.kraken.com/hc/en-us/articles/203325763-Margin-Call-Level-and-Margin-Liquidation-Level - else: - raise OperationalException("Cross margin not available on this exchange with freqtrade") diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index fe984e408..01f7da19d 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -3,7 +3,8 @@ import logging from typing import Dict import ccxt -from freqtrade.enums import MaintenanceMarginFormula + +from freqtrade.enums import LiqFormula from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, OperationalException, TemporaryError) from freqtrade.exchange import Exchange @@ -24,7 +25,7 @@ class Binance(Exchange): "l2_limit_range": [5, 10, 20, 50, 100, 500, 1000], } - maintenance_margin_formula = MaintenanceMarginFormula.BINANCE + maintenance_margin_formula = LiqFormula.BINANCE def stoploss_adjust(self, stop_loss: float, order: Dict) -> bool: """ diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 5dcfca176..7979eac86 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -21,7 +21,7 @@ from pandas import DataFrame from freqtrade.constants import DEFAULT_AMOUNT_RESERVE_PERCENT, ListPairsWithTimeframes from freqtrade.data.converter import ohlcv_to_dataframe, trades_dict_to_list -from freqtrade.enums import MaintenanceMarginFormula +from freqtrade.enums import LiqFormula from freqtrade.exceptions import (DDosProtection, ExchangeError, InsufficientFundsError, InvalidOrderException, OperationalException, PricingError, RetryableOrderError, TemporaryError) @@ -69,7 +69,7 @@ class Exchange: "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) } _ft_has: Dict = {} - maintenance_margin_formula: MaintenanceMarginFormula + liq_formula: LiqFormula def __init__(self, config: Dict[str, Any], validate: bool = True) -> None: """ diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index dfac0c5d1..c1aa2bef2 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -4,7 +4,7 @@ from typing import Any, Dict import ccxt -from freqtrade.enums import MaintenanceMarginFormula +from freqtrade.enums import LiqFormula from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, OperationalException, TemporaryError) from freqtrade.exchange import Exchange @@ -22,7 +22,7 @@ class Ftx(Exchange): "ohlcv_candle_limit": 1500, } - maintenance_margin_formula = MaintenanceMarginFormula.FTX + maintenance_margin_formula = LiqFormula.FTX def market_is_tradable(self, market: Dict[str, Any]) -> bool: """ diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index a9063a0a7..833ea712d 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -4,7 +4,7 @@ from typing import Any, Dict import ccxt -from freqtrade.enums import MaintenanceMarginFormula +from freqtrade.enums import LiqFormula from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, OperationalException, TemporaryError) from freqtrade.exchange import Exchange @@ -24,7 +24,7 @@ class Kraken(Exchange): "trades_pagination_arg": "since", } - maintenance_margin_formula = MaintenanceMarginFormula.KRAKEN + maintenance_margin_formula = LiqFormula.KRAKEN def market_is_tradable(self, market: Dict[str, Any]) -> bool: """ diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 75dff6b31..4305fda91 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -105,8 +105,9 @@ class FreqtradeBot(LoggingMixin): # Start calculating maintenance margin if on cross margin # TODO: Add margin_mode to freqtrade.configuration? - if self.config.get('margin_mode') == "cross": - self.maintenance_margin = MaintenanceMargin(self.exchange.maintenance_margin_formula) + if self.config.get('leverage_type') == "cross" or \ + self.config.get('leverage_type') == "cross_futures": + self.maintenance_margin = MaintenanceMargin(self.exchange.liq_formula) self.maintenance_margin.run def notify_status(self, msg: str) -> None: diff --git a/freqtrade/maintenance_margin.py b/freqtrade/maintenance_margin.py index 68402e0b2..8fa5cf58a 100644 --- a/freqtrade/maintenance_margin.py +++ b/freqtrade/maintenance_margin.py @@ -1,11 +1,11 @@ -from freqtrade.enums import MaintenanceMarginFormula +from freqtrade.enums import LiqFormula from freqtrade.persistence import Trade class MaintenanceMargin: trades: list[Trade] - formula: MaintenanceMarginFormula + formula: LiqFormula @property def margin_level(self): @@ -15,7 +15,7 @@ class MaintenanceMargin: def liq_level(self): # This may be a constant value and may not need a function return - def __init__(self, formula: MaintenanceMarginFormula): + def __init__(self, formula: LiqFormula): return def add_new_trade(self, trade):