From 3e04e243b48be50dac57cc0fae54554394452eab Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 4 Aug 2021 04:51:30 -0600 Subject: [PATCH] Fixed errors with tradinng_mode types --- freqtrade/exchange/exchange.py | 1 - freqtrade/exchange/ftx.py | 2 +- freqtrade/freqtradebot.py | 31 ++++++++++++++----------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 3e726a9e1..6c91a3e9f 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -69,7 +69,6 @@ class Exchange: "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) } _ft_has: Dict = {} - liq_formula: LiqFormula interest_mode: InterestMode = InterestMode.NONE liq_formula: LiqFormula = LiqFormula.NONE diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index 50ea28079..d4bb9ce0b 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -22,7 +22,7 @@ class Ftx(Exchange): "stoploss_on_exchange": True, "ohlcv_candle_limit": 1500, } - #interest_mode: InterestMode = InterestMode.HOURSPERDAY + # interest_mode: InterestMode = InterestMode.HOURSPERDAY liq_formula: LiqFormula = LiqFormula.FTX def market_is_tradable(self, market: Dict[str, Any]) -> bool: diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 01fb729b2..be29cd355 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -16,7 +16,7 @@ from freqtrade.configuration import validate_config_consistency from freqtrade.data.converter import order_book_to_dataframe from freqtrade.data.dataprovider import DataProvider from freqtrade.edge import Edge -from freqtrade.enums import RPCMessageType, SellType, State, TradingMode +from freqtrade.enums import Collateral, RPCMessageType, SellType, State, TradingMode from freqtrade.exceptions import (DependencyException, ExchangeError, InsufficientFundsError, InvalidOrderException, PricingError) from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds @@ -42,6 +42,9 @@ class FreqtradeBot(LoggingMixin): This is from here the bot start its logic. """ + trading_mode: TradingMode = TradingMode.SPOT + collateral_type: Optional[Collateral] = None + def __init__(self, config: Dict[str, Any]) -> None: """ Init all variables and objects the bot needs to work @@ -105,21 +108,17 @@ class FreqtradeBot(LoggingMixin): self._exit_lock = Lock() LoggingMixin.__init__(self, logger, timeframe_to_seconds(self.strategy.timeframe)) - if self.config.get('trading_mode') == "cross_margin": - self.trading_mode = TradingMode.CROSS_MARGIN - elif self.config.get('trading_mode') == "isolated_margin": - self.trading_mode = TradingMode.ISOLATED_MARGIN - elif self.config.get('trading_mode') == "cross_futures": - self.trading_mode = TradingMode.CROSS_FUTURES - elif self.config.get('trading_mode') == "isolated_futures": - self.trading_mode = TradingMode.ISOLATED_FUTURES - else: - self.trading_mode = TradingMode.SPOT + trading_mode = self.config.get('trading_mode') + collateral_type = self.config.get('collateral_type') + if trading_mode: + self.trading_mode = TradingMode(trading_mode) + + if collateral_type: + self.collateral_type = Collateral(collateral_type) # Start calculating maintenance margin if on cross margin # TODO: Add margin_mode to freqtrade.configuration? - if self.trading_mode == TradingMode.CROSS_MARGIN or \ - self.trading_mode == TradingMode.CROSS_FUTURES: + if self.collateral_type == Collateral.CROSS: self.maintenance_margin = MaintenanceMargin( liq_formula=self.exchange.liq_formula, @@ -551,8 +550,7 @@ class FreqtradeBot(LoggingMixin): is_short=is_short ) - if self.trading_mode == TradingMode.ISOLATED_MARGIN or \ - self.trading_mode == TradingMode.ISOLATED_FUTURES: + if self.collateral_type == Collateral.ISOLATED: isolated_liq = self.exchange.liq_formula( trading_mode=self.trading_mode, @@ -562,8 +560,7 @@ class FreqtradeBot(LoggingMixin): is_short=is_short ) - if self.trading_mode == TradingMode.CROSS_FUTURES or \ - self.trading_mode == TradingMode.ISOLATED_FUTURES: + if self.trading_mode == TradingMode.FUTURES: self.exchange.set_leverage(pair=pair, leverage=leverage) return interest_rate, isolated_liq