Changed leverage mode formula to trading mode

This commit is contained in:
Sam Germain 2021-08-01 16:19:59 -06:00
parent 5312d044a0
commit 03aa99c5a2
3 changed files with 33 additions and 31 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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"