From 03aa99c5a2fa08a2ddcd271232a9b7aca1f2c640 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sun, 1 Aug 2021 16:19:59 -0600 Subject: [PATCH] Changed leverage mode formula to trading mode --- freqtrade/enums/leveragemode.py | 11 --------- freqtrade/enums/liqformula.py | 40 ++++++++++++++++----------------- freqtrade/enums/tradingmode.py | 13 +++++++++++ 3 files changed, 33 insertions(+), 31 deletions(-) delete mode 100644 freqtrade/enums/leveragemode.py create mode 100644 freqtrade/enums/tradingmode.py diff --git a/freqtrade/enums/leveragemode.py b/freqtrade/enums/leveragemode.py deleted file mode 100644 index c77251c0d..000000000 --- a/freqtrade/enums/leveragemode.py +++ /dev/null @@ -1,11 +0,0 @@ -from enum import Enum - - -class LeverageMode(Enum): - """ - Enum to distinguish between cross margin, isolated margin, and futures - """ - CROSS = "cross" - ISOLATED = "isolated" - CROSS_FUTURES = "cross_futures" - ISOLATED_FUTURES = "cross_futures" diff --git a/freqtrade/enums/liqformula.py b/freqtrade/enums/liqformula.py index fb55bf8d3..e7892d7ed 100644 --- a/freqtrade/enums/liqformula.py +++ b/freqtrade/enums/liqformula.py @@ -3,7 +3,7 @@ from enum import Enum # from math import ceil from typing import Optional -from freqtrade.enums import LeverageMode +from freqtrade.enums import TradingMode from freqtrade.exceptions import OperationalException @@ -14,59 +14,59 @@ class LiqFormula(Enum): KRAKEN = "KRAKEN" FTX = "FTX" - def __exception(self, leverage_mode: LeverageMode, freq_specific: Optional[bool] = True): + def __exception(self, trading_mode: TradingMode, freq_specific: Optional[bool] = True): """ Raises an exception if exchange used doesn't support desired leverage mode - :param leverage_mode: cross, isolated, cross_futures or isolated_futures + :param trading_mode: cross, isolated, cross_futures or isolated_futures :param freq_specific: False if the exchange does not support this leverage mode True if only freqtrade doesn't support it """ if freq_specific: raise OperationalException( - f"Freqtrade does not support {leverage_mode.value} on {self.name}") + f"Freqtrade does not support {trading_mode.value} on {self.name}") else: - raise OperationalException(f"{self.name} does not support {leverage_mode.value}") + raise OperationalException(f"{self.name} does not support {trading_mode.value}") def __call__(self, **k): - leverage_mode: LeverageMode = k.leverage_mode + trading_mode: TradingMode = k.trading_mode # * Cross Margin - if leverage_mode == LeverageMode.CROSS: + if trading_mode == TradingMode.CROSS: if self.name == "BINANCE": # TODO: perform a calculation based on this formula # https://www.binance.com/en/support/faq/f6b010588e55413aa58b7d63ee0125ed - self.__exception(leverage_mode) + self.__exception(trading_mode) elif self.name == "KRAKEN": # TODO: perform a calculation based on this formula # https://support.kraken.com/hc/en-us/articles/203325763-Margin-Call-Level-and-Margin-Liquidation-Level - self.__exception(leverage_mode) + self.__exception(trading_mode) elif self.name == "FTX": - self.__exception(leverage_mode) + self.__exception(trading_mode) # * Isolated Margin - elif leverage_mode == LeverageMode.ISOLATED: + elif trading_mode == TradingMode.ISOLATED: if self.name == "KRAKEN": # Kraken doesn't have isolated margin - self.__exception(leverage_mode, False) + self.__exception(trading_mode, False) else: - self.__exception(leverage_mode) + self.__exception(trading_mode) # * Cross Futures - elif leverage_mode == LeverageMode.CROSS_FUTURES: + elif trading_mode == TradingMode.CROSS_FUTURES: if self.name == "BINANCE": # TODO: perform a calculation based on this formula # https://www.binance.com/en/support/faq/b3c689c1f50a44cabb3a84e663b81d93 - self.__exception(leverage_mode) + self.__exception(trading_mode) else: - self.__exception(leverage_mode) + self.__exception(trading_mode) # * Isolated Futures - elif leverage_mode == LeverageMode.ISOLATED_FUTURES: + elif trading_mode == TradingMode.ISOLATED_FUTURES: if self.name == "BINANCE": # TODO: perform a calculation based on this formula # https://www.binance.com/en/support/faq/b3c689c1f50a44cabb3a84e663b81d93 - self.__exception(leverage_mode) + self.__exception(trading_mode) elif self.name == "KRAKEN": # Kraken doesn't have isolated margin - self.__exception(leverage_mode, False) + self.__exception(trading_mode, False) else: - self.__exception(leverage_mode) + self.__exception(trading_mode) diff --git a/freqtrade/enums/tradingmode.py b/freqtrade/enums/tradingmode.py new file mode 100644 index 000000000..d8d1fec00 --- /dev/null +++ b/freqtrade/enums/tradingmode.py @@ -0,0 +1,13 @@ +from enum import Enum + + +class TradingMode(Enum): + """ + Enum to distinguish between + spot, cross margin, isolated margin, futures or any other trading method + """ + SPOT = "spot" + CROSS_MARGIN = "cross margin" + ISOLATED_MARGIN = "isolated margin" + CROSS_FUTURES = "cross futures" + ISOLATED_FUTURES = "isolated futures"