From 8638e6fe47dc847a95b31350401d59ccc078eb23 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 18 Nov 2021 19:56:59 +0100 Subject: [PATCH] Simplify tradingmode parsing --- freqtrade/exchange/exchange.py | 7 ++----- freqtrade/freqtradebot.py | 7 ++----- freqtrade/optimize/backtesting.py | 4 +++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 0acd10900..20a0c7e69 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -130,11 +130,8 @@ class Exchange: self._trades_pagination = self._ft_has['trades_pagination'] self._trades_pagination_arg = self._ft_has['trades_pagination_arg'] - self.trading_mode: TradingMode = ( - TradingMode(config.get('trading_mode')) - if config.get('trading_mode') - else TradingMode.SPOT - ) + self.trading_mode = TradingMode(config.get('trading_mode', 'spot')) + self.collateral: Optional[Collateral] = ( Collateral(config.get('collateral')) if config.get('collateral') diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 4fd6d9b1b..708635991 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -106,12 +106,9 @@ class FreqtradeBot(LoggingMixin): self._exit_lock = Lock() LoggingMixin.__init__(self, logger, timeframe_to_seconds(self.strategy.timeframe)) - self.trading_mode: TradingMode = TradingMode.SPOT + self.trading_mode = TradingMode(self.config.get('trading_mode', 'spot')) + self.collateral_type: Optional[Collateral] = None - - if 'trading_mode' in self.config: - self.trading_mode = TradingMode(self.config['trading_mode']) - if 'collateral_type' in self.config: self.collateral_type = Collateral(self.config['collateral_type']) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 678ff1b32..26408e341 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -18,6 +18,7 @@ from freqtrade.data.btanalysis import trade_list_to_dataframe from freqtrade.data.converter import trim_dataframe, trim_dataframes from freqtrade.data.dataprovider import DataProvider from freqtrade.enums import BacktestState, SellType +from freqtrade.enums.tradingmode import TradingMode from freqtrade.exceptions import DependencyException, OperationalException from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds from freqtrade.mixins import LoggingMixin @@ -122,7 +123,8 @@ class Backtesting: # TODO-lev: This should come from the configuration setting or better a # TODO-lev: combination of config/strategy "use_shorts"(?) and "can_short" from the exchange - self._can_short = False + self.trading_mode = TradingMode(config.get('trading_mode', 'spot')) + self._can_short = self.trading_mode == TradingMode.MARGIN self.progress = BTProgress() self.abort = False