From 14c345f6f672fe72e52ab824309cc83b078d5706 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sun, 1 Aug 2021 21:08:52 -0600 Subject: [PATCH] added none to LiqFormula --- freqtrade/enums/liqformula.py | 9 +-- tests/leverage/test_liquidation_price.py | 78 +++++++++--------------- 2 files changed, 33 insertions(+), 54 deletions(-) diff --git a/freqtrade/enums/liqformula.py b/freqtrade/enums/liqformula.py index 95f9dba44..d65c5db38 100644 --- a/freqtrade/enums/liqformula.py +++ b/freqtrade/enums/liqformula.py @@ -3,16 +3,17 @@ from enum import Enum # from math import ceil from typing import Optional -from freqtrade.enums import TradingMode +from freqtrade.enums.tradingmode import TradingMode from freqtrade.exceptions import OperationalException class LiqFormula(Enum): """Equations to calculate liquidation price""" - BINANCE = "BINANCE" - KRAKEN = "KRAKEN" + BINANCE = "Binance" + KRAKEN = "Kraken" FTX = "FTX" + NONE = None def __exception(self, trading_mode: TradingMode, freq_specific: Optional[bool] = True): """ @@ -72,7 +73,7 @@ class LiqFormula(Enum): trading_mode: TradingMode = k['trading_mode'] - if trading_mode == TradingMode.SPOT: + if trading_mode == TradingMode.SPOT or self.name == "NONE": return None if self.name == "BINANCE": diff --git a/tests/leverage/test_liquidation_price.py b/tests/leverage/test_liquidation_price.py index afabeedbd..ba3005794 100644 --- a/tests/leverage/test_liquidation_price.py +++ b/tests/leverage/test_liquidation_price.py @@ -5,61 +5,39 @@ from freqtrade.enums import LiqFormula, TradingMode def test_liquidation_formula(): + spot = TradingMode.SPOT - # cross_margin = TradingMode.CROSS_MARGIN - # isolated_margin = TradingMode.ISOLATED_MARGIN - # cross_futures = TradingMode.CROSS_FUTURES - # isolated_futures = TradingMode.ISOLATED_FUTURES + cross_margin = TradingMode.CROSS_MARGIN + isolated_margin = TradingMode.ISOLATED_MARGIN + cross_futures = TradingMode.CROSS_FUTURES + isolated_futures = TradingMode.ISOLATED_FUTURES - assert LiqFormula.BINANCE( - trading_mode=spot - ) is None - # TODO-lev: Uncomment these assertions and make them real calculation tests - # assert LiqFormula.BINANCE( - # trading_mode=cross_margin - # ) == 1.0 #Replace 1.0 with real value - # assert LiqFormula.BINANCE( - # trading_mode=isolated_margin - # ) == 1.0 - # assert LiqFormula.BINANCE( - # trading_mode=cross_futures - # ) == 1.0 - # assert LiqFormula.BINANCE( - # trading_mode=isolated_futures - # ) == 1.0 + assert LiqFormula.NONE(trading_mode=spot) is None + assert LiqFormula.NONE(trading_mode=cross_margin) is None + assert LiqFormula.NONE(trading_mode=isolated_margin) is None + assert LiqFormula.NONE(trading_mode=cross_futures) is None + assert LiqFormula.NONE(trading_mode=isolated_futures) is None - assert LiqFormula.KRAKEN( - trading_mode=spot - ) is None + assert LiqFormula.BINANCE(trading_mode=spot) is None # TODO-lev: Uncomment these assertions and make them real calculation tests - # assert LiqFormula.KRAKEN( - # trading_mode=cross_margin - # ) == 1.0 - # LiqFormula.KRAKEN( - # trading_mode=isolated_margin - # ) + # TODO-lev: Replace 1.0 with real value + # assert LiqFormula.BINANCE(trading_mode=cross_margin) == 1.0 + # assert LiqFormula.BINANCE(trading_mode=isolated_margin) == 1.0 + # assert LiqFormula.BINANCE(trading_mode=cross_futures) == 1.0 + # assert LiqFormula.BINANCE(trading_mode=isolated_futures) == 1.0 + + assert LiqFormula.KRAKEN(trading_mode=spot) is None + # TODO-lev: Uncomment these assertions and make them real calculation tests + # assert LiqFormula.KRAKEN(trading_mode=cross_margin) == 1.0 + # LiqFormula.KRAKEN(trading_mode=isolated_margin) # asset exception thrown #TODO-lev: Check that exception is thrown - # assert LiqFormula.KRAKEN( - # trading_mode=cross_futures - # ) == 1.0 - # LiqFormula.KRAKEN( - # trading_mode=isolated_futures - # ) + # assert LiqFormula.KRAKEN(trading_mode=cross_futures) == 1.0 + # LiqFormula.KRAKEN(trading_mode=isolated_futures) # asset exception thrown #TODO-lev: Check that exception is thrown - assert LiqFormula.FTX( - trading_mode=spot - ) is None + assert LiqFormula.FTX(trading_mode=spot) is None # TODO-lev: Uncomment these assertions and make them real calculation tests - # assert LiqFormula.FTX( - # trading_mode=cross_margin - # ) == 1.0 - # assert LiqFormula.FTX( - # trading_mode=isolated_margin - # ) == 1.0 - # assert LiqFormula.FTX( - # trading_mode=cross_futures - # ) == 1.0 - # assert LiqFormula.FTX( - # trading_mode=isolated_futures - # ) == 1.0 + # assert LiqFormula.FTX(trading_mode=cross_margin) == 1.0 + # assert LiqFormula.FTX(trading_mode=isolated_margin) == 1.0 + # assert LiqFormula.FTX(trading_mode=cross_futures) == 1.0 + # assert LiqFormula.FTX(trading_mode=isolated_futures) == 1.0