From 704e32b0dc18034739337078e324882eded02e50 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 7 Sep 2024 09:28:35 +0200 Subject: [PATCH] feat: properly parse marginmode on startup --- freqtrade/configuration/configuration.py | 10 +++++++++- freqtrade/freqtradebot.py | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index d9c860abd..1bbc84861 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -15,7 +15,14 @@ from freqtrade.configuration.directory_operations import create_datadir, create_ from freqtrade.configuration.environment_vars import enironment_vars_to_dict from freqtrade.configuration.load_config import load_file, load_from_files from freqtrade.constants import Config -from freqtrade.enums import NON_UTIL_MODES, TRADE_MODES, CandleType, RunMode, TradingMode +from freqtrade.enums import ( + NON_UTIL_MODES, + TRADE_MODES, + CandleType, + MarginMode, + RunMode, + TradingMode, +) from freqtrade.exceptions import OperationalException from freqtrade.loggers import setup_logging from freqtrade.misc import deep_merge_dicts, parse_db_uri_for_logging @@ -389,6 +396,7 @@ class Configuration: config.get("trading_mode", "spot") or "spot" ) config["trading_mode"] = TradingMode(config.get("trading_mode", "spot") or "spot") + config["margin_mode"] = MarginMode(config.get("margin_mode", "") or "") self._args_to_config( config, argname="candle_types", logstring="Detected --candle-types: {}" ) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index dff99e93e..15a3ae6ee 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -22,6 +22,7 @@ from freqtrade.edge import Edge from freqtrade.enums import ( ExitCheckTuple, ExitType, + MarginMode, RPCMessageType, SignalDirection, State, @@ -108,6 +109,7 @@ class FreqtradeBot(LoggingMixin): PairLocks.timeframe = self.config["timeframe"] self.trading_mode: TradingMode = self.config.get("trading_mode", TradingMode.SPOT) + self.margin_mode: MarginMode = self.config.get("margin_mode", MarginMode.NONE) self.last_process: Optional[datetime] = None # RPC runs in separate threads, can start handling external commands just after @@ -2216,7 +2218,11 @@ class FreqtradeBot(LoggingMixin): # TODO: should shorting/leverage be supported by Edge, # then this will need to be fixed. trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True) - if order.ft_order_side == trade.entry_side or (trade.amount > 0 and trade.is_open): + if ( + order.ft_order_side == trade.entry_side + or (trade.amount > 0 and trade.is_open) + or self.margin_mode == MarginMode.CROSS + ): # Must also run for partial exits # TODO: Margin will need to use interest_rate as well. # interest_rate = self.exchange.get_interest_rate()